[antlr-interest] AST - don't get it

Manu manunews at gmail.com
Wed Nov 8 05:19:02 PST 2006


Hi,

I have understood why is good to build an AST but I don't understand
exactly how the tree builder operators work. For example, I'd expect
the following grammar to generate an AST for the entry: 123 * 456
like:

(START (* 123 456))

but instead it generates:

(NIL (START (* 456)))

where did the 123 go?

grammar Expressions;

options
{
	output=AST;
	ASTLabelType=CommonTree;
}

tokens
{
	START;
}

s	:	 expression EOF -> ^(START expression);


expression: multiplicativeExpression ('+'^^ multiplicativeExpression)*;

multiplicativeExpression: primitiveExpression ('*'^^ primitiveExpression)*;

primitiveExpression: INT_LITERAL;
	
INT_LITERAL: ('0'..'9')+;

WS: (' ' | '\r' | '\t' | '\n') {channel=99;};

Please help me,
Thanks.


More information about the antlr-interest mailing list