如何在 Bison 解析器上返回多个标记?
我的语法是这样的
decl:
attributes; {/*create an object here with the attributes $$?*/ }
attributes:
|
att1 attributes {$$ = $1;}
|
att2 attributes {$$ = $1;}
|
attn attributes {$$ = $1;};
我想获取用户输入的所有属性,其中一些是可选的,顺序无关紧要,类型不同
My grammar is something like this
decl:
attributes; {/*create an object here with the attributes $?*/ }
attributes:
|
att1 attributes {$ = $1;}
|
att2 attributes {$ = $1;}
|
attn attributes {$ = $1;};
I want to get all the attributes entered by the user, some of them are optional and the order doesn't matter, types are different
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在
$$
变量中返回一个结构;根据需要分配给其成员。这是我手头上的一些代码的示例:来自同一解析器的另一个示例,与上述更简单的规则相比,它在基于条目自定义
struct
方面付出了更多的努力;缺点是这变得相当复杂,但优点是这是对单个对象属性的更好演示:You need to return a structure in your
$$
variable; assign to its members as you need to. Here's an example from some code I have handy:Another example from the same parser, which puts more effort into customizing a
struct
based on an entry than the above simpler rules; the downside is that this is getting quite complex, but the upside is that this is a better demonstration of attributes of a single object:现在语法
now the grammar