Search in sources :

Example 61 with RecognitionException

use of org.antlr.runtime.RecognitionException in project Apktool by iBotPeaches.

the class SmaliBuilder method buildFile.

private void buildFile(String fileName, DexBuilder dexBuilder) throws AndrolibException, IOException {
    File inFile = new File(mSmaliDir, fileName);
    InputStream inStream = new FileInputStream(inFile);
    if (fileName.endsWith(".smali")) {
        try {
            if (!SmaliMod.assembleSmaliFile(inFile, dexBuilder, false, false)) {
                throw new AndrolibException("Could not smali file: " + fileName);
            }
        } catch (IOException | RecognitionException ex) {
            throw new AndrolibException(ex);
        }
    } else {
        LOGGER.warning("Unknown file type, ignoring: " + inFile);
    }
    inStream.close();
}
Also used : AndrolibException(brut.androlib.AndrolibException) ExtFile(brut.directory.ExtFile) RecognitionException(org.antlr.runtime.RecognitionException)

Example 62 with RecognitionException

use of org.antlr.runtime.RecognitionException in project antlr4 by antlr.

the class RuleFunction method getElementFrequenciesForAlt.

/** Given list of X and r refs in alt, compute how many of each there are */
protected Pair<FrequencySet<String>, FrequencySet<String>> getElementFrequenciesForAlt(AltAST ast) {
    try {
        ElementFrequenciesVisitor visitor = new ElementFrequenciesVisitor(new CommonTreeNodeStream(new GrammarASTAdaptor(), ast));
        visitor.outerAlternative();
        if (visitor.frequencies.size() != 1) {
            factory.getGrammar().tool.errMgr.toolError(ErrorType.INTERNAL_ERROR);
            return new Pair<>(new FrequencySet<String>(), new FrequencySet<String>());
        }
        return new Pair<>(visitor.getMinFrequencies(), visitor.frequencies.peek());
    } catch (RecognitionException ex) {
        factory.getGrammar().tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, ex);
        return new Pair<>(new FrequencySet<String>(), new FrequencySet<String>());
    }
}
Also used : GrammarASTAdaptor(org.antlr.v4.parse.GrammarASTAdaptor) RecognitionException(org.antlr.runtime.RecognitionException) FrequencySet(org.antlr.v4.misc.FrequencySet) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream) Pair(org.antlr.v4.runtime.misc.Pair)

Example 63 with RecognitionException

use of org.antlr.runtime.RecognitionException in project antlr4 by antlr.

the class ParserATNFactory method _createATN.

protected void _createATN(Collection<Rule> rules) {
    createRuleStartAndStopATNStates();
    GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
    for (Rule r : rules) {
        // find rule's block
        GrammarAST blk = (GrammarAST) r.ast.getFirstChildWithType(ANTLRParser.BLOCK);
        CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor, blk);
        ATNBuilder b = new ATNBuilder(nodes, this);
        try {
            setCurrentRuleName(r.name);
            Handle h = b.ruleBlock(null);
            rule(r.ast, r.name, h);
        } catch (RecognitionException re) {
            ErrorManager.fatalInternalError("bad grammar AST structure", re);
        }
    }
}
Also used : ATNBuilder(org.antlr.v4.parse.ATNBuilder) GrammarAST(org.antlr.v4.tool.ast.GrammarAST) GrammarASTAdaptor(org.antlr.v4.parse.GrammarASTAdaptor) Rule(org.antlr.v4.tool.Rule) LeftRecursiveRule(org.antlr.v4.tool.LeftRecursiveRule) RecognitionException(org.antlr.runtime.RecognitionException) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream)

Example 64 with RecognitionException

use of org.antlr.runtime.RecognitionException in project antlr4 by antlr.

the class Tool method parse.

public GrammarRootAST parse(String fileName, CharStream in) {
    try {
        GrammarASTAdaptor adaptor = new GrammarASTAdaptor(in);
        ToolANTLRLexer lexer = new ToolANTLRLexer(in, this);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        lexer.tokens = tokens;
        ToolANTLRParser p = new ToolANTLRParser(tokens, this);
        p.setTreeAdaptor(adaptor);
        try {
            ParserRuleReturnScope r = p.grammarSpec();
            GrammarAST root = (GrammarAST) r.getTree();
            if (root instanceof GrammarRootAST) {
                ((GrammarRootAST) root).hasErrors = lexer.getNumberOfSyntaxErrors() > 0 || p.getNumberOfSyntaxErrors() > 0;
                assert ((GrammarRootAST) root).tokenStream == tokens;
                if (grammarOptions != null) {
                    ((GrammarRootAST) root).cmdLineOptions = grammarOptions;
                }
                return ((GrammarRootAST) root);
            }
        } catch (v3TreeGrammarException e) {
            errMgr.grammarError(ErrorType.V3_TREE_GRAMMAR, fileName, e.location);
        }
        return null;
    } catch (RecognitionException re) {
        // TODO: do we gen errors now?
        ErrorManager.internalError("can't generate this message at moment; antlr recovers");
    }
    return null;
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) GrammarRootAST(org.antlr.v4.tool.ast.GrammarRootAST) ToolANTLRLexer(org.antlr.v4.parse.ToolANTLRLexer) GrammarAST(org.antlr.v4.tool.ast.GrammarAST) GrammarASTAdaptor(org.antlr.v4.parse.GrammarASTAdaptor) org.antlr.v4.parse.v3TreeGrammarException(org.antlr.v4.parse.v3TreeGrammarException) ParserRuleReturnScope(org.antlr.runtime.ParserRuleReturnScope) ToolANTLRParser(org.antlr.v4.parse.ToolANTLRParser) RecognitionException(org.antlr.runtime.RecognitionException)

Example 65 with RecognitionException

use of org.antlr.runtime.RecognitionException in project binnavi by google.

the class MemoryExpressionParser method multExpression.

// $ANTLR start "multExpression"
// C:\\Dokumente und
// Einstellungen\\sp\\workspace\\com.google.security.zynamics.binnavi-Trunk\\src\\com.google.security.zynamics.binnavi\\parsers\\gotomem\\MemoryExpression.g:42:1:
// multExpression : primaryExpression ( OPERAND_MULT primaryExpression )* ;
public final MemoryExpressionParser.multExpression_return multExpression() throws RecognitionException {
    final MemoryExpressionParser.multExpression_return retval = new MemoryExpressionParser.multExpression_return();
    retval.start = input.LT(1);
    Object root_0 = null;
    Token OPERAND_MULT9 = null;
    MemoryExpressionParser.primaryExpression_return primaryExpression8 = null;
    MemoryExpressionParser.primaryExpression_return primaryExpression10 = null;
    Object OPERAND_MULT9_tree = null;
    try {
        // C:\\Dokumente und
        // Einstellungen\\sp\\workspace\\com.google.security.zynamics.binnavi-Trunk\\src\\com.google.security.zynamics.binnavi\\parsers\\gotomem\\MemoryExpression.g:43:3:
        // ( primaryExpression ( OPERAND_MULT primaryExpression )* )
        // C:\\Dokumente und
        // Einstellungen\\sp\\workspace\\com.google.security.zynamics.binnavi-Trunk\\src\\com.google.security.zynamics.binnavi\\parsers\\gotomem\\MemoryExpression.g:43:5:
        // primaryExpression ( OPERAND_MULT primaryExpression )*
        {
            root_0 = (Object) adaptor.nil();
            pushFollow(FOLLOW_primaryExpression_in_multExpression239);
            primaryExpression8 = primaryExpression();
            state._fsp--;
            adaptor.addChild(root_0, primaryExpression8.getTree());
            // ( OPERAND_MULT primaryExpression )*
            loop3: do {
                int alt3 = 2;
                final int LA3_0 = input.LA(1);
                if ((LA3_0 == OPERAND_MULT)) {
                    alt3 = 1;
                }
                switch(alt3) {
                    case 1:
                        // C:\\Dokumente und
                        // Einstellungen\\sp\\workspace\\com.google.security.zynamics.binnavi-Trunk\\src\\com.google.security.zynamics.binnavi\\parsers\\gotomem\\MemoryExpression.g:43:24:
                        // OPERAND_MULT primaryExpression
                        {
                            OPERAND_MULT9 = (Token) match(input, OPERAND_MULT, FOLLOW_OPERAND_MULT_in_multExpression242);
                            OPERAND_MULT9_tree = (Object) adaptor.create(OPERAND_MULT9);
                            root_0 = (Object) adaptor.becomeRoot(OPERAND_MULT9_tree, root_0);
                            pushFollow(FOLLOW_primaryExpression_in_multExpression245);
                            primaryExpression10 = primaryExpression();
                            state._fsp--;
                            adaptor.addChild(root_0, primaryExpression10.getTree());
                        }
                        break;
                    default:
                        break loop3;
                }
            } while (true);
        }
        retval.stop = input.LT(-1);
        retval.tree = (Object) adaptor.rulePostProcessing(root_0);
        adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
    } catch (final RecognitionException e) {
        throw e;
    } finally {
    }
    return retval;
}
Also used : Token(org.antlr.runtime.Token) RecognitionException(org.antlr.runtime.RecognitionException)

Aggregations

RecognitionException (org.antlr.runtime.RecognitionException)168 CommonTree (org.antlr.runtime.tree.CommonTree)132 Token (org.antlr.runtime.Token)122 RewriteRuleSubtreeStream (org.antlr.runtime.tree.RewriteRuleSubtreeStream)84 RewriteRuleTokenStream (org.antlr.runtime.tree.RewriteRuleTokenStream)65 NoViableAltException (org.antlr.runtime.NoViableAltException)37 RewriteEarlyExitException (org.antlr.runtime.tree.RewriteEarlyExitException)15 CommonTokenStream (org.antlr.runtime.CommonTokenStream)9 MismatchedSetException (org.antlr.runtime.MismatchedSetException)8 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)6 EarlyExitException (org.antlr.runtime.EarlyExitException)4 TokenRewriteStream (org.antlr.runtime.TokenRewriteStream)4 GrammarASTAdaptor (org.antlr.v4.parse.GrammarASTAdaptor)3 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)3 CharStream (org.antlr.runtime.CharStream)2 MismatchedTokenException (org.antlr.runtime.MismatchedTokenException)2 CommonTreeNodeStream (org.antlr.runtime.tree.CommonTreeNodeStream)2 AndrolibException (brut.androlib.AndrolibException)1 ExtFile (brut.directory.ExtFile)1 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)1