FileDocCategorySizeDatePackage
AlternativeBlock.javaAPI DocGlassfish v2 API7558Wed Aug 30 15:34:04 BST 2006persistence.antlr

AlternativeBlock

public class AlternativeBlock extends AlternativeElement
A list of alternatives

Fields Summary
protected String
initAction
protected Vector
alternatives
protected String
label
protected int
alti
protected int
altj
protected int
analysisAlt
protected boolean
hasAnAction
protected boolean
hasASynPred
protected int
ID
protected static int
nblks
boolean
not
boolean
greedy
boolean
greedySet
protected boolean
doAutoGen
protected boolean
warnWhenFollowAmbig
protected boolean
generateAmbigWarnings
Constructors Summary
public AlternativeBlock(Grammar g)

  // the general warning "shut-up" mechanism
    // conflicts with alt of subrule.
    // Turning this off will suppress stuff
    // like the if-then-else ambig.

       
        super(g);
        alternatives = new Vector(5);
        this.not = false;
        nblks++;
        ID = nblks;
    
public AlternativeBlock(Grammar g, Token start, boolean not)

        super(g, start);
        alternatives = new Vector(5);
//		this.line = start.getLine();
//		this.column = start.getColumn();
        this.not = not;
        nblks++;
        ID = nblks;
    
Methods Summary
public voidaddAlternative(persistence.antlr.Alternative alt)

        alternatives.appendElement(alt);
    
public voidgenerate()

        grammar.generator.gen(this);
    
public persistence.antlr.AlternativegetAlternativeAt(int i)

        return (Alternative)alternatives.elementAt(i);
    
public persistence.antlr.collections.impl.VectorgetAlternatives()

        return alternatives;
    
public booleangetAutoGen()

        return doAutoGen;
    
public java.lang.StringgetInitAction()

        return initAction;
    
public java.lang.StringgetLabel()

        return label;
    
public persistence.antlr.Lookaheadlook(int k)

        return grammar.theLLkAnalyzer.look(k, this);
    
public voidprepareForAnalysis()

        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 voidremoveTrackingOfRuleRefs(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 voidsetAlternatives(persistence.antlr.collections.impl.Vector v)

        alternatives = v;
    
public voidsetAutoGen(boolean doAutoGen_)

        doAutoGen = doAutoGen_;
    
public voidsetInitAction(java.lang.String initAction_)

        initAction = initAction_;
    
public voidsetLabel(java.lang.String label_)

        label = label_;
    
public voidsetOption(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.StringtoString()

        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;