[antlr-interest] Why use trees rather than building up your own code?
Colin Yates
colin.yates at gmail.com
Fri Jul 29 03:19:48 PDT 2011
Hi all,
I understand that the ANTLR grammar can produce an intermediate form tree
which is then parsed or you can provide code snippets to build up your own
internal representation.
I have always used the second, for example:
departmentDefinition returns[DepartmentDefinition value]
@init {$value = new DepartmentDefinition(); }
: DEPARTMENT singleReferenceDataDefinition {
$value.setDepartmentDefinition($singleReferenceDataDefinition.value);
} departmentStatements[$value]+
This seems a much more natural approach, and I have implemented a handful of
pretty complex grammars this way, but I get the sense that trees are the
preferred approach.
My question is why - what benefit do they get you?
The reason I want to know is I am about to embark on a library for editing
documents defined by an ANTLR grammar with syntax highlighting etc. (see my
next email :)) and I want to make sure I am not sending myself up an alley
:)
Col
More information about the antlr-interest
mailing list