private Token GetToken() { token = new Token() { Value = "", Type = TokenType.End }; while ((index < code.Length) && char.IsWhiteSpace(code[index])) index++; if (index < code.Length) { if (code[index].IsIn(delimiters)) { int start = index++; switch (code[start]) { case '<': switch (code[index]) { case '=': index++; break; case '>': index++; break; } break; case '>': case '=': if (code[index] == '=') { index++; } break; case '&': if (code[index] == '&') { index++; } break; case '|': if (code[index] == '|') { index++; } break; } string op = code.Substring(start, index - start); token = new Token() { Value = op, Type = TokenType.Delimiter }; } else if (char.IsLetter(code[index])) { int start = index++; while ((index < code.Length) && !code[index].IsDelim(delimiters)) { index++; } string name = code.Substring(start, index - start); TokenType type = TokenType.Variable; if (functions.ContainsKey(name.ToUpper())) type = TokenType.Function; token = new Token() { Value = name, Type = type }; } else if (char.IsDigit(code[index])) { int start = index++; while ((index < code.Length) && (char.IsDigit(code[index]) || (code[index] == '.'))) { index++; } token = new Token() { Value = code.Substring(start, index - start), Type = TokenType.Number }; } } return token; }
private double ProcessVariable() { double retVal = 0; if (token.Type == TokenType.Variable) { Token left = token; int start = index; GetToken(); if (token.Value != "=") // no es una asignacion { index = start; // Devuelvo a la posicion anterior token = left; retVal = ProcessFunction(); } else // es una asignacion { GetToken(); retVal = ProcessFunction(); vars[left.Value.ToUpper()] = retVal; } } else { retVal = ProcessFunction(); vars["X"] = retVal; } return retVal; }