/// <summary> /// Compile a Mond program from a string. /// </summary> /// <param name="source">Source code to compile</param> /// <param name="fileName">Optional file name to use in errors</param> /// <param name="generateDebugInfo">Enable generating debug info</param> public static MondProgram Compile(string source, string fileName = null, bool generateDebugInfo = true) { var lexer = new Lexer(source, fileName); var parser = new Parser(lexer); var expression = parser.ParseAll(); expression.SetParent(null); expression.Simplify(); //expression.Print(0); var compiler = new ExpressionCompiler(generateDebugInfo); return compiler.Compile(expression); }
public MondValue Evaluate(string expression) { var options = new MondCompilerOptions(); var lexer = new Lexer("return " + expression, "debug", options); var parser = new Parser(lexer); var expr = parser.ParseStatement(false); var rewriter = new DebugExpressionRewriter(LocalObjectName); expr = expr.Accept(rewriter).Simplify(); expr.SetParent(null); var oldLocal = _state[LocalObjectName]; _state[LocalObjectName] = _localObject; var program = new ExpressionCompiler(options).Compile(expr); var result = _state.Load(program); _state[LocalObjectName] = oldLocal; return result; }