List of usage examples for org.antlr.v4.runtime RecognitionException RecognitionException
public RecognitionException(Recognizer<?, ?> recognizer, IntStream input, ParserRuleContext ctx)
From source file:com.koltem.filetype.verilog.editor.VerilogContextTreeListener.java
public VerilogContextTreeListener(Verilog2001Parser parser) { recognitionException = new RecognitionException(parser, null, RuleContext.EMPTY); syntaxErrors = new ArrayList<SyntaxError>(); }
From source file:it.cnr.istc.iloc.ddl.Preprocessing.java
License:Open Source License
@Override public void enterFormula_statement(DDLParser.Formula_statementContext ctx) { if (c_node != null) { IScope c_scope = scopes.get(ctx); if (ctx.object != null) { for (TerminalNode tn : ctx.object.ID()) { try { IField field = c_scope.getField(tn.getText()); c_scope = field.getType(); } catch (NoSuchFieldException ex) { parser.notifyErrorListeners(tn.getSymbol(), ex.getMessage(), new RecognitionException(parser, parser.getInputStream(), ctx)); }/*from ww w .j a va 2 s . c om*/ } } else if (c_scope != solver) { // Since ctx.object is null, we have an implicit scope for the current goal c_scope = c_scope.getEnclosingScope(); } IStaticCausalGraph.IEdge.Type type = null; if (ctx.goal != null) { type = IStaticCausalGraph.IEdge.Type.Goal; } else if (ctx.fact != null) { type = IStaticCausalGraph.IEdge.Type.Fact; } try { solver.getStaticCausalGraph().addEdge(type, c_node.node, solver.getStaticCausalGraph().getNode(c_scope.getPredicate(ctx.predicate.getText()))); } catch (ClassNotFoundException ex) { Logger.getLogger(Preprocessing.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:it.cnr.istc.iloc.ddl.StatementExecutor.java
License:Open Source License
@Override public Boolean visitAssignment_statement(DDLParser.Assignment_statementContext ctx) { IEnvironment c_environment = environment; IScope c_scope = scopes.get(ctx);//from w ww . j a v a 2 s . co m if (ctx.object != null) { if (ctx.object.t != null) { c_environment = c_environment.get("this"); } else if (ctx.object.s != null) { try { c_environment = c_environment.get("super"); c_scope = c_scope.getField("super").getType(); } catch (NoSuchFieldException ex) { parser.notifyErrorListeners(((TerminalNode) ctx.object.getChild(0)).getSymbol(), ex.getMessage(), new RecognitionException(parser, parser.getInputStream(), ctx.expr())); } } for (TerminalNode tn : ctx.object.ID()) { try { IField field = c_scope.getField(tn.getText()); c_environment = c_environment.get(tn.getText()); c_scope = field.getType(); } catch (NoSuchFieldException ex) { parser.notifyErrorListeners(tn.getSymbol(), ex.getMessage(), new RecognitionException(parser, parser.getInputStream(), ctx.expr())); } } } c_environment.set(ctx.field.getText(), new ObjectVisitor(solver, parser, scopes, environment).visit(ctx.expr())); return Boolean.TRUE; }
From source file:it.cnr.istc.iloc.ddl.StatementExecutor.java
License:Open Source License
@Override public Boolean visitFormula_statement(DDLParser.Formula_statementContext ctx) { // We use the environment for retrieving the scope of the goal IEnvironment c_environment = environment; // This is the language scope. Do not confuse this scope with the goal scope! This scope is intented for retrieving the goal predicate IScope c_scope = scopes.get(ctx);/*from w ww . ja va 2s .co m*/ if (ctx.object != null) { // We are creating a new goal whose scope is given by ctx.object if (ctx.object.t != null) { // ctx.object starts with "this". c_scope = c_environment.get("this").getType(); c_environment = c_environment.get("this"); } else if (ctx.object.s != null) { // ctx.object starts with "super". c_scope = c_environment.get("super").getType(); c_environment = c_environment.get("super"); } // Neither "this" nor "super" are included inside the ctx.object.ID() hence we can retrieve the goal scope for (TerminalNode tn : ctx.object.ID()) { c_scope = c_environment.get(tn.getText()).getType(); c_environment = c_environment.get(tn.getText()); } } else if (c_scope != solver) { // Since ctx.object is null, we have an implicit scope for the current goal // c_scope can be a disjunction or a preference.. while (!(c_scope instanceof IPredicate || c_scope instanceof IConstructor)) { c_scope = c_scope.getEnclosingScope(); c_environment = c_environment.getEnclosingEnvironment(); } if (c_scope instanceof IPredicate) { // The implicit goal is defined inside a rule c_environment = c_environment.getEnclosingEnvironment(); } else { // The implicit goal is defined inside a constructor } c_environment = c_environment.getEnclosingEnvironment(); // We will use this variable as the scope of the new formula.. assert c_environment instanceof IObject; } assert c_environment instanceof IObject || c_environment instanceof ISolver; try { IPredicate predicate = c_scope.getPredicate(ctx.predicate.getText()); Map<String, IObject> assignments = new HashMap<>(); if (ctx.assignment_list() != null) { ctx.assignment_list().assignment().forEach(ac -> { assignments.put(ac.field.getText(), new ObjectVisitor(solver, parser, scopes, environment).visit(ac.value)); }); } if (c_environment instanceof IObject) { if (c_environment instanceof IEnum) { assignments.put(Constants.SCOPE, (IObject) c_environment); } else { assignments.put(Constants.SCOPE, solver.getConstraintNetwork().newEnum((IType) c_scope, Arrays.asList((IObject) c_environment))); } } IFormula formula = null; IFormula cause = (environment.get("this") instanceof IFormula) ? (IFormula) environment.get("this") : null; if (ctx.goal != null) { formula = predicate.newGoal(cause, assignments); } else if (ctx.fact != null) { formula = predicate.newFact(cause, assignments); } environment.set(ctx.name.getText(), formula); if (environment == solver) { solver.defineField(new Field(ctx.name.getText(), predicate)); } } catch (ClassNotFoundException ex) { parser.notifyErrorListeners(ctx.predicate, ex.getMessage(), new RecognitionException(parser, parser.getInputStream(), ctx)); } return Boolean.TRUE; }
From source file:it.cnr.istc.iloc.ddl.TypeDeclaration.java
License:Open Source License
@Override public void enterTypedef_declaration(DDLParser.Typedef_declarationContext ctx) { IType primitive_type = new TypeVisitor(solver, parser, scopes).visit(ctx.primitive_type()); if (primitive_type == null) { parser.notifyErrorListeners(ctx.expr().start, "cannot find symbol " + ctx.primitive_type().getText(), new RecognitionException(parser, parser.getInputStream(), ctx.expr())); }/*from ww w . j a v a2 s. co m*/ if (ctx.expr() instanceof DDLParser.Range_expressionContext) { INumber min = (INumber) new ObjectVisitor(solver, parser, scopes, null) .visit(((DDLParser.Range_expressionContext) ctx.expr()).min); INumber max = (INumber) new ObjectVisitor(solver, parser, scopes, null) .visit(((DDLParser.Range_expressionContext) ctx.expr()).max); DDLTypeDef type_def = new DDLTypeDef(solver, scope, primitive_type, ctx.name.getText(), min, max); scope.defineType(type_def); } else if (ctx.expr() instanceof DDLParser.Literal_expressionContext) { INumber val = (INumber) new ObjectVisitor(solver, parser, scopes, null).visit(ctx.expr()); DDLTypeDef type_def = new DDLTypeDef(solver, scope, primitive_type, ctx.name.getText(), val, val); scope.defineType(type_def); } else { parser.notifyErrorListeners(ctx.expr().start, "Incompatible types: expected numeric expression", new RecognitionException(parser, parser.getInputStream(), ctx.expr())); } }