Ejemplo n.º 1
0
        public static xblock GetCodeBlock(string code)
        {
            xblock ret = null;

            Microsoft.JScript.Vsa.VsaEngine engine = new Microsoft.JScript.Vsa.VsaEngine();
            StringWriter sw = new StringWriter();

            engine.InitVsaEngine("test", new VsaSite(sw));
            DocumentContext docContext = new DocumentContext("", engine);
            Context         context    = new Context(docContext, code);
            JSParser        parser     = new JSParser(context);
            Block           block      = parser.ParseEvalBody();

            ret = new xjscript.xblock(block);

            engine.Close();
            // MessageBox.Show(((Completion)block.Evaluate()).value.ToString());

            return(ret);
        }
Ejemplo n.º 2
0
        public xast parser(AST ast)
        {
            xast ret = null;

            if (ast == null)
            {
            }
            else if (ast is VariableDeclaration)
            {
                ret = new xvardeclare((VariableDeclaration)ast);
            }
            else if (ast is Assign)
            {
                ret = new xassing((Assign)ast);
            }
            else if (ast is If)
            {
                ret = new xif((If)ast);
            }
            else if (ast is While)
            {
                ret = new xwhile((While)ast);
            }
            else if (ast is Expression)
            {
                ret = new xexpr((Expression)ast);
            }
            else if (ast is Block)
            {
                ret = new xblock((Block)ast);
            }
            else if (ast is ConstantWrapper)
            {
                ret = new xconstantwrapper((ConstantWrapper)ast);
            }
            else if (ast is For)
            {
                ret = new xfor((For)ast);
            }
            else if (ast is Call)
            {
                ret = new xcall((Call)ast);
            }
            else if (ast is Equality)
            {
                ret = new xequality((Equality)ast);
            }
            else if (ast is Relational)
            {
                ret = new xrelational((Relational)ast);
            }
            else if (ast is PostOrPrefixOperator)
            {
                ret = new xpostorprefixoperator((PostOrPrefixOperator)ast);
            }
            else if (ast is Lookup)
            {
                ret = new xlookup((Lookup)ast);
            }
            else if (ast is Call)
            {
                ret = new xcall((Call)ast);
            }
            else if (ast is ASTList)
            {
                ret = new xastlist((ASTList)ast);
            }
            return(ret);
        }