[antlr-interest] Inserting a literal token in an AST rewrite rule
antlr at mirality.co.nz
Sat Feb 13 03:38:36 PST 2010
At 19:16 13/02/2010, Victor Liu wrote:
> : '-' expression_power -> ^(TOK_TIMES '-1' expression_power)
> | expression_power
>This doesn't work because apparently I can't just insert a
>token ('-1') in the rewrite rule.
Actually you can -- but it has to be a *token*, not just a string.
.... ^(TOK_TIMES INT["-1"] expression_power) ...
>Also, is there a way to simplify the rule into a one-liner?
With the AST output you seem to want, I think you've already got
it as simple as possible.
More information about the antlr-interest