private PdlTerm VisitTermNode(IInternalTreeNode node) { PdlFactor factor = null; PdlTerm term = null; for (int c = 0; c < node.Children.Count; c++) { var child = node.Children[c]; switch (child.NodeType) { case TreeNodeType.Internal: var internalNode = child as IInternalTreeNode; var symbolValue = internalNode.Symbol.Value; if (PdlGrammar.Factor == symbolValue) { factor = VisitFactorNode(internalNode); } else if (PdlGrammar.Term == symbolValue) { term = VisitTermNode(internalNode); } break; case TreeNodeType.Token: break; } } if (term is null) { return(new PdlTerm(factor)); } return(new PdlTermConcatenation(factor, term)); }
private PdlExpression VisitExpressionNode(IInternalTreeNode node) { PdlTerm term = null; PdlExpression expression = null; for (int c = 0; c < node.Children.Count; c++) { var child = node.Children[c]; switch (child.NodeType) { case TreeNodeType.Internal: var internalNode = child as IInternalTreeNode; var symbolValue = internalNode.Symbol.Value; if (PdlGrammar.Term == symbolValue) { term = VisitTermNode(internalNode); } else if (PdlGrammar.Expression == symbolValue) { expression = VisitExpressionNode(internalNode); } break; case TreeNodeType.Token: break; } } if (expression is null) { return(new PdlExpression(term)); } return(new PdlExpressionAlteration(term, expression)); }
public PdlExpressionAlteration( PdlTerm term, PdlExpression expression) : base(term) { Expression = expression; _hashCode = ComputeHashCode(); }
IEnumerable <ProductionModel> Term(PdlTerm term, ProductionModel currentProduction) { foreach (var production in Factor(term.Factor, currentProduction)) { yield return(production); } if (term.NodeType != PdlNodeType.PdlTermConcatenation) { yield break; } var concatenation = term as PdlTermConcatenation; foreach (var production in Term(concatenation.Term, currentProduction)) { yield return(production); } }
public PdlTermConcatenation(PdlFactor factor, PdlTerm term) : base(factor) { Term = term; _hashCode = ComputeHashCode(); }
public PdlExpression(PdlTerm term) { Term = term; _hashCode = ComputeHashCode(); }