views:

34

answers:

1

How can I know during parsing which rule is currently matched? I'd like to automatically build an XML (or other objectal hierarchy) representing the parsed input, using rule names, without the need of using grammar actions or trees.

Is this possible?

Many thanks, Yaakov

+1  A: 

AFAIK, that is not possible. But why don't you use ANTLR's built in tree construction? In the options{ } part of your grammar, add output=AST; and use rewrite rules where applicable. See: http://www.antlr.org/wiki/display/~admin/2008/11/30/Example+tree+rewriting+with+patterns

Bart Kiers
I have a very large grammar, and I'm trying to avoid defining tree construction expressions on it.I found the EnterRule(ruleName) and ExitRule(ruleName) methods in IDebugEventListener, which get executed in debug mode (I believe).Do you happen to have any experience with those?Yaakov
Yaakov Davis
Yaakov, I'm sorry, I don't...
Bart Kiers

related questions