如何在 bison 语法中匹配字符串?

发布于 2024-12-22 22:16:59 字数 130 浏览 6 评论 0原文

如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

街角迷惘 2024-12-29 22:16:59

您可以逐个字符地识别 bison 中的字符串,例如:

polysphere: 'p' 'o' 'l' 'y' 'S' 'p' 'h' 'e' 'r' 'e'

但这相当低效——通常,在词法分析器中识别字符串并返回单个标记要好得多

You could recognize the string in bison character by character, eg:

polysphere: 'p' 'o' 'l' 'y' 'S' 'p' 'h' 'e' 'r' 'e'

but that is rather ineffecient -- generally its much better to recognize the string in the lexer and return a single token

我不咬妳我踢妳 2024-12-29 22:16:59

您无法识别语法中的字符串。您将遇到如下错误:

不支持多字符文字标记

您应该简单地在 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; }

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文