[antlr-interest] Newby Question: Hello world example with ANTLRWorks 1.2.3

Martijn Reuvers martijn.reuvers at gmail.com
Fri Sep 25 13:01:11 PDT 2009


Hello Simon,

Nothing is missing, it's just a bit too much. I am not entirely sure
but I think you cannot use TOKEN+ in another token. Maybe someone else
can explain this better? For example this will work:

statement
	:	 DIGIT (PLUS DIGIT)*;

DIGIT   : '0'..'9'+;

PLUS    : '+';

Yeah you're free to choose what to do (to use inline actions) or do
your stuff separately (e.g. using a treewalker). StringTemplate might
be useful if you need code generation for example.

Martijn


On Fri, Sep 25, 2009 at 9:50 PM, Simon Gubler <sgubler at gmail.com> wrote:
> Hi all
>
> The following grammar compiles with ANTLRWorks 1.2.3 but when I debug it
> with "1+2+3" it generates a Parse Tree with the following elements:
> root->statement->MissingTokenException.
>
> In the file SimplePlusGrammar.g:
> grammar SimplePlusGrammar;
> statement : INTEGER (PLUS INTEGER)*;
> PLUS    : '+';
> DIGIT   : ('0'..'9');
> INTEGER : DIGIT+;
>
> Can you explain what is missing in the grammar to generate a valid Parse
> Tree out of "1+2+3"
> In many examples so far I have seen Java Code inside the *.g file. Is it
> possible to have only the grammar definition in the *.g file so that it can
> be used by different programming languages
>
> I'm posting my questions here because I haven't found a forum or something
> similar where I can put them.
>
> Kind regards
>
> Simon Gubler
>
>
> 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