void DecorateCore() { ReadSettings(); var productions = _config.Productions; var initial = productions.Count; PopulateUsings(); for (var i = 0; i < initial; i++) { DecorateProduction(productions[i]); } if (productions.Count == 0) { _reporter.AddError(1, 1, 1, 1, "No productions defined."); return; } PopulateTopLevelSegments(); DetectUnreachableNonTerminals(); if (!VerifyProductionReferences()) { return; } _config.UseErrorRecovery = _terminals.ContainsKey(Segment.Error.Name); _config.Graph = ParseGraph.ConstructGraph(_config); ValidateGraph(); }
static object GenerateParseGraph(string text) { var errorReporter = new Mock <IErrorReporter>(MockBehavior.Strict); var parser = new ConfigParser(errorReporter.Object); var config = parser.Parse(new ConfigScanner(text)); SyntaxTreeDecorator.Decorate(config, errorReporter.Object); var parse = ParseGraph.ConstructGraph(config); return(parse.Graph); }
public void ConstructDFA1() { var parseGraph = ParseGraph.ConstructGraph(ConstructSample1()); const string expected = "0 (S) -- <A> --> 1 \r\n" + "[<A'> -> • <A>, EOF] [<A'> -> <A> •, EOF] \r\n" + "[<A> -> • a, EOF] \r\n" + "[<A> -> • ( <A> ), EOF] \r\n" + "0 (S) -- a --> 2 \r\n" + "[<A'> -> • <A>, EOF] [<A> -> a •, )/EOF] \r\n" + "[<A> -> • a, EOF] \r\n" + "[<A> -> • ( <A> ), EOF] \r\n" + "0 (S) -- ( --> 3 \r\n" + "[<A'> -> • <A>, EOF] [<A> -> • a, )] \r\n" + "[<A> -> • a, EOF] [<A> -> • ( <A> ), )] \r\n" + "[<A> -> • ( <A> ), EOF] [<A> -> ( • <A> ), )/EOF]\r\n" + "3 -- a --> 2 \r\n" + "[<A> -> • a, )] [<A> -> a •, )/EOF] \r\n" + "[<A> -> • ( <A> ), )] \r\n" + "[<A> -> ( • <A> ), )/EOF] \r\n" + "3 -- ( --> 3 \r\n" + "[<A> -> • a, )] [<A> -> • a, )] \r\n" + "[<A> -> • ( <A> ), )] [<A> -> • ( <A> ), )] \r\n" + "[<A> -> ( • <A> ), )/EOF] [<A> -> ( • <A> ), )/EOF]\r\n" + "3 -- <A> --> 4 \r\n" + "[<A> -> • a, )] [<A> -> ( <A> • ), EOF] \r\n" + "[<A> -> • ( <A> ), )] \r\n" + "[<A> -> ( • <A> ), )/EOF] \r\n" + "4 -- ) --> 5 \r\n" + "[<A> -> ( <A> • ), EOF] [<A> -> ( <A> ) •, )/EOF]\r\n" + ""; const string expectedStartPoints = "<A>: 0\r\n" + ""; var renderer = new ParseRenderer(); Assert.That(renderer.Render(parseGraph.Graph, 25), Is.EqualTo(expected)); Assert.That(renderer.StartPointsRenderer(parseGraph), Is.EqualTo(expectedStartPoints)); }
public void ConstructDFA2() { var parseGraph = ParseGraph.ConstructGraph(ConstructSample2()); const string expected = "0 (S) -- <E> --> 1 \r\n" + "[<E'> -> • <E>, EOF] [<E'> -> <E> •, EOF] \r\n" + "[<E> -> • n, EOF] \r\n" + "[<E> -> • <V>, EOF] \r\n" + "[<V> -> • id, EOF] \r\n" + "0 (S) -- n --> 2 \r\n" + "[<E'> -> • <E>, EOF] [<E> -> n •, EOF] \r\n" + "[<E> -> • n, EOF] \r\n" + "[<E> -> • <V>, EOF] \r\n" + "[<V> -> • id, EOF] \r\n" + "0 (S) -- <V> --> 3 \r\n" + "[<E'> -> • <E>, EOF] [<E> -> <V> •, EOF] \r\n" + "[<E> -> • n, EOF] \r\n" + "[<E> -> • <V>, EOF] \r\n" + "[<V> -> • id, EOF] \r\n" + "0 (S) -- id --> 4 \r\n" + "[<E'> -> • <E>, EOF] [<V> -> id •, EOF] \r\n" + "[<E> -> • n, EOF] \r\n" + "[<E> -> • <V>, EOF] \r\n" + "[<V> -> • id, EOF] \r\n" + "5 (S) -- <S> --> 6 \r\n" + "[<S'> -> • <S>, EOF] [<S'> -> <S> •, EOF] \r\n" + "[<S> -> • id, EOF] \r\n" + "[<S> -> • <V> := <E>, EOF] \r\n" + "[<V> -> • id, :=] \r\n" + "5 (S) -- id --> 7 \r\n" + "[<S'> -> • <S>, EOF] [<S> -> id •, EOF] \r\n" + "[<S> -> • id, EOF] [<V> -> id •, :=] \r\n" + "[<S> -> • <V> := <E>, EOF] \r\n" + "[<V> -> • id, :=] \r\n" + "5 (S) -- <V> --> 8 \r\n" + "[<S'> -> • <S>, EOF] [<S> -> <V> • := <E>, EOF]\r\n" + "[<S> -> • id, EOF] \r\n" + "[<S> -> • <V> := <E>, EOF] \r\n" + "[<V> -> • id, :=] \r\n" + "8 -- := --> 9 \r\n" + "[<S> -> <V> • := <E>, EOF] [<E> -> • n, EOF] \r\n" + " [<E> -> • <V>, EOF] \r\n" + " [<V> -> • id, EOF] \r\n" + " [<S> -> <V> := • <E>, EOF]\r\n" + "9 -- n --> 2 \r\n" + "[<E> -> • n, EOF] [<E> -> n •, EOF] \r\n" + "[<E> -> • <V>, EOF] \r\n" + "[<V> -> • id, EOF] \r\n" + "[<S> -> <V> := • <E>, EOF] \r\n" + "9 -- <V> --> 3 \r\n" + "[<E> -> • n, EOF] [<E> -> <V> •, EOF] \r\n" + "[<E> -> • <V>, EOF] \r\n" + "[<V> -> • id, EOF] \r\n" + "[<S> -> <V> := • <E>, EOF] \r\n" + "9 -- id --> 4 \r\n" + "[<E> -> • n, EOF] [<V> -> id •, EOF] \r\n" + "[<E> -> • <V>, EOF] \r\n" + "[<V> -> • id, EOF] \r\n" + "[<S> -> <V> := • <E>, EOF] \r\n" + "9 -- <E> --> 10 \r\n" + "[<E> -> • n, EOF] [<S> -> <V> := <E> •, EOF]\r\n" + "[<E> -> • <V>, EOF] \r\n" + "[<V> -> • id, EOF] \r\n" + "[<S> -> <V> := • <E>, EOF] \r\n" + ""; const string expectedStartPoints = "<E>: 0\r\n" + "<S>: 5\r\n" + ""; var renderer = new ParseRenderer(); Assert.That(renderer.Render(parseGraph.Graph, 26), Is.EqualTo(expected)); Assert.That(renderer.StartPointsRenderer(parseGraph), Is.EqualTo(expectedStartPoints)); }