如何将文字从 flex 返回到 yacc?
在我的 yacc 文件中,我有如下内容:
var_declaration : type_specifier ID ';'
| type_specifier ID '[' NUM ']' ';' ;
type_specifier : INT | VOID ;
ID、NUM、INT 和 VOID 是从 flex 返回的标记,因此 yacc 识别它们没有问题。问题是上面有‘[’和‘;’之类的东西。当这些被flex识别后,应该返回什么给yacc?
In my yacc file I have things like the following:
var_declaration : type_specifier ID ';'
| type_specifier ID '[' NUM ']' ';' ;
type_specifier : INT | VOID ;
ID, NUM, INT, and VOID are tokens that get returned from flex, so yacc has no problems recognizing them. The problem is that in the above there are things like '[' and ';'. When these are recognized by flex, what should be returned to yacc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以只返回字符本身。保证令牌不与 ASCII 字符冲突:
http:// www.gnu.org/software/bison/manual/html_node/Token-Decl.html
所以在你的flex文件中,
就可以了。
You can just return the characters themselves. Tokens are guaranteed not to conflict with ASCII characters:
http://www.gnu.org/software/bison/manual/html_node/Token-Decl.html
So in your flex file,
is OK.