[antlr-interest] Heterogeneous trees

Bogdanov, Serge serge.bogdanov at intel.com
Tue May 3 08:11:47 PDT 2005


Peter,

            It looks like you are trying to abuse antlr. I guess you
should've done it differently:

tokens { 
  SPECIAL1<AST=Special1AST>; 
  IDENT<AST=Special2AST>; 
} 

expr: (IDENT SPECIAL1)=> IDENT! SPECIAL^ | IDENT^ ;

 

or

 

expr: (IDENT SPECIAL1)=> IDENT SPECIAL^<AST=Special1AST> |
IDENT^<AST=Special2AST>;

 

>> Sergey Bogdanov

intel massachusetts

M/S HD2-246
77 Reed Road, 
Hudson, MA  01749

Tel: (978)553-2724

________________________________

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Peter Kronenberg
Sent: Tuesday, May 03, 2005 11:05 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Heterogeneous trees

 

I'm writing a parser that builds a heterogeneous tree.  The nodes are
based on the token type.  But I'm having a problem when a predicate is
needed to determine the correct token type.  Here's a contrived example.
An IDENT followed by SPECIAL1, I want to create a SPECIAL1 AST.  But an
IDENT by itself should be reflected as a SPECIAL2 type.

Before I added the different AST's, this parser worked, but now, the
IDENT node is just created using the default type.  How can I get it to
honor the AST that's specified in the tokens section?

tokens { 
  SPECIAL1<AST=Special1AST>; 
  SPECIAL2<AST=Special2AST>; 
} 

expr: (IDENT SPECIAL1)=> IDENT SPECIAL^ | i:IDENT^ {#i.setType(SPECIAL2)


 

Peter Kronenberg 
Software Engineer 
(703) 885-1222 
pkronenberg at technicacorp.com 

The information contained in this transmission may contain privileged
and confidential information. It is intended only for the use of the
person(s) named above. If you are not the intended recipient, you are
hereby notified that any review, dissemination, distribution or
duplication of this communication is strictly prohibited. If you are not
the intended recipient, please contact the sender by reply e-mail and
destroy all copies of the original message. Technica Corporation does
not represent this e-mail to be free from any virus, fault or defect and
it is therefore the responsibility of the recipient to first scan it for
viruses, faults and defects. To reply to our e-mail administrator
directly, please send an e-mail to postmaster at technicacorp.com. Thank
you.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050503/75afe448/attachment.html


More information about the antlr-interest mailing list