IEnumerable<ProductionModel> Repetition(EbnfFactorRepetition repetition, ProductionModel currentProduction) { var name = repetition.ToString(); var nonTerminal = new NonTerminal(name); var repetitionProduction = new ProductionModel(nonTerminal); currentProduction.AddWithAnd(new NonTerminalModel(nonTerminal)); var expression = repetition.Expression; foreach (var production in Expression(expression, repetitionProduction)) yield return production; repetitionProduction.AddWithAnd(new NonTerminalModel(nonTerminal)); repetitionProduction.Lambda(); yield return repetitionProduction; }
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; }
IEnumerable<ProductionModel> Optional(EbnfFactorOptional optional, ProductionModel currentProduction) { var name = optional.ToString(); var nonTerminal = new NonTerminal(name); var optionalProduction = new ProductionModel(nonTerminal); currentProduction.AddWithAnd(new NonTerminalModel(nonTerminal)); var expression = optional.Expression; foreach (var production in Expression(expression, optionalProduction)) yield return production; optionalProduction.Lambda(); yield return optionalProduction; }