Flex/Bison:糟糕的令牌管理
Flex/Bison: Bad token management?
我的词法器和解析器有问题。
首先,在我的词法分析器中,我有这样一行:
"if" beginScope(stOTHER); return IF;
在我的解析器中:
stmt: IF '(' exp ')' stmts
...
stmts: stmt
| '{' stmt_list '}'
| '{' '}'
在这样的代码中:
if(sth) {
dosth;
}
if(other) {
doothersth;
}
beginScope 会被调用两次,因为(我认为)Bison 不知道if
语句的结尾在哪里,所以当它找到IF
令牌时,他将其作为if
语句的结尾,并再次阅读它以开始另一个if
语句......
请帮帮我...
正如 Zack 在注释中提到的,您应该从解析器操作调用 beginScope
:
stmt: IF { beginScope(stOTHER); } '(' exp ')' stmts
相关文章:
- 如何在C++中使用X509证书模在令牌中查找私钥
- holeMenuProgram.cpp:38:1 错误:'}'令牌之前的预期主表达式
- C++:"("令牌"之前有预期的非限定 id 指向类中成员函数的指针
- Arduino 用于语句错误。令牌之前的预期')' ';'。如何解决这个问题?
- 错误:令牌 { '{' 之前应存在非限定 ID
- 允许哪些令牌作为 #include 的参数?
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- 它在 { 令牌之前给了我预期的标识符
- (错误:令牌之前'<<'预期的主表达式)
- 为什么 ## aka 令牌粘贴运算符不适用于 C 和 C++ 中的注释?
- 错误:"->"令牌之前的预期初始值设定项
- LINUX 操作系统上的错误:令牌之前预期的构造函数、析构函数或类型转换'('?
- 丢失读入的每一行输入中的最后一个令牌
- 如何使用 libCurl 将访问令牌发送到服务器 API
- C++令牌定义成员
- 宏定义中的预处理器令牌两边有两个双引号
- 错误:C++中']'令牌之前的预期主表达式
- 错误:令牌之前的预期主表达式'&&'
- 令牌之前']'预期的主表达式?
- Flex/Bison:糟糕的令牌管理