[antlr-interest] Again semantical problem

Bryan Ewbank ewbank at gmail.com
Wed Jun 8 11:20:20 PDT 2005


I think it's more *you* that must do this *using* ANTLR.  ANTLR allows
you to walk the tree using a concise notation, but you have to decide
what needs to be done.

For example...

The following walker assigns MyLocalType to PLUS numeric operators.

   #( PLUS INT INT ) { ##->MyLocalType(IntegerType); }
   | #( PLUS FLOAT INT ) { ##->MyLocalType(FloatType); }
   | #( PLUS INT FLOAT ) { ##->MyLocalType(FloatType); }
   | #( PLUS FLOAT FLOAT ) { ##->MyLocalType(FloatType); }

Then, at ASSIGN:

   #(ASSIGN lhs rhs) { ##->MyLocalType(#rhs->MyLocalType(); }

Now, printing an ASSIGN requires that you emit the syntax to make it
into a declaration by looking at MyLocalType of the ASSIGN node.

This is of course oversimplified, and there are other ways to do this,
but it should help to distinguish what ANTLR does (allow you a way to
generate an AST, and to walk that AST) from what it does not (define
the shape of the AST, any semantic information, etc).

On 6/8/05, Serafettin Senturk <serafettin_sentuerk at intergral.com> wrote:
> I have again a question about semantical analysis in Antlr. How far is it
> possible to solve semantical problems with Antlr?
> ...
> How far is it possible to solve such a problem in Antlr? or is Antlr only
> for syntactical transformations?


More information about the antlr-interest mailing list