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();
}
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>());
}
}
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);
}
}
}
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;
}
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;
}
Aggregations