Package org.sablecc.sablecc.lrautomaton

Examples of org.sablecc.sablecc.lrautomaton.Alternative


            if (alternative == null) {
                throw CompilerException.invalidReference(identifier);
            }

            Alternative grammarAlternative = alternative
                    .getGrammarAlternative();

            int size = grammarAlternative.getElements().size();
            if (size == 0) {
                throw CompilerException.alternativeNotRecursive(identifier);
            }

            String prodName = this.currentProduction.getNameToken().getText();

            // is it left recursive?
            Element element = grammarAlternative.getElement(0);
            if (element instanceof ProductionElement
                    && ((ProductionElement) element).getProduction().getName()
                            .equals(prodName)) {
                // check that recursion is followed by token
                if (grammarAlternative.getElements().size() < 2
                        || !(grammarAlternative.getElement(1) instanceof TokenElement)) {
                    throw CompilerException
                            .recursionNotFollowedByToken(identifier);
                }
            }
            else {
                // not left recursive => check that it is right recursive
                element = grammarAlternative.getElement(size - 1);
                if (!(element instanceof ProductionElement)
                        || !((ProductionElement) element).getProduction()
                                .getName().equals(prodName)) {
                    throw CompilerException.alternativeNotRecursive(identifier);
                }
            }

            this.currentPriorityLevel.addAlternative(grammarAlternative);
            grammarAlternative.setPriorityLevel(this.currentPriorityLevel,
                    identifier);
        }
    }
View Full Code Here


                if (action.getType() == ActionType.SHIFT) {
                    mAction.newShift();
                }
                else {
                    ReduceAction reduceAction = (ReduceAction) action;
                    Alternative alternative = reduceAction.getAlternative();
                    Production production = alternative.getProduction();
                    String production_CamelCaseName = to_CamelCase(production
                            .getName());
                    String alt_CamelCaseName = to_CamelCase(alternative
                            .getName());
                    String alt_CamelCaseFullName = production_CamelCaseName
                            + (alt_CamelCaseName.equals("") ? "" : "_"
                                    + alt_CamelCaseName);

                    MReduce mReduce = mAction.newReduce(alt_CamelCaseFullName);

                    ArrayList<Element> elements = alternative.getElements();
                    int elementCount = elements.size();
                    for (int i = elementCount - 1; i >= 0; i--) {
                        Element element = elements.get(i);
                        String element_CamelCaseName = to_CamelCase(element
                                .getName());
View Full Code Here

TOP

Related Classes of org.sablecc.sablecc.lrautomaton.Alternative

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.