1 | using System.Collections.Generic;
|
---|
2 | using System.Linq;
|
---|
3 | using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration;
|
---|
4 |
|
---|
5 | namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration {
|
---|
6 |
|
---|
7 | public abstract class Symbol {
|
---|
8 | public readonly string StringRepresentation;
|
---|
9 |
|
---|
10 | protected Symbol(string representation) {
|
---|
11 | StringRepresentation = representation;
|
---|
12 | }
|
---|
13 |
|
---|
14 | public override string ToString() {
|
---|
15 | return StringRepresentation;
|
---|
16 | }
|
---|
17 | }
|
---|
18 |
|
---|
19 | public class TerminalSymbol : Symbol {
|
---|
20 | public TerminalSymbol(string representation) : base(representation) { }
|
---|
21 | }
|
---|
22 |
|
---|
23 | public class NonterminalSymbol : Symbol {
|
---|
24 | public List<Production> Alternatives;
|
---|
25 |
|
---|
26 | public NonterminalSymbol(string representation) : base(representation) {
|
---|
27 | Alternatives = new List<Production>();
|
---|
28 | }
|
---|
29 |
|
---|
30 | public void AddProduction(params Symbol[] production) {
|
---|
31 | Alternatives.Add(new Production(production));
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | public class VariableSymbol : NonterminalSymbol { // Convenience class
|
---|
36 | public IEnumerable<TerminalSymbol> VariableTerminalSymbols;
|
---|
37 |
|
---|
38 | public VariableSymbol(string representation, IEnumerable<string> variableNames) : base(representation) {
|
---|
39 | List<TerminalSymbol> createdSymbols = new List<TerminalSymbol>();
|
---|
40 | VariableTerminalSymbols = createdSymbols;
|
---|
41 |
|
---|
42 | foreach (string variableName in variableNames) {
|
---|
43 | TerminalSymbol s = new TerminalSymbol(variableName);
|
---|
44 | createdSymbols.Add(s);
|
---|
45 | AddProduction(s);
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public class Production : List<Symbol> {
|
---|
51 |
|
---|
52 | public Production(params Symbol[] symbols) : base(symbols) { }
|
---|
53 |
|
---|
54 | public Production(IEnumerable<Symbol> symbols) : base(symbols) { }
|
---|
55 |
|
---|
56 | public override string ToString() {
|
---|
57 | return string.Join(" ", this);
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|