0

我正在尝试重写我的 AST 并输出语义警告。如果我将 [] 与它接受的词法分析器规则一起使用但不与解析器规则一起使用,为什么?我有一个名为“var”的解析器规则,如果通过执行以下操作声明,我想测试该值:

-> ^(DECLARATION TYPE var[Main.symbols.test_declared($var.text)] expression?);

但我得到:

unexpected token: Main.symbols.test_declared($var.text)

有没有办法解决这个问题?

我见过的大多数教程只使用了 LEXER 规则,但我不能基于我的语法,例如 IDENTIFIER 是 var 的一部分。

4

1 回答 1

1

In ANTLR 3, the var[xxx] syntax means you are passing xxx as an argument to the var rule. If this is not what you are trying to do, you'll need to clarify exactly what your goals are. Inside a rewrite rule (on the right hand side of the -> operator), the var rule is already completed so arguments are meaningless. You can reference the result with just var:

-> ^(DECLARATION TYPE var expression?);
于 2013-08-20T14:40:19.237 回答