C 预处理器的 ANTLR 语法
我在antlr网站上下载了ac预处理器语法。但是它有一个错误,我不知道如何纠正它。
macroExpansion
: id=IDENTIFIER WS? LPAREN WS? RPAREN -> ^(EXPAND $id)
| id=IDENTIFIER WS? LPAREN WS? macArgs WS? RPAREN -> ^(EXPAND $id macArgs?)
规则宏扩展对于下面的代码会出错:
typedef VOID (WINAPI *PFIBER_START_ROUTINE)( LPVOID lpFiberParameter );
因为VOID后面的标记将被视为参数,但实际上VOID只是一个宏而不是函数宏。
我怎样才能改变语法?希望有人能帮助我。谢谢!
I download a c preprocessor grammar on the antlr website.But it has an error and I have no idea about how to correct it.
macroExpansion
: id=IDENTIFIER WS? LPAREN WS? RPAREN -> ^(EXPAND $id)
| id=IDENTIFIER WS? LPAREN WS? macArgs WS? RPAREN -> ^(EXPAND $id macArgs?)
rule macroExpansion will go wrong for the code below:
typedef VOID (WINAPI *PFIBER_START_ROUTINE)( LPVOID lpFiberParameter );
Because tokens following VOID would be considered as arguments,but in fact VOID is just a macro not a function marco.
How can I change the grammar?Hope anyone can help me.Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于规则必须以
IDENTIFIER
开头,后跟LPAREN
,因此我看不到它与typedef VOID (
等输入匹配,因为>typedef
没有被考虑在内。仅通过查看
macroExpansion
:我会对语法的其余部分有点怀疑:
macArgs?
是可选的在重写规则中,但这不正确:左侧不是可选的。它可以像这样重写:在这种情况下
macArgs?
是正确的。Since the rule must start with
IDENTIFIER
followed by aLPAREN
, I can't see it ever match input liketypedef VOID (
since thetypedef
isn't accounted for.By only looking at the
macroExpansion
:I'd be a bit skeptical about the rest of the grammar though: the
macArgs?
is made optional in the rewrite rule, but that is not correct: the left hand side isn't optional. It could be rewritten like this:in which case
macArgs?
is correct.