ParserToken() public method

public ParserToken ( string code ) : IList
code string
return IList
Ejemplo n.º 1
0
    public object Eval(string script)
    {
        if (env == null)
        {
            Init();
        }

        var token = env.ParserToken(script);             //词法分析
        var expr  = env.Expr_CompilerToken(token, true); //语法分析,简单表达式,一句话
        var value = env.Expr_Execute(expr, content);     //执行表达式

        if (value == null)
        {
            return(null);
        }
        return(value.value);
    }
Ejemplo n.º 2
0
    public void BeginInit()
    {
        env = new CSLE.CLS_Environment(this);
        Log_Warn("C#Light Ver:" + env.version);

        //System
        env.RegType(new CSLE.RegHelper_Type(typeof(NotImplementedException), "NotImplementedException"));
        env.RegType(new CSLE.RegHelper_Type(typeof(Exception), "Exception"));
        env.RegType(new CSLE.RegHelper_Type(typeof(object), "object"));

        //Framework
        env.RegType(new CSLE.RegHelper_Type(typeof(IScreenForModel), "IScreenForModel"));
        env.RegType(new CSLE.RegHelper_Type(typeof(IGameForModel), "IGameForModel"));

        env.RegType(new CSLE.RegHelper_Type(typeof(IGameModel), "IGameForModel"));
        env.RegType(new CSLE.RegHelper_Type(typeof(IScriptModel), "IScriptModel"));
        env.RegType(new CSLE.RegHelper_Type(typeof(IUIToolModel), "IUIToolModel"));
        env.RegType(new CSLE.RegHelper_Type(typeof(IBlockSceneModel), "IBlockSceneModel"));

        //UnityEngine
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Debug), "Debug"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.GameObject), "GameObject"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Object), "Object"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Transform), "Transform"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.UI.Text), "Text"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.RectTransform), "RectTransform"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Vector2), "Vector2"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Vector3), "Vector3"));
        env.RegType(new CSLE.RegHelper_Type(typeof(UnityEngine.Vector4), "Vector4"));



        //直接编译模式
        string[] files = System.IO.Directory.GetFiles(Application.streamingAssetsPath + "/script", "*.cs", System.IO.SearchOption.AllDirectories);
        Dictionary <string, IList <CSLE.Token> > tokens = new Dictionary <string, IList <CSLE.Token> >();

        foreach (var f in files)
        {
            string code = System.IO.File.ReadAllText(f);
            var    t    = env.ParserToken(code);
            tokens[f] = t;
        }

        env.Project_Compiler(tokens, true);


        inited = true;
    }
Ejemplo n.º 3
0
    public static void CSLightDoString(string code)
    {
        var c    = new CSLE.CLS_Content(env, false);
        int hash = code.GetHashCode();

        if (expcache.ContainsKey(hash))
        {
            env.Expr_Execute(expcache[hash], c);
            return;
        }
        var t = env.ParserToken(code);
        var e = env.Expr_CompilerToken(t);

        expcache[hash] = e;
        env.Expr_Execute(e, c);
    }