[antlr-interest] Imaginary nodes in Antlr 3

geoff ot0006 at 0x29a.org.uk
Sat Jun 16 06:38:49 PDT 2007


Hallo there,

I'm running AntlrWorks 1.0.2, Antlr 3.0, StringTemplate 3.1b1 on XP.

I have The Definitive Antlr Reference open next to me.

I'm adding an AST to the Expr.g first example. I want to make the assignment operator an
imaginary node:

stat:   expr NEWLINE! {System.out.println($expr.value);}
    |   ID '=' expr NEWLINE  -> ^(ASSIGN ID expr)          
    |   NEWLINE!
    ; 

On p166 Adding Imaginary Nodes the book says "simply refer to its token type and, and
Antlr will create a Token object with that token type", which is what I expected to happen
to ASSIGN.

But, this does not work, and I get 
(135) ... Reference to undefined token in rewrite rules: ASSIGN
as well as red wavy underlining in AntlrWorks.

On a guess I then tried adding the token to the grammar

ASSIGN : ; 

and everything compiled and ran as expected, tree built perfectly.

Is there something I'm missing on automatic creation of imaginary tokens? Clues welcome.

--
best,
geoff stevens

regrettably the email address above will bounce



More information about the antlr-interest mailing list