[antlr-interest] @members section in tree grammar

Bart Kiers bkiers at gmail.com
Sun Jul 10 12:48:53 PDT 2011


Hi Shane,

Inside a combined- or lexer- or parser grammar, the `tokens` should be
placed before the `members` section(s):

(lexer | parser)? grammar ...
options { ... }
tokens { ... }
@header { ... }   (or: @parser::header { ... }, @lexer::header { ... })
@members { ... }  (or: @parser::members { ... }, @lexer::members { ... })

But a tree grammar gets its tokens from the `tokenVocab` key:

tree grammar ExprWalker;

options {
  tokenVocab=Expr;
  ASTLabelType=CommonTree;
}

So no `tokens` section inside a tree grammar.

Regards,

Bart.


On Sun, Jul 10, 2011 at 9:31 PM, Shane <srberry1 at gmail.com> wrote:

> I can put an @members section in a grammar without any problem, but when I
> put one in a tree grammar, I get a bunch of exceptions.  It ignores
> everything after the @members section.  BTW,  I'm trying to get access to
> the error output, so I can show it to the user.
>
> Exception:
> unexpected token: tokens {
>
>
> grammar Expr;
>
> options {
>    output=AST;
>    ASTLabelType=CommonTree;
>    backtrack=true;
> }
>
> @members {
>    public String getTokenErrorDisplay(Token t) {
>        return t.toString();
>    }
> }
>
> tokens {
>    DIV                     = '/'               ;
>    EQUAL                   = '=='              ;
>    GREATER_OR_EQUAL        = '>='              ;
>    GREATER_THAN            = '>'               ;
> ...
>
>
> Can tree grammars handle @members sections?  or am I doing something wrong?
>
> Thanks,
>
> srb
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list