Methods Summary |
---|
public void | addAlternative(persistence.antlr.Alternative alt)
alternatives.appendElement(alt);
|
public void | generate()
grammar.generator.gen(this);
|
public persistence.antlr.Alternative | getAlternativeAt(int i)
return (Alternative)alternatives.elementAt(i);
|
public persistence.antlr.collections.impl.Vector | getAlternatives()
return alternatives;
|
public boolean | getAutoGen()
return doAutoGen;
|
public java.lang.String | getInitAction()
return initAction;
|
public java.lang.String | getLabel()
return label;
|
public persistence.antlr.Lookahead | look(int k)
return grammar.theLLkAnalyzer.look(k, this);
|
public void | prepareForAnalysis()
for (int i = 0; i < alternatives.size(); i++) {
// deterministic() uses an alternative cache and sets lookahead depth
Alternative a = (Alternative)alternatives.elementAt(i);
a.cache = new Lookahead[grammar.maxk + 1];
a.lookaheadDepth = GrammarAnalyzer.LOOKAHEAD_DEPTH_INIT;
}
|
public void | removeTrackingOfRuleRefs(persistence.antlr.Grammar g)Walk the syntactic predicate and, for a rule ref R, remove
the ref from the list of FOLLOW references for R (stored
in the symbol table.
for (int i = 0; i < alternatives.size(); i++) {
Alternative alt = getAlternativeAt(i);
AlternativeElement elem = alt.head;
while (elem != null) {
if (elem instanceof RuleRefElement) {
RuleRefElement rr = (RuleRefElement)elem;
RuleSymbol rs = (RuleSymbol)g.getSymbol(rr.targetRule);
if (rs == null) {
grammar.antlrTool.error("rule " + rr.targetRule + " referenced in (...)=>, but not defined");
}
else {
rs.references.removeElement(rr);
}
}
else if (elem instanceof AlternativeBlock) {// recurse into subrules
((AlternativeBlock)elem).removeTrackingOfRuleRefs(g);
}
elem = elem.next;
}
}
|
public void | setAlternatives(persistence.antlr.collections.impl.Vector v)
alternatives = v;
|
public void | setAutoGen(boolean doAutoGen_)
doAutoGen = doAutoGen_;
|
public void | setInitAction(java.lang.String initAction_)
initAction = initAction_;
|
public void | setLabel(java.lang.String label_)
label = label_;
|
public void | setOption(persistence.antlr.Token key, persistence.antlr.Token value)
if (key.getText().equals("warnWhenFollowAmbig")) {
if (value.getText().equals("true")) {
warnWhenFollowAmbig = true;
}
else if (value.getText().equals("false")) {
warnWhenFollowAmbig = false;
}
else {
grammar.antlrTool.error("Value for warnWhenFollowAmbig must be true or false", grammar.getFilename(), key.getLine(), key.getColumn());
}
}
else if (key.getText().equals("generateAmbigWarnings")) {
if (value.getText().equals("true")) {
generateAmbigWarnings = true;
}
else if (value.getText().equals("false")) {
generateAmbigWarnings = false;
}
else {
grammar.antlrTool.error("Value for generateAmbigWarnings must be true or false", grammar.getFilename(), key.getLine(), key.getColumn());
}
}
else if (key.getText().equals("greedy")) {
if (value.getText().equals("true")) {
greedy = true;
greedySet = true;
}
else if (value.getText().equals("false")) {
greedy = false;
greedySet = true;
}
else {
grammar.antlrTool.error("Value for greedy must be true or false", grammar.getFilename(), key.getLine(), key.getColumn());
}
}
else {
grammar.antlrTool.error("Invalid subrule option: " + key.getText(), grammar.getFilename(), key.getLine(), key.getColumn());
}
|
public java.lang.String | toString()
String s = " (";
if (initAction != null) {
s += initAction;
}
for (int i = 0; i < alternatives.size(); i++) {
Alternative alt = getAlternativeAt(i);
Lookahead cache[] = alt.cache;
int k = alt.lookaheadDepth;
// dump lookahead set
if (k == GrammarAnalyzer.LOOKAHEAD_DEPTH_INIT) {
}
else if (k == GrammarAnalyzer.NONDETERMINISTIC) {
s += "{?}:";
}
else {
s += " {";
for (int j = 1; j <= k; j++) {
s += cache[j].toString(",", grammar.tokenManager.getVocabulary());
if (j < k && cache[j + 1] != null) s += ";";
}
s += "}:";
}
// dump alternative including pred (if any)
AlternativeElement p = alt.head;
String pred = alt.semPred;
if (pred != null) {
s += pred;
}
while (p != null) {
s += p;
p = p.next;
}
if (i < (alternatives.size() - 1)) {
s += " |";
}
}
s += " )";
return s;
|