[antlr-interest] Newbie question - imaginary nodes

Lucian Adrian Grijincu lucian.grijincu at gmail.com
Sun Apr 6 16:40:40 PDT 2008


Use the "Contents" from the begging of the book :)

There's a "4.4 Tokens Specification" section in the book.

Anyways, here's a sniplet from my code:

grammar Yanl;

tokens {
   TYPETOKEN;
   ASSIGN;
   VARDEF;
}

On Mon, Apr 7, 2008 at 2:33 AM, Chris Lambrou <chris at lambrou.net> wrote:
> Hello there,
>
> I'm currently working through Ter's book and trying to understand how to
> create imaginary nodes to represent pseudo-operations. I'm having trouble
> with the relevant section from the book 'Adding imaginary nodes' (p.166), as
> follows:
>
> decl : type ID ';' -> ^(VARDEF type ID) ;
>
> This represents the 'variable declaration' pseudo-operation, with two child
> nodes representing the type and name of the variable. It's clear that 'type'
> refers to another rule, and ID represents an identifier token, but where
> does VARDEF come from? With reference to the imaginary VARDEF token, the
> book states the following:
>
> The imaginary token must be defined elsewhere in a grammar or in the tokens
> section.
>
> Where can I define the VARDEF token elsewhere in the grammar? I can't define
> like all of the 'concrete' tokens, as a VARDEF token can never exist as an
> actual sequence of input characters. This leaves the alternative of defining
> it in the tokens section, but I can't find any other reference to the tokens
> section in the book.
>


-- 
Lucian


More information about the antlr-interest mailing list