01: package antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.cs.usfca.edu
05: * Software rights: http://www.antlr.org/license.html
06: */
07:
08: import java.util.Hashtable;
09:
10: /** Intermediate data class holds information about an alternative */
11: class Alternative {
12: // Tracking alternative linked list
13: AlternativeElement head; // head of alt element list
14: AlternativeElement tail; // last element added
15:
16: // Syntactic predicate block if non-null
17: protected SynPredBlock synPred;
18: // Semantic predicate action if non-null
19: protected String semPred;
20: // Exception specification if non-null
21: protected ExceptionSpec exceptionSpec;
22: // Init action if non-null;
23: protected Lookahead[] cache; // lookahead for alt. Filled in by
24: // deterministic() only!!!!!!! Used for
25: // code gen after calls to deterministic()
26: // and used by deterministic for (...)*, (..)+,
27: // and (..)? blocks. 1..k
28: protected int lookaheadDepth; // each alt has different look depth possibly.
29: // depth can be NONDETERMINISTIC too.
30: // 0..n-1
31: // If non-null, Tree specification ala -> A B C (not implemented)
32: protected Token treeSpecifier = null;
33: // True of AST generation is on for this alt
34: private boolean doAutoGen;
35:
36: public Alternative() {
37: }
38:
39: public Alternative(AlternativeElement firstElement) {
40: addElement(firstElement);
41: }
42:
43: public void addElement(AlternativeElement e) {
44: // Link the element into the list
45: if (head == null) {
46: head = tail = e;
47: } else {
48: tail.next = e;
49: tail = e;
50: }
51: }
52:
53: public boolean atStart() {
54: return head == null;
55: }
56:
57: public boolean getAutoGen() {
58: // Don't build an AST if there is a tree-rewrite-specifier
59: return doAutoGen && treeSpecifier == null;
60: }
61:
62: public Token getTreeSpecifier() {
63: return treeSpecifier;
64: }
65:
66: public void setAutoGen(boolean doAutoGen_) {
67: doAutoGen = doAutoGen_;
68: }
69: }
|