KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > Alternative


1 package persistence.antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/license.html
6  *
7  */

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

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