[antlr-interest] How can I insert a Token in the token stream?

Randall R Schulz rschulz at sonic.net
Sun Sep 21 14:44:13 PDT 2008


On Saturday 20 September 2008 22:00, Yet ANOTHER Test Runner wrote:
> Sorry for my poor English :(
>
> Many computer languages like TTCN3, allows near '}' token or at the
> last statement inside block statement omit ';' token correctly, like
> this:
>
> if(xx){
>
>     const integer i:=1;    //error if missing ';'
>
>     const integer i2:=2  //ok! even though missing ';'
>
> }
>
> How can I insert a token ';' in the TokenStream if it is omitted.

Why conceptualize it as inserting a semicolon? Why not conceptualize it 
as the semicolon being a _separator_, not a _terminator_ and write the 
syntax rules accordingly?

E.g., compare these:

/* All statements are terminated by a semicolon */
BlockBody: ( Statement ';' ) *

vs.:

/* Statements are separated by a semicolon */
BlockBody: ( Statement ( ';' Statement ) * ) ?


> ...


Randall Schulz


More information about the antlr-interest mailing list