public void ValidExpressionContainsNoUnrecognizedTokens() { TheLexer lexer = new TheLexer(); var tokens = lexer.GetTokens("3 + 5"); Assert.AreEqual(0, tokens.Count(p => p.GetType() == typeof (UnrecognizedToken))); }
public void UnrecognizedTokenDetected() { TheLexer lexer = new TheLexer(); var tokens = lexer.GetTokens("3 xyz 5"); Assert.AreEqual(1, tokens.Count(p => p.GetType() == typeof(UnrecognizedToken))); }
/// <summary> /// Evaluates the expression /// </summary> public decimal Evaluate() { Lexer.TheLexer lexer = new Lexer.TheLexer(); var tokens = lexer.GetTokens(_expression).ToList(); Parser parser = new Parser(new OperationOrder()); ExpressionTree expressionTree = parser.Parse(tokens); return expressionTree.Walk(); }
/// <summary> /// Evaluates the expression /// </summary> public decimal Evaluate() { Lexer.TheLexer lexer = new Lexer.TheLexer(); var tokens = lexer.GetTokens(_expression).ToList(); Parser parser = new Parser(new OperationOrder()); ExpressionTree expressionTree = parser.Parse(tokens); return(expressionTree.Walk()); }