KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > antlr > TreeBlockContext


1 package antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/RIGHTS.html
6  *
7  * $Id: //depot/code/org.antlr/main/main/antlr/TreeBlockContext.java#4 $
8  */

9
10 /**The context needed to add root,child elements to a Tree. There
11  * is only one alternative (i.e., a list of children). We subclass to
12  * specialize. MakeGrammar.addElementToCurrentAlt will work correctly
13  * now for either a block of alts or a Tree child list.
14  *
15  * The first time addAlternativeElement is called, it sets the root element
16  * rather than adding it to one of the alternative lists. Rather than have
17  * the grammar duplicate the rules for grammar atoms etc... we use the same
18  * grammar and same refToken behavior etc... We have to special case somewhere
19  * and here is where we do it.
20  */

21 class TreeBlockContext extends BlockContext {
22     protected boolean nextElementIsRoot = true;
23
24
25     public void addAlternativeElement(AlternativeElement e) {
26         TreeElement tree = (TreeElement)block;
27         if (nextElementIsRoot) {
28             tree.root = (GrammarAtom)e;
29             nextElementIsRoot = false;
30         }
31         else {
32             super.addAlternativeElement(e);
33         }
34     }
35 }
36
Popular Tags