1 package it.unical.mat.parsers.asp.dlv;
3 import it.unical.mat.parsers.asp.ASPDataCollection;
4 import org.antlr.v4.runtime.BailErrorStrategy;
5 import org.antlr.v4.runtime.CharStreams;
6 import org.antlr.v4.runtime.CommonTokenStream;
7 import org.antlr.v4.runtime.ConsoleErrorListener;
8 import org.antlr.v4.runtime.DefaultErrorStrategy;
9 import org.antlr.v4.runtime.RecognitionException;
10 import org.antlr.v4.runtime.atn.PredictionMode;
16 this.answerSets = answerSets;
21 answerSets.addAnswerSet();
23 return visitChildren(ctx);
28 answerSets.addAnswerSet();
30 return visitChildren(ctx);
35 answerSets.addAnswerSet();
37 return visitChildren(ctx);
42 answerSets.storeCost(Integer.parseInt(ctx.INTEGER_CONSTANT(1).getText()), Integer.parseInt(ctx.INTEGER_CONSTANT(0).getText()));
49 answerSets.storeAtom(ctx.getText());
54 public static void parse(
final ASPDataCollection answerSets,
final String atomsList,
final boolean two_stageParsing) {
55 final CommonTokenStream tokens =
new CommonTokenStream(
new DLVLexer(CharStreams.fromString(atomsList)));
59 if(!two_stageParsing) {
60 visitor.visit(parser.output());
65 parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
66 parser.removeErrorListeners();
67 parser.setErrorHandler(
new BailErrorStrategy());
70 visitor.visit(parser.output());
71 }
catch (
final RuntimeException exception) {
72 if(exception.getClass() == RuntimeException.class && exception.getCause() instanceof RecognitionException) {
74 parser.addErrorListener(ConsoleErrorListener.INSTANCE);
75 parser.setErrorHandler(
new DefaultErrorStrategy());
76 parser.getInterpreter().setPredictionMode(PredictionMode.LL);
77 visitor.visit(parser.output());