Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/tools/CedmaImporter/Token.cs @ 2320

Last change on this file since 2320 was 2261, checked in by gkronber, 15 years ago

Refactoring: extracted classes. #719

File size: 1.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.IO;
6using HeuristicLab.Modeling.Database;
7using HeuristicLab.Modeling.Database.SQLServerCompact;
8using HeuristicLab.GP;
9using HeuristicLab.GP.Interfaces;
10using HeuristicLab.GP.StructureIdentification;
11using System.Diagnostics;
12
13namespace 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}
Note: See TracBrowser for help on using the repository browser.