[antlr-interest] How can I insert a Token in the token stream?
Randall R Schulz
rschulz at sonic.net
Sun Sep 21 14:48:46 PDT 2008
On Sunday 21 September 2008 14:44, Randall R Schulz wrote:
> On Saturday 20 September 2008 22:00, Yet ANOTHER Test Runner wrote:
> > ...
> >
> > 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 ) * ) ?
NOTE: I should not have used upper-case letters for these rules, since
that's for lexer rules. I should be:
/* 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