[antlr-interest] declare throws-clause for rule
Gerard van de Glind
g.vandeglind at beinformed.nl
Thu Jul 3 04:24:02 PDT 2008
Hi,
Yes, you can throw an exception (a RuntTimeException to be precise,
because these are unchecked) from your grammar. And you can catch these
exceptions in the class that invokes the generated parser.
Example:
expression : ruleA | ruleB { if (condition) {throw new
RunTimeException("");} };
Also, code that you place in the @member action gets generated into your
parser.
Good luck!
Cheers, Gerard
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of tilman walter
Sent: donderdag 3 juli 2008 12:15
To: ANTLR List
Subject: [antlr-interest] declare throws-clause for rule
Hi List,
I am a newby to antlr.
Is there a possibility to let a rule throw a custom exception that can
be catched by the class invoking the parser?
I think i could place this piece of code in the generated class, but i
wonder if i can reach this through a grammar construct....
I would appreciate for any hint.
Thanks is advance.
Tilman
More information about the antlr-interest
mailing list