Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Symbol.cs @ 15723

Last change on this file since 15723 was 15723, checked in by lkammere, 6 years ago

#2886: Add simple data analysis tests and further informations about algorithm run.

File size: 1.8 KB
Line 
1using System.Collections.Generic;
2using System.Linq;
3using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration;
4
5namespace 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}
Note: See TracBrowser for help on using the repository browser.