3 using Antlr4.Runtime.Atn;
13 this.answerSets = answerSets;
18 answerSets.AddAnswerSet();
20 return VisitChildren(context);
23 public override object VisitModel(ClingoParser.ModelContext context)
25 string cost = context.NEW_LINE().GetText().Trim();
29 string[] tokens = cost.Split(
' ');
30 int levels = tokens.Length - 1;
32 for (
int i = 1; i < tokens.Length; i++)
33 answerSets.StoreCost(levels--, Int32.Parse(tokens[i]));
36 return VisitChildren(context);
41 answerSets.StoreAtom(context.GetText());
46 public static void Parse(
IASPDataCollection answerSets,
string atomsList,
bool two_stageParsing)
48 CommonTokenStream tokens =
new CommonTokenStream(
new ClingoLexer(CharStreams.fromstring(atomsList)));
49 ClingoParser parser =
new ClingoParser(tokens);
52 if (!two_stageParsing)
54 visitor.Visit(parser.output());
59 parser.Interpreter.PredictionMode = PredictionMode.SLL;
61 parser.RemoveErrorListeners();
63 parser.ErrorHandler =
new BailErrorStrategy();
67 visitor.Visit(parser.output());
69 catch (SystemException exception)
71 if (exception.GetBaseException() is RecognitionException)
74 parser.AddErrorListener(ConsoleErrorListener<object>.Instance);
76 parser.ErrorHandler =
new DefaultErrorStrategy();
77 parser.Interpreter.PredictionMode = PredictionMode.LL;
79 visitor.Visit(parser.output());