[antlr-interest] parentheses sequence validation
Martin Probst
mail at martin-probst.com
Tue Jan 25 08:47:40 PST 2005
Hi,
> Ex: ((()())()) : Validated OK
> (() : The error is thrown: expecting RPAREN, found : OK
>
> BUT when trying validate the expression: ()) no error is thrown!!!
You need to check for the EOF condition. In your case your parser just
stops parsing if it can't continue to match rules. The trailing ')' is
silently ignored. Fix it by writing:
expr: LPAREN (expr)* RPAREN EOF!
( EOF is the meta-token for the End-Of-File, the ! operator keeps it out
of your parse tree).
Regards,
Martin
More information about the antlr-interest
mailing list