[antlr-interest] Comments and questions on a recent project

Tiller, Michael (M.M.) mtiller at ford.com
Mon Aug 26 08:11:47 PDT 2002



> -----Original Message-----
> From: mzukowski at yci.com [mailto:mzukowski at yci.com]
> Sent: Monday, August 26, 2002 11:01 AM
> To: antlr-interest at yahoogroups.com
> Subject: RE: [antlr-interest] Comments and questions on a 
> recent project
> 
> 
> 
> >As part of the parsing stage, I tried to do my best to construct a
> >succinct AST.  I eliminated lots of punctuation and extraneous
> >keywords from AST and I tried to introduce some high-level 
> "imaginary"
> >tokens to represent the important nodes in my AST.  I suppose I could
> >have used the same token types that the keywords/punctuation 
> generated
> >but I guess I feel it is slightly cleaner to create new ones
> >specifically for "rule nodes".  I had a few difficulties with this.
> >The first was that there are some funny constructs in the language
> >where some qualifiers appear in some rules and some appear 
> above them.
> >Simple example:
> >
> >stored_definition
> >  : ("final")? class_definition
> >  ;
> > 
> >class_definition
> >  : ("encapsulated")? ("partial")? restricted_class IDENT ...
> >      { ## = #([DEFINITION, "DEFINITION"], ##); }
> >  ;
> 
> Why not:
> 
> stored_definition
>    : ("final")? class_definition
>        { ## = #([DEFINITION, "DEFINITION"], ##); }
>    ;
> class_definition
>   : ("encapsulated")? ("partial")? restricted_class IDENT ...
>   ;
> 

Sorry, I wasn't clear about that.  The "class_definition" rule is used in
other places.  I suppose I could move the imaginary node creation up one
level.  The drawback would be that I would end up creating DEFINITION nodes
in several places rather than just one.  Is there a way to add a child to an
existing node?!?  I wasn't able to get this out of the tree construction
documentation.  In other words, isn't there an easy way to do this in a
language neutral way:

stored_definition
  : (fn:"final")? cd:class_definition
    { #cd->addChild(#fn); }

> For example, 
> in some cases I
> might be interested in resolving the fully qualified names to 
> all my data
> elements.  So I'd like to add associate such names with the 
> instance names
> in my AST (not fully qualified).  What is the best way to do this?  I
> thought about using heterogeneous AST nodes, but that would 
> make the problem
> quite complicated the AST nodes would be potentially in 
> conflict from one
> application to another.  Using homogeneous AST nodes, I could 
> certainly add
> sub-nodes with the information I want but there are two 
> issues I'm concerned
> about:
> >
> 
> Typically I build tables to handle this sort of thing.  Just 
> about anything
> that can be in an AST can be in a table with the node as a 
> key and then a
> value of whatever.

An excellent suggestion.  This way I can create a tables on an application
specific basis.  Thanks!

> I'll comment upon the rest, hopefully at lunchtime.
> 
> Monty

Here is one more question (although your "table" suggestion might work
well).  How to establish "parent" relationships?  Is there any facility for
finding parent nodes?

--
Mike

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list