Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Tests/Token.cs @ 6055

Last change on this file since 6055 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 2.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Globalization;
23
24namespace HeuristicLab.Problems.DataAnalysis.Tests {
25  internal enum TokenSymbol { LPAR, RPAR, SYMB, NUMBER };
26  internal class Token {
27    public static readonly Token LPAR = Token.Parse("(");
28    public static readonly Token RPAR = Token.Parse(")");
29
30    public TokenSymbol Symbol { get; set; }
31    public string StringValue { get; set; }
32    public double DoubleValue { get; set; }
33    public Token() { }
34
35    public override bool Equals(object obj) {
36      Token other = (obj as Token);
37      if (other == null) return false;
38      if (other.Symbol != Symbol) return false;
39      return other.StringValue == this.StringValue;
40    }
41
42    public static Token Parse(string strToken) {
43      strToken = strToken.Trim();
44      Token t = new Token();
45      t.StringValue = strToken.Trim();
46      double temp;
47      if (strToken == "") {
48        t = null;
49      } else if (strToken == "(") {
50        t.Symbol = TokenSymbol.LPAR;
51      } else if (strToken == ")") {
52        t.Symbol = TokenSymbol.RPAR;
53      } else if (double.TryParse(strToken, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out temp)) {
54        t.Symbol = TokenSymbol.NUMBER;
55        t.DoubleValue = double.Parse(strToken, CultureInfo.InvariantCulture.NumberFormat);
56      } else {
57        t.Symbol = TokenSymbol.SYMB;
58        t.StringValue = t.StringValue.ToUpper();
59      }
60      return t;
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.