如何将ANTLR C语法中的postfix_expression转换为AST?
我正在通过修改C语法并尝试一些自己感兴趣的东西来学习ANTLR。我开始使用的C语法来自: http://www.antlr.org/grammar/1153358328744/ Cg
现在我想将 postfix_expression
转换为其相应的 AST,但还不知道与表单转换相关的任何内容xx (aa|bb|cc)* yy
...
unary_expression
: postfix_expression
| unary_operator^ unary_expression
;
postfix_expression
: primary_expression
( '[' expression ']'
| '(' ')'
| '(' argument_expression_list ')'
| '.' ID
)*
;
unary_operator
: '+'
| '-'
| '~'
| '!'
;
...
你能帮我解决这个问题吗?您只需在语法中的 postfix_expression
部分添加一些 ^
和/或 !
符号即可。
I'm learning ANTLR by modifying the C grammar and trying something interests myself. The C grammar I started with is from: http://www.antlr.org/grammar/1153358328744/C.g
Now I want to transform postfix_expression
to its corresponding AST but haven't known anything related to the transformation of the form xx (aa|bb|cc)* yy
...
unary_expression
: postfix_expression
| unary_operator^ unary_expression
;
postfix_expression
: primary_expression
( '[' expression ']'
| '(' ')'
| '(' argument_expression_list ')'
| '.' ID
)*
;
unary_operator
: '+'
| '-'
| '~'
| '!'
;
...
Can you help me with this problem? You may just add some ^
and/or !
notations to the postfix_expression
part in the grammar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会选择这样的东西:
它将把输入解析
为以下 AST:
图像描述">
Id'd go for something like this:
which will parse the input:
into the following AST:
making it easy to evaluate the expression left to right.