1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.IO;
|
---|
6 | using HeuristicLab.Modeling.Database;
|
---|
7 | using HeuristicLab.Modeling.Database.SQLServerCompact;
|
---|
8 | using HeuristicLab.GP;
|
---|
9 | using HeuristicLab.GP.Interfaces;
|
---|
10 | using HeuristicLab.GP.StructureIdentification;
|
---|
11 | using System.Diagnostics;
|
---|
12 |
|
---|
13 | namespace CedmaImporter {
|
---|
14 | public enum TokenSymbol { LPAR, RPAR, SYMB, NUMBER };
|
---|
15 | public class Token {
|
---|
16 | public static readonly Token LPAR = Token.Parse("(");
|
---|
17 | public static readonly Token RPAR = Token.Parse(")");
|
---|
18 |
|
---|
19 | public TokenSymbol Symbol { get; set; }
|
---|
20 | public string StringValue { get; set; }
|
---|
21 | public double DoubleValue { get; set; }
|
---|
22 | public Token() { }
|
---|
23 |
|
---|
24 | public override bool Equals(object obj) {
|
---|
25 | Token other = (obj as Token);
|
---|
26 | if (other == null) return false;
|
---|
27 | if (other.Symbol != Symbol) return false;
|
---|
28 | return other.StringValue == this.StringValue;
|
---|
29 | }
|
---|
30 |
|
---|
31 | public static Token Parse(string strToken) {
|
---|
32 | strToken = strToken.Trim();
|
---|
33 | Token t = new Token();
|
---|
34 | t.StringValue = strToken.Trim();
|
---|
35 | double temp;
|
---|
36 | if (strToken == "") {
|
---|
37 | t = null;
|
---|
38 | } else if (strToken == "(") {
|
---|
39 | t.Symbol = TokenSymbol.LPAR;
|
---|
40 | } else if (strToken == ")") {
|
---|
41 | t.Symbol = TokenSymbol.RPAR;
|
---|
42 | } else if (double.TryParse(strToken, out temp)) {
|
---|
43 | t.Symbol = TokenSymbol.NUMBER;
|
---|
44 | t.DoubleValue = double.Parse(strToken);
|
---|
45 | } else {
|
---|
46 | t.Symbol = TokenSymbol.SYMB;
|
---|
47 | }
|
---|
48 | return t;
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|