ParserRuleContext tree; try { // first, try parsing with potentially faster SLL mode parser.getInterpreter().setPredictionMode(PredictionMode.SLL); tree = parseFunction.apply(parser); // 此时解析为Antlr树 } catch (ParseCancellationException ex) { // if we fail, parse with LL mode tokenStream.seek(0); // rewind input stream parser.reset(); // SLL不行的话,使用降级模式LL parser.getInterpreter().setPredictionMode(PredictionMode.LL); tree = parseFunction.apply(parser); }
returnnewAstBuilder(parsingOptions).visit(tree); // 访问者模式,生成Presto自定义的语法树 } catch (StackOverflowError e) { thrownewParsingException(name + " is too large (stack overflow while parsing)"); } }