private EbnfBlockRule VisitRuleNode(IInternalTreeNode node) { EbnfQualifiedIdentifier qualifiedIdentifier = 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.QualifiedIdentifier == symbolValue) { qualifiedIdentifier = VisitQualifiedIdentifierNode(internalNode); } else if (EbnfGrammar.Expression == symbolValue) { expression = VisitExpressionNode(internalNode); } break; case TreeNodeType.Token: break; } } return(new EbnfBlockRule( new EbnfRule(qualifiedIdentifier, expression))); }
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> Expression(EbnfExpression expression, ProductionModel currentProduction) { foreach (var production in Term(expression.Term, currentProduction)) { yield return(production); } if (expression.NodeType != EbnfNodeType.EbnfExpressionAlteration) { yield break; } var expressionAlteration = expression as EbnfExpressionAlteration; currentProduction.Lambda(); foreach (var production in Expression(expressionAlteration.Expression, currentProduction)) { yield return(production); } }
public EbnfFactorGrouping(EbnfExpression expression) { Expression = expression; _hashCode = ComputeHashCode(); }
public EbnfFactorOptional(EbnfExpression expression) { Expression = expression; _hashCode = ComputeHashCode(); }
public EbnfFactorRepetition(EbnfExpression expression) { Expression = expression; _hashCode = ComputeHashCode(); }
public EbnfRule(EbnfQualifiedIdentifier qualifiedIdentifier, EbnfExpression expression) { QualifiedIdentifier = qualifiedIdentifier; Expression = expression; _hashCode = ComputeHashCode(); }