List of usage examples for org.antlr.v4.runtime ParserRuleContext accept
@Override public <T> T accept(ParseTreeVisitor<? extends T> visitor)
From source file:com.blazebit.persistence.impl.expression.JPQLSelectExpressionVisitorImpl.java
License:Apache License
private WhenClauseExpression handleWhenClause(ParserRuleContext condition, ParserRuleContext result) { return new WhenClauseExpression((Predicate) condition.accept(this), result.accept(this)); }
From source file:com.blazebit.persistence.parser.expression.JPQLSelectExpressionVisitorImpl.java
License:Apache License
private WhenClauseExpression handleWhenClause(ParserRuleContext condition, ParserRuleContext result) { return new WhenClauseExpression(condition.accept(this), result.accept(this)); }
From source file:com.boothen.jsonedit.outline.JsonContentProvider.java
License:Open Source License
@Override public Object[] getChildren(Object parentElement) { if (parentElement instanceof ParserRuleContext) { ParserRuleContext context = (ParserRuleContext) parentElement; List<ParseTree> children = context.accept(treeFilter); return children.toArray(); }//from w ww . j av a 2s .c o m return new Object[0]; }
From source file:dijkstra.Dijkstra.java
License:Open Source License
static private void doCompile() { DijkstraParser parser = DijkstraFactory.makeParser(new ANTLRInputStream(fileContents)); // $codepro.audit.disable variableShouldBeFinal ParserRuleContext tree = parser.dijkstraText(); ASTNode ast = tree.accept(new ASTCreator()); ast.accept(new SymbolCreator()); TypeChecker checker = new TypeChecker(); do {// w ww . ja va 2 s . co m ast.accept(checker); } while (checker.checkAgain()); // get the class name programName = ((ProgramNode) ((RootNode) ast).getProgramNode()).programName; List<byte[]> codeList = new ArrayList<byte[]>(); DijkstraCodeGenerator codeGen = new DijkstraCodeGenerator(); if (customPackage != null) { codeGen.setClassPackage(customPackage); } for (ASTNode classDef : ast.children) { codeList.add(classDef.accept(codeGen)); } for (int i = 0; i < ast.children.size(); i++) { String className; if (ast.children.get(i) instanceof ClassDeclarationNode) { className = ((ClassDeclarationNode) ast.children.get(i)).getID().getName(); } else { className = ((ProgramNode) ast.children.get(i)).programName; } byte[] compiledCode = codeList.get(i); try (FileOutputStream fos = new FileOutputStream("djkcode/" + className + ".class")) { fos.write(compiledCode); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:dijkstra.dikstra.Dijkstra.java
License:Open Source License
static private void doCompile() { DijkstraParser parser = DijkstraFactory.makeParser(new ANTLRInputStream(fileContents)); ParserRuleContext tree = parser.dijkstraText(); ASTNode ast = tree.accept(new ASTCreator()); ast.accept(new SymbolCreator()); TypeChecker checker = new TypeChecker(); do {// ww w .j a va 2 s . c o m ast.accept(checker); } while (checker.checkAgain()); DijkstraCodeGenerator generator = new DijkstraCodeGenerator(); if (customPackage != null) { generator.setClassPackage(customPackage); } // get the class name programName = ((ProgramNode) ast).programName; byte[] code = ast.accept(new DijkstraCodeGenerator()); FileOutputStream fos; try { fos = new FileOutputStream(outputDirectory + "/" + customPackage + "/" + programName + ".class"); fos.write(code); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:jasy.lang.ASMCompiler.java
private static jasy.lang.ast.CodeAST getStatement(ParserRuleContext ctx, MetaProcessing mp) { jasy.lang.ast.CodeAST r = ctx.accept(new JasyBaseVisitor<jasy.lang.ast.CodeAST>() { @Override/*from w w w . j a va2 s.co m*/ public CodeAST visitStatement(JasyParser.StatementContext ctx) { if (ctx.nonDelimitedStatement() != null) return ctx.nonDelimitedStatement().accept(this); if (ctx.delimitedStatement() != null) return ctx.delimitedStatement().accept(this); if (ctx.metaBlock() != null) return ctx.metaBlock().accept(this); return null; } @Override public CodeAST visitDelimitedStatement(JasyParser.DelimitedStatementContext ctx) { if (ctx.expression() != null) { ExpressionAST expression = getExpression(ctx.expression(), mp); return new RootExpressionAST(new Region(ctx), expression); } return ctx.getChild(0).accept(this); } @Override public CodeAST visitReturnStatement(JasyParser.ReturnStatementContext ctx) { ExpressionAST expression = getExpression(ctx.expression(), mp); return new ReturnAST(new Region(ctx), expression); } @Override public CodeAST visitVariableDeclaration(JasyParser.VariableDeclarationContext ctx) { String type = ctx.typeQualifier().getText(); String name = ctx.identifier().getText(); ExpressionAST value; if (ctx.expression() != null) value = getExpression(ctx.expression(), mp); else value = null; return new VariableDeclarationAST(new Region(ctx), name, new NameTypeAST(new Region(ctx.typeQualifier()), type), value); } @Override public CodeAST visitMetaBlock(JasyParser.MetaBlockContext ctx) { List<CodeAST> statements = getStatements(ctx.statements(), mp); return new MetaCodeAST(null, new BlockAST(null, statements)); } // @Override // public CodeAST visitInjectStatement(JasyParser.InjectStatementContext ctx) { // ExpressionAST expression = getExpression(ctx.expression(), mp); // // return new InjectAST(new Region(ctx), expression); // } @Override public CodeAST visitIfElseStatement(JasyParser.IfElseStatementContext ctx) { ExpressionAST condition = getExpression(ctx.condition, mp); CodeAST ifTrueBody = getBody(ctx.ifTrueBlock); CodeAST ifFalseBody = ctx.ifFalseBlock != null ? getBody(ctx.ifFalseBlock) : null; return new IfElseAST(new Region(ctx), condition, ifTrueBody, ifFalseBody); } @Override public CodeAST visitWhileStatement(JasyParser.WhileStatementContext ctx) { ExpressionAST condition = getExpression(ctx.condition, mp); CodeAST body = getBody(ctx.whileTrueBlock); return new WhileAST(new Region(ctx), condition, body); } @Override public CodeAST visitForStatement(JasyParser.ForStatementContext ctx) { List<CodeAST> initialization = ctx.initialization != null ? getStatements(ctx.initialization.delimitedStatement(), mp) : null; ExpressionAST condition = ctx.condition != null ? getExpression(ctx.condition, mp) : null; List<CodeAST> update = ctx.update != null ? getStatements(ctx.update.delimitedStatement(), mp) : null; List<CodeAST> body = getStatements(ctx.whileTrueBlock.statements(), mp); ArrayList<CodeAST> statements = new ArrayList<>(); statements.addAll(initialization); ArrayList<CodeAST> whileBody = new ArrayList<>(); whileBody.addAll(body); whileBody.addAll(update); statements.add(new WhileAST(new Region(ctx), condition, new BlockAST(new Region(ctx.whileTrueBlock), whileBody))); return new BlockAST(new Region(ctx), statements); // return new WhileAST(new Region(ctx), condition, body); } private CodeAST getBody(JasyParser.SingleOrMultiStatementContext ctx) { return ctx.statement() != null ? getStatement(ctx.statement(), mp) : new BlockAST(new Region(ctx), getStatements(ctx.statements(), mp)); } }); return r; }
From source file:jasy.lang.ASMCompiler.java
private static ExpressionAST getExpression(ParserRuleContext ctx, MetaProcessing mp) { return ctx.accept(new ContextToExpression(mp)); }
From source file:jasy.lang.ASMCompiler.java
private static Class<?> validateExpression(ParserRuleContext ctx, ArrayList<Message> errorMessages) { return ctx.accept(new JasyBaseVisitor<Class<?>>() { @Override//from w w w . j av a2 s . c o m public Class<?> visitStringLiteral(JasyParser.StringLiteralContext ctx) { return String.class; } @Override public Class<?> visitIntegerLiteral(JasyParser.IntegerLiteralContext ctx) { return int.class; } }); }
From source file:net.udidb.expr.lang.c.CExpressionCompiler.java
License:Open Source License
@VisibleForTesting static void resolveSymbols(ParserRuleContext parseTree, ParseTreeProperty<NodeState> states, ExecutionContext executionContext, Function currentFunction, long pc) { SymbolResolutionVisitor resolutionVisitor = new SymbolResolutionVisitor(states, executionContext, currentFunction, pc);/*from w ww .j ava2 s . c om*/ parseTree.accept(resolutionVisitor); }
From source file:net.udidb.expr.lang.c.CExpressionCompiler.java
License:Open Source License
@VisibleForTesting static void typeCheckExpression(ParserRuleContext parseTree, ParseTreeProperty<NodeState> states) { TypeCheckingVisitor typeCheckingVisitor = new TypeCheckingVisitor(states); parseTree.accept(typeCheckingVisitor); }