[antlr-interest] Look Ahead while parsing a tree.

mzukowski at yci.com mzukowski at yci.com
Fri Nov 1 07:47:50 PST 2002


The lookahead depth k is always one for tree parsers.  Syntactic predicates
work in tree parsers if you need to look deeper than one.  

LA(1) isn't defined, but there is a variable _t which is the current node.
Hence _t.getFirstChild() and _t.getNextSibling() will give you the next
token down or right.  Be sure to handle the case that they return null.

Monty
-----Original Message-----
From: Trey Spiva [mailto:Trey.Spiva at embarcadero.com]
Sent: Friday, November 01, 2002 7:36 AM
To: 'antlr-interest at yahoogroups.com'
Subject: [antlr-interest] Look Ahead while parsing a tree.


I was wondering if there any way to look ahead while parsing a Tree.  I know
that in a recognizer you can use the LA(1) to test the next token,  can I do
something similar in a tree parser.
 
To give you a context I will explain my need.
 
For the java code:
 
if(m_a.doA() != null)
{
   m_b.doInterB();
}
else if(m_TestB.doB() == 1)
{
   m_a.doA();
}
else
{
   DoItSuper();
}
 
The tree will look like:
 
If
|
 -- EXPR           // The conditional test.
|
 -- { [SLIST]      // The body of the if statement
|
 -- If             // The else if part
     |
      -- EXPR      // The conditional test.
     | 
      -- { [SLIST] // The body of the if statement
     |
      -- { [SLIST  // The else part
 
When processing the tree I can tell if the SLIST is a else-if or a else.
Can any one help me understand?  I am working with the java grammar that
ships the ANTLR.

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 

 

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



More information about the antlr-interest mailing list