[antlr-interest] Question on tree generation

James Mello james.mello at intelligentdiscovery.com
Thu Dec 28 13:13:43 PST 2006


Given the rule:

begin! :
	(s:SLASH t:typeValue)+


How does one build up a tree using the tree building syntax such given the
input

/a:b /c:d /e:f (where a:b, c:d, e:f are of type typeValue)

That you will end up with a tree that looks like so?

Sibling(/a:b) ->sibling(/c:d)....

I've tried the following action rule, but only end up with the last
element....

{
	#begin = #(s, t);
}

James Mello : Software Engineer - ATS, Inc. 
web: www.intelligentdiscovery.com | (p) 360.698.7100x236 | (f) 360.698.7200 

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Agnisys
Sent: Thursday, December 28, 2006 11:31 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Newbie questions: How to traverse the AST ...

Hi,
  I need to pick up useful pieces of information from a 3rd party file. The
file format is simple field based with possible quoted text. I've written
the lexer and parser for the file (.g). I would have used Perl but decided
to try Antlr in the hope that when the 3rd party changes the format I would
have to do little to accommodate the changes. 

  I have a couple of questions related to this :

  1.  What is the standard idiom to traverse the AST ? Any examples would
help. How do I get to the relevant information in the Java code?
  2.  Is there an AWK mode that simply splits the input into fields?
  3.  How to deal with quoted comments that can contain elements from the
language itself.
      For example :
      ABC="123 456=789"
      The '=' should be skipped inside the double quote.
  4.  Is the antlr-interest group postings search-able on any site?

Thanks for any pointers for any of these questions. This would enable me to
move forward. 
Anupam.

P.S. Anxiously waiting for the Antlr book. I found this to be very helpful:
http://www.cs.usfca.edu/~parrt/course/652/lectures/antlr-lexers.html





More information about the antlr-interest mailing list