private EbnfTerm VisitTermNode(IInternalTreeNode node) { EbnfFactor factor = null; EbnfTerm 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 (EbnfGrammar.Factor == symbolValue) { factor = VisitFactorNode(internalNode); } else if (EbnfGrammar.Term == symbolValue) { term = VisitTermNode(internalNode); } break; case TreeNodeType.Token: break; } } if (term == null) { return(new EbnfTerm(factor)); } return(new EbnfTermConcatenation(factor, term)); }
private EbnfExpression VisitExpressionNode(IInternalTreeNode node) { EbnfTerm term = null; EbnfExpression 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 (EbnfGrammar.Term == symbolValue) { term = VisitTermNode(internalNode); } else if (EbnfGrammar.Expression == symbolValue) { expression = VisitExpressionNode(internalNode); } break; case TreeNodeType.Token: break; } } if (expression == null) { return(new EbnfExpression(term)); } return(new EbnfExpressionAlteration(term, expression)); }
public EbnfExpressionAlteration( EbnfTerm term, EbnfExpression expression) : base(term) { Expression = expression; _hashCode = ComputeHashCode(); }
IEnumerable <ProductionModel> Term(EbnfTerm term, ProductionModel currentProduction) { foreach (var production in Factor(term.Factor, currentProduction)) { yield return(production); } if (term.NodeType != EbnfNodeType.EbnfTermConcatenation) { yield break; } var concatenation = term as EbnfTermConcatenation; foreach (var production in Term(concatenation.Term, currentProduction)) { yield return(production); } }
public EbnfExpression(EbnfTerm term) { Term = term; _hashCode = ComputeHashCode(); }
public EbnfTermConcatenation(EbnfFactor factor, EbnfTerm term) : base(factor) { Term = term; _hashCode = ComputeHashCode(); }
IEnumerable<ProductionModel> Term(EbnfTerm term, ProductionModel currentProduction) { foreach (var production in Factor(term.Factor, currentProduction)) yield return production; if (term.NodeType != EbnfNodeType.EbnfTermConcatenation) yield break; var concatenation = term as EbnfTermConcatenation; foreach(var production in Term(concatenation.Term, currentProduction)) yield return production; }