[antlr-interest] Rewrite rules from alternative tokens, how?
blake.friedman at gmail.com
Sun Sep 21 07:07:52 PDT 2008
I've run into problems trying to do something like this:
prefix : a=('-' | '+') prefix -> ^(PREFIX $a prefix)
int : '0'..'9'+
To generate trees such as:
(FACTOR - (FACTOR - 12))
Which is to say, how do I identify which token was selected and add it
to my rewrite rule?
At the moment I've identified two workarounds:
prefix : '-' prefix -> ^(PREFIX '-' prefix)
| '+' prefix -> ^(PREFIX '+' prefix)
prefix : umOK prefix -> ^(PREFIX umok prefix)
umOK : ('-'|'+') ;
The first isn't great, and the second is OK (but I'm not wild about
it). I've been scratching around on the online documentation and
Terence's book, but I'm a little overwhelmed :).
P.S. Apologies for the cryptic subject, wasn't all that sure how to
describe the problem.
More information about the antlr-interest