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