public void Can_Evaluate_Assignments() { var assignment = "x = (2 + 2) * 5"; var parseResult = _engine.ParseString(assignment); Assert.IsTrue(parseResult.IsAssignmentResult); Assert.AreEqual("x", (parseResult as AssignmentResult).Item.Variable); Assert.AreEqual(20, _engine.EvaluateExpression <int>((parseResult as AssignmentResult).Item.Expression)); }
private void ParseStatement(string statement) { ParseResult parseResult = null; try { parseResult = _engine.ParseString(statement); } catch { throw new ParseException(statement); } switch (parseResult) { case AssignmentResult assignment: _id = assignment.Item.Variable; _expression = assignment.Item.Expression; break; default: throw new ParseException($"Statement {statement} is not an assignment statement. Cannot use Expressions directly."); } }