/// <summary> /// Creates node in context of given grammar, from completeEdge /// </summary> /// <param name="grammar">Grammar which rules created current node</param> /// <param name="completeEdge">Edge that will be represented by created node</param> internal Node(GrammarBase grammar, CompleteEdge completeEdge) { Edge = completeEdge; Grammar = grammar; if (TerminalEdge == null) { Name = completeEdge.CompleteLabel.Parent.Name; } else { Name = TerminalEdge.Parent.Name; } addChild(completeEdge.ExtendingEdge); var current = completeEdge.ExtendedEdge; while (current != null) { addChild(current.ExtendingEdge); current = current.ExtendedEdge; } ChildNodes.Reverse(); skipTransientChildren(); removePunctuation(); }
/// <summary> /// Creates parser, from given grammar /// (Accepts all CFG forms) /// </summary> /// <param name="grammar">Grammar specifing parsing rules</param> public Parser(GrammarBase grammar) { _grammar = grammar; grammar.Build(); var nonTerminals = grammar.CollectNonTerminals(grammar.Root); //prepare edges foreach (var nonTerm in nonTerminals) { foreach (var sequence in nonTerm.Rule.Sequences) { var activeLabel = new ActiveLabel(sequence); _activeChains.Add(sequence, activeLabel); } } buildEdgeTransitions(); //set root transitions _rootTransitions = getRootTransitions().ToArray(); }