在 mac os 中编译 lex 和 yacc 时出错
Error while compiling lex and yacc in mac os
我正在设计一个 lex 和 yacc 程序 MAC OS..
当我尝试执行以下操作时:
gcc sample.tab.c lex.yy.c -ly -ll
它向我展示了很多错误,最后..
致命错误:发出的错误太多,现在停止 [-ferror-limit=]
出现了一些错误:
./sample.tab.h:44:6: error: expected identifier
if = 260,
^
./sample.tab.h:46:6: error: expected identifier
else = 262,
^
./sample.tab.h:48:6: error: expected identifier
while = 264,
^
./sample.tab.h:53:6: error: expected identifier
return = 269,
谁能帮我解决这个问题?
谢谢..
不能使用 C 关键字作为非终结符的名称。这就是为什么通常使用 ALL-CAPS 作为非终端名称的原因。所以你的 flex 文件可能包括
while { return WHILE; }
return { return RETURN; }
如果你是野牛,你可以声明别名:
%token WHILE "while"
%token RETURN "return"
允许您编写如下规则:
whileStatement: "while" '(' expression ')' statement
我正在设计一个 lex 和 yacc 程序 MAC OS..
当我尝试执行以下操作时:
gcc sample.tab.c lex.yy.c -ly -ll
它向我展示了很多错误,最后..
致命错误:发出的错误太多,现在停止 [-ferror-limit=]
出现了一些错误:
./sample.tab.h:44:6: error: expected identifier
if = 260,
^
./sample.tab.h:46:6: error: expected identifier
else = 262,
^
./sample.tab.h:48:6: error: expected identifier
while = 264,
^
./sample.tab.h:53:6: error: expected identifier
return = 269,
谁能帮我解决这个问题?
谢谢..
不能使用 C 关键字作为非终结符的名称。这就是为什么通常使用 ALL-CAPS 作为非终端名称的原因。所以你的 flex 文件可能包括
while { return WHILE; }
return { return RETURN; }
如果你是野牛,你可以声明别名:
%token WHILE "while"
%token RETURN "return"
允许您编写如下规则:
whileStatement: "while" '(' expression ')' statement