【问题标题】:Error while compiling lex and yacc in mac os在 mac os 中编译 lex 和 yacc 时出错
【发布时间】:2017-03-18 11:58:54
【问题描述】:

我正在开发一个 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,

有人可以帮我吗?

谢谢你..

【问题讨论】:

标签: xcode macos flex-lexer yacc lex


【解决方案1】:

您不能使用 C 关键字作为非终结符的名称。这就是为什么通常使用全大写作为非终端名称的原因。所以你的 flex 文件可能包含

while    { return WHILE; }
return  {  return  RETURN; }

如果你是野牛,你可以声明别名:

%token WHILE "while"
%token RETURN "return"

允许您编写如下规则:

whileStatement: "while" '(' expression ')' statement

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多