using System.Collections.Generic; using System.Linq; namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration { public abstract class Symbol { public readonly string StringRepresentation; protected Symbol(string representation) { StringRepresentation = representation; } public override string ToString() { return StringRepresentation; } } public class TerminalSymbol : Symbol { public TerminalSymbol(string representation) : base(representation) { } } public class NonterminalSymbol : Symbol { public List Alternatives; public NonterminalSymbol(string representation) : base(representation) { Alternatives = new List(); } public void AddProduction(params Symbol[] production) { Alternatives.Add(new Production(production)); } } public class VariableSymbol : NonterminalSymbol { // Convenience class public IEnumerable VariableTerminalSymbols; public VariableSymbol(string representation, IEnumerable variableNames) : base(representation) { List createdSymbols = new List(); VariableTerminalSymbols = createdSymbols; foreach (string variableName in variableNames) { TerminalSymbol s = new TerminalSymbol(variableName); createdSymbols.Add(s); AddProduction(s); } } } public class Production : List { public Production(params Symbol[] symbols) : base(symbols) { } public Production(IEnumerable symbols) : base(symbols) { } public override string ToString() { return string.Join(" ", this); } } }