Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Tests/Token.cs @ 5831

Last change on this file since 5831 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 2.4 KB
RevLine 
[2447]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2447]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
[2625]22using System.Globalization;
[2447]23
[3733]24namespace HeuristicLab.Problems.DataAnalysis.Tests {
25  internal enum TokenSymbol { LPAR, RPAR, SYMB, NUMBER };
26  internal class Token {
[2447]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
[4545]42    public override int GetHashCode() {
43      return Symbol.GetHashCode() & StringValue.GetHashCode();
44    }
45
[2447]46    public static Token Parse(string strToken) {
47      strToken = strToken.Trim();
48      Token t = new Token();
49      t.StringValue = strToken.Trim();
50      double temp;
51      if (strToken == "") {
52        t = null;
53      } else if (strToken == "(") {
54        t.Symbol = TokenSymbol.LPAR;
55      } else if (strToken == ")") {
56        t.Symbol = TokenSymbol.RPAR;
[2625]57      } else if (double.TryParse(strToken, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out temp)) {
[2447]58        t.Symbol = TokenSymbol.NUMBER;
[2625]59        t.DoubleValue = double.Parse(strToken, CultureInfo.InvariantCulture.NumberFormat);
[2447]60      } else {
61        t.Symbol = TokenSymbol.SYMB;
[3746]62        t.StringValue = t.StringValue.ToUpper();
[2447]63      }
64      return t;
65    }
66  }
67}
Note: See TracBrowser for help on using the repository browser.