Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4027 was 3746, checked in by gkronber, 15 years ago

Added project for HeuristicLab.Problems.DataAnalysis.Tests. #791

File size: 2.4 KB
RevLine 
[2447]1#region License Information
2/* HeuristicLab
[3733]3 * Copyright (C) 2002-2010 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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using System.IO;
27using System.Diagnostics;
[2625]28using System.Globalization;
[2447]29
[3733]30namespace HeuristicLab.Problems.DataAnalysis.Tests {
31  internal enum TokenSymbol { LPAR, RPAR, SYMB, NUMBER };
32  internal class Token {
[2447]33    public static readonly Token LPAR = Token.Parse("(");
34    public static readonly Token RPAR = Token.Parse(")");
35
36    public TokenSymbol Symbol { get; set; }
37    public string StringValue { get; set; }
38    public double DoubleValue { get; set; }
39    public Token() { }
40
41    public override bool Equals(object obj) {
42      Token other = (obj as Token);
43      if (other == null) return false;
44      if (other.Symbol != Symbol) return false;
45      return other.StringValue == this.StringValue;
46    }
47
48    public static Token Parse(string strToken) {
49      strToken = strToken.Trim();
50      Token t = new Token();
51      t.StringValue = strToken.Trim();
52      double temp;
53      if (strToken == "") {
54        t = null;
55      } else if (strToken == "(") {
56        t.Symbol = TokenSymbol.LPAR;
57      } else if (strToken == ")") {
58        t.Symbol = TokenSymbol.RPAR;
[2625]59      } else if (double.TryParse(strToken, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out temp)) {
[2447]60        t.Symbol = TokenSymbol.NUMBER;
[2625]61        t.DoubleValue = double.Parse(strToken, CultureInfo.InvariantCulture.NumberFormat);
[2447]62      } else {
63        t.Symbol = TokenSymbol.SYMB;
[3746]64        t.StringValue = t.StringValue.ToUpper();
[2447]65      }
66      return t;
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.