KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > antlr > Alternative


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/Alternative.java#4 $
8  */

9
10 import java.util.Hashtable JavaDoc;
11
12 /** Intermediate data class holds information about an alternative */
13 class Alternative {
14     // Tracking alternative linked list
15
AlternativeElement head; // head of alt element list
16
AlternativeElement tail; // last element added
17

18     // Syntactic predicate block if non-null
19
protected SynPredBlock synPred;
20     // Semantic predicate action if non-null
21
protected String JavaDoc semPred;
22     // Exception specification if non-null
23
protected ExceptionSpec exceptionSpec;
24     // Init action if non-null;
25
protected Lookahead[] cache; // lookahead for alt. Filled in by
26
// deterministic() only!!!!!!! Used for
27
// code gen after calls to deterministic()
28
// and used by deterministic for (...)*, (..)+,
29
// and (..)? blocks. 1..k
30
protected int lookaheadDepth; // each alt has different look depth possibly.
31
// depth can be NONDETERMINISTIC too.
32
// 0..n-1
33
// If non-null, Tree specification ala -> A B C (not implemented)
34
protected Token treeSpecifier = null;
35     // True of AST generation is on for this alt
36
private boolean doAutoGen;
37
38
39     public Alternative() {
40     }
41
42     public Alternative(AlternativeElement firstElement) {
43         addElement(firstElement);
44     }
45
46     public void addElement(AlternativeElement e) {
47         // Link the element into the list
48
if (head == null) {
49             head = tail = e;
50         }
51         else {
52             tail.next = e;
53             tail = e;
54         }
55     }
56
57     public boolean atStart() {
58         return head == null;
59     }
60
61     public boolean getAutoGen() {
62         // Don't build an AST if there is a tree-rewrite-specifier
63
return doAutoGen && treeSpecifier == null;
64     }
65
66     public Token getTreeSpecifier() {
67         return treeSpecifier;
68     }
69
70     public void setAutoGen(boolean doAutoGen_) {
71         doAutoGen = doAutoGen_;
72     }
73 }
74
Popular Tags