如何在 bison 语法中匹配字符串?
如何在 bison 语法中匹配字符串?比方说,一个代表自身的字符串,例如“polySphere”。我是否必须在 .lex 文件中创建一个令牌(如 POLYSPHERE),然后在 bison 中使用它?我不能直接使用字符串吗?
谢谢
How do I match a string in bison grammar? A string that stands for itself like "polySphere" let's say. Will I have to create a token in the .lex file like POLYSPHERE and then use that in bison? Can't I just use the string directly?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以逐个字符地识别 bison 中的字符串,例如:
但这相当低效——通常,在词法分析器中识别字符串并返回单个标记要好得多
You could recognize the string in bison character by character, eg:
but that is rather ineffecient -- generally its much better to recognize the string in the lexer and return a single token
您无法识别语法中的字符串。您将遇到如下错误:
不支持多字符文字标记
您应该简单地在 lex 中添加
"polySphere" { return POLYSPHERE; }
you can't identify a string in your grammar.you will have an error like this :
multicharacter literal tokens not supported
you should simply add in your lex
"polySphere" { return POLYSPHERE; }