Exemple #1
0
        public string TranspileToCSharp(string whileCode)
        {
            string sharpCode = null;

            try
            {
                var result = whileParser.Parse(whileCode);
                if (result.IsOk)
                {
                    var ast = result.Result;

                    var checker = new SemanticChecker();

                    var context = checker.SemanticCheck(ast);

                    sharpCode = ast.Transpile(context);
                    sharpCode = GetCSharpCode(sharpCode, Guid.NewGuid().ToString());
                }
            }
            catch
            {
                sharpCode = null;
            }


            return(sharpCode);
        }
Exemple #2
0
        public Func <int> CompileToFunction(string whileCode)
        {
            Func <int> function = null;

            try
            {
                var result = whileParser.Parse(whileCode);
                if (result.IsOk)
                {
                    var ast = result.Result;

                    var checker = new SemanticChecker();

                    var context = checker.SemanticCheck(ast);

                    var emiter = Emit <Func <int> > .NewDynamicMethod("Method" + Guid.NewGuid());

                    emiter = ast.EmitByteCode(context, emiter);
                    //emiter.LoadConstant(42);
                    //emiter.Return();
                    function = emiter.CreateDelegate();
                    object res = function.Invoke();
                }
            }
            catch
            {
                function = null;
            }


            return(function);
        }
Exemple #3
0
        public string TranspileToCSharp(string whileCode)
        {
            string sharpCode = null;

            try
            {
                ParseResult <WhileToken, WhileAST> result = whileParser.Parse(whileCode);
                if (result.IsOk)
                {
                    WhileAST ast = result.Result;

                    SemanticChecker checker = new SemanticChecker();

                    CompilerContext context = checker.SemanticCheck(ast);

                    sharpCode = ast.Transpile(context);
                    sharpCode = GetCSharpCode(sharpCode, Guid.NewGuid().ToString());
                }
            }
            catch
            {
                sharpCode = null;
            }


            return(sharpCode);
        }