2 using System.Collections.Generic;
4 using Antlr4.Runtime.Atn;
11 private Dictionary<int, int> costs;
15 this.answerSets = answerSets;
20 answerSets.AddAnswerSet();
22 if (context.cost() !=
null && !context.cost().IsEmpty)
24 costs =
new Dictionary<int, int>();
25 string[] FirstCost = context.cost().COST_LABEL().GetText().Split(
' ')[1].Split(
'@');
27 costs[Int32.Parse(FirstCost[1])] = Int32.Parse(FirstCost[0]);
31 foreach (KeyValuePair<int, int> entry
in costs)
32 answerSets.StoreCost(entry.Key, entry.Value);
34 return VisitChildren(context);
37 public override object VisitLevel(DLV2Parser.LevelContext context)
39 int level = Int32.Parse(context.INTEGER()[1].GetText()), cost = Int32.Parse(context.INTEGER()[0].GetText());
42 answerSets.StoreCost(level, cost);
49 answerSets.StoreAtom(context.GetText());
54 public static void Parse(
IASPDataCollection answerSets,
string atomsList,
bool two_stageParsing)
56 CommonTokenStream tokens =
new CommonTokenStream(
new DLV2Lexer(CharStreams.fromstring(atomsList)));
57 DLV2Parser parser =
new DLV2Parser(tokens);
60 if (!two_stageParsing)
62 visitor.Visit(parser.output());
67 parser.Interpreter.PredictionMode = PredictionMode.SLL;
69 parser.RemoveErrorListeners();
71 parser.ErrorHandler =
new BailErrorStrategy();
75 visitor.Visit(parser.output());
77 catch (SystemException exception)
79 if (exception.GetBaseException() is RecognitionException)
82 parser.AddErrorListener(ConsoleErrorListener<object>.Instance);
84 parser.ErrorHandler =
new DefaultErrorStrategy();
85 parser.Interpreter.PredictionMode = PredictionMode.LL;
87 visitor.Visit(parser.output());