Arun Ramakrishnan
2012-12-11 23:18:49 UTC
Lets take this AST generating grammer.
************
prog : duration NEWLINE?
{System.out.println($duration.tree.toStringTree());} ;
duration : years|year ;
year: 'year' -> ^('years' '1');
years : INT 'years' -> ^('years' INT) ;
************
input: 5 years
tree string: (years 5)
input: year
tree string: 9
a) for the input of "5 years" the output tree string is "(years 5)" which
is as expected. However, for an input of "year" the output tree string is
"9". Now, 9 happens to be the token code for 'years'. Why this
inconsistency ?
b) In the rule for year, I am trying to transform it into a more
generalized form as the rule years. But, the value '1' dosent show up in
the tree structure.
How can I go about this. appreciate the help.
thanks
Arun
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
************
prog : duration NEWLINE?
{System.out.println($duration.tree.toStringTree());} ;
duration : years|year ;
year: 'year' -> ^('years' '1');
years : INT 'years' -> ^('years' INT) ;
************
input: 5 years
tree string: (years 5)
input: year
tree string: 9
a) for the input of "5 years" the output tree string is "(years 5)" which
is as expected. However, for an input of "year" the output tree string is
"9". Now, 9 happens to be the token code for 'years'. Why this
inconsistency ?
b) In the rule for year, I am trying to transform it into a more
generalized form as the rule years. But, the value '1' dosent show up in
the tree structure.
How can I go about this. appreciate the help.
thanks
Arun
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address