public static Token Parse(string strToken) { strToken = strToken.Trim(); Token t = new Token(); t.StringValue = strToken.Trim(); double temp; if (strToken == "") { t = null; } else if (strToken == "(") { t.Symbol = TokenSymbol.LPAR; } else if (strToken == ")") { t.Symbol = TokenSymbol.RPAR; } else if (double.TryParse(strToken, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out temp)) { t.Symbol = TokenSymbol.NUMBER; t.DoubleValue = double.Parse(strToken, CultureInfo.InvariantCulture.NumberFormat); } else { t.Symbol = TokenSymbol.SYMB; t.StringValue = t.StringValue.ToUpper(); } return t; }
private void Expect(Token token, Queue<Token> tokens) { Token cur = tokens.Dequeue(); if (!token.Equals(cur)) throw new FormatException("Expected: " + token.StringValue + ", but got: " + cur.StringValue); }
private ISymbolicExpressionTreeNode CreateTree(Token token) { if (token.Symbol != TokenSymbol.SYMB) throw new FormatException("Expected function symbol, but got: " + token.StringValue); return knownSymbols[token.StringValue].CreateTreeNode(); }