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