[antlr-interest] Why use trees rather than building up your own code?

Gokulakannan Somasundaram gokul007 at gmail.com
Fri Jul 29 06:07:41 PDT 2011


This is very well discussed in the book ANTLR - Definitive Reference.

Basically mostly people will construct a tree out of the grammar. The
library identifies the common usage and provides a solution for it.

Gokul.

On Fri, Jul 29, 2011 at 6:19 PM, Colin Yates <colin.yates at gmail.com> wrote:

> 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
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list