Undisputed007
Undisputed007

Reputation: 649

tree rewriting with []

I am trying to rewrite my AST and output semantic warnings. If i use [] with a lexer rule it accepts but not with a parser rule why ? I have a parser rule called "var" and i will like to test the value if declared by doing something like this:

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

but i get :

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

is there a way to get around this ?

Most tutorials i have seen only LEXER rules are used, but i can't based on my grammar,e.g IDENTIFIER is a part of var.

Upvotes: 0

Views: 77

Answers (1)

Sam Harwell
Sam Harwell

Reputation: 99889

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?);

Upvotes: 1

Related Questions