[antlr-interest] Newby - How to find rule context in the AST
    Harris, Tobin 
    tobin at tobinharris.com
       
    Sun May 27 02:16:02 PDT 2007
    
    
  
Hi Folks,
 
This one's bugging me...
 
So far, everything I've read says that you don't need a big bloated
"parse tree" when evaluating your grammar. Instead, we have a more
concise AST that only contains the values. For example:
 
My top grammar rule looks a bit like this
uriformat = scheme '://' credentials? host path? query?
 
The AST outputs like this 
 
http  :// tobin : xyz @ someurl.com / blah
 
instead of  the parse tree, which is more like this
 
[scheme]
   http
://
[credentials]
  Tobin
  :
  xyz
  @
[host]
  Someurl.com
[path]
  /blah
 
The problem is, I want to be able to interrogate the tree to find out
if, for example, the [credentials] were parsed, and then loop through
the sub-nodes (username, password etc). Unfortunately the AST doesn't
contain this information. I can get the type of a node, but that will
only be a "DIGIT" or "INT" etc. 
 
Is there a way of retaining more of the parse tree? Am I missing
something here? 
 
I did see an example for Oracle URI where the author embeds Actions in
rules, and thought this might be a way to go...
 
{ #tnsnames_entry = #([TNSNAMES_ENTRY, "tnsnames_entry"],
#tnsnames_entry); }
 
However, actions get evaluated to the target language - C# in my case -
and I'm not actually sure what the above language is or what the code is
doing!?
 
Any help appreciated!
 
Tobin 
 
P.S - I started looking in to ANTLR as an alternative to RegEx, because
it just didn't seem like the right tool for the job. However, I was
hoping for an approach that didn't require a massive learning curve! Are
there any other tools that might fit my simple needs better?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070527/c73c9010/attachment.html 
    
    
More information about the antlr-interest
mailing list