Exemplo n.º 1
0
 public bool Load(Dsl.ISyntaxComponent dsl, Interpreter interpreter)
 {
     m_Interpreter = interpreter;
     m_Dsl         = dsl;
     Dsl.ValueData valueData = dsl as Dsl.ValueData;
     if (null != valueData)
     {
         return(Load(valueData));
     }
     else
     {
         Dsl.FunctionData funcData = dsl as Dsl.FunctionData;
         if (null != funcData)
         {
             if (funcData.HaveParam())
             {
                 var  callData = funcData;
                 bool ret      = Load(callData);
                 if (!ret)
                 {
                     int num = callData.GetParamNum();
                     List <IExpression> args = new List <IExpression>();
                     for (int ix = 0; ix < num; ++ix)
                     {
                         Dsl.ISyntaxComponent param = callData.GetParam(ix);
                         args.Add(interpreter.Load(param));
                     }
                     return(Load(args));
                 }
                 return(ret);
             }
             else
             {
                 return(Load(funcData));
             }
         }
         else
         {
             Dsl.StatementData statementData = dsl as Dsl.StatementData;
             if (null != statementData)
             {
                 return(Load(statementData));
             }
         }
     }
     return(false);
 }
Exemplo n.º 2
0
 public void AddStatement(ValueData statement)
 {
     m_Statements.Add(statement);
     if ((int)ExtentClassEnum.EXTENT_CLASS_STATEMENT != m_ExtentClass) {
         m_ExtentClass = (int)ExtentClassEnum.EXTENT_CLASS_STATEMENT;
     }
 }
Exemplo n.º 3
0
 public void CopyFrom(CallData other)
 {
     m_IsHighOrder = other.m_IsHighOrder;
     m_Name = other.m_Name;
     m_Call = other.m_Call;
     m_Params = other.m_Params;
     m_ParamClass = other.m_ParamClass;
 }
Exemplo n.º 4
0
 public void Clear()
 {
     m_Name = null;
     m_Call = null;
     m_IsHighOrder = false;
     m_Params = new List<ISyntaxComponent>();
     m_ParamClass = (int)ParamClassEnum.PARAM_CLASS_NOTHING;
 }
Exemplo n.º 5
0
 public void AddParams(ValueData param)
 {
     m_Params.Add(param);
     if ((int)ParamClassEnum.PARAM_CLASS_NOTHING == m_ParamClass) {
         m_ParamClass = (int)ParamClassEnum.PARAM_CLASS_PARENTHESIS;
     }
 }
Exemplo n.º 6
0
 public void CopyFrom(ValueData other)
 {
     m_Type = other.m_Type;
     m_Id = other.m_Id;
     m_Line = other.m_Line;
 }
Exemplo n.º 7
0
 internal static void writeBinary(MemoryStream stream, List<string> identifiers, ValueData data)
 {
     stream.WriteByte((byte)DslBinaryCode.BeginValue);
     if (null != data) {
         stream.WriteByte((byte)((int)DslBinaryCode.ValueTypeBegin + data.GetIdType()));
         identifiers.Add(data.GetId());
     }
     stream.WriteByte((byte)DslBinaryCode.EndValue);
 }
Exemplo n.º 8
0
 internal static void readBinary(byte[] bytes, ref int curCodeIndex, List<string> identifiers, ref int curIdIndex, CallData data)
 {
     byte code = readByte(bytes, curCodeIndex++);
     if (code == (byte)DslBinaryCode.BeginCall) {
         code = readByte(bytes, curCodeIndex);
         if (code >= (byte)DslBinaryCode.ParamTypeBegin) {
             ++curCodeIndex;
             data.SetParamClass(code - (byte)DslBinaryCode.ParamTypeBegin);
         }
         code = readByte(bytes, curCodeIndex);
         if (code == (byte)DslBinaryCode.BeginValue) {
             ValueData valueData = new ValueData();
             readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, valueData);
             data.Name = valueData;
         } else if (code == (byte)DslBinaryCode.BeginCall) {
             CallData callData = new CallData();
             readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, callData);
             data.Call = callData;
         }
         for (; ; ) {
             code = readByte(bytes, curCodeIndex);
             if (code == (byte)DslBinaryCode.EndCall) {
                 ++curCodeIndex;
                 break;
             } else {
                 ISyntaxComponent syntaxData = readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex);
                 if (null != syntaxData) {
                     data.Params.Add(syntaxData);
                 } else {
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 9
0
 internal static void readBinary(byte[] bytes, ref int curCodeIndex, List<string> identifiers, ref int curIdIndex, ValueData data)
 {
     byte code = readByte(bytes, curCodeIndex++);
     if (code == (byte)DslBinaryCode.BeginValue) {
         code = readByte(bytes, curCodeIndex);
         if (code >= (byte)DslBinaryCode.ValueTypeBegin) {
             ++curCodeIndex;
             data.SetType(code - (byte)DslBinaryCode.ValueTypeBegin);
             data.SetId(readIdentifier(identifiers, curIdIndex++));
         }
         code = readByte(bytes, curCodeIndex);
         if (code == (byte)DslBinaryCode.EndValue) {
             ++curCodeIndex;
         }
     }
 }
Exemplo n.º 10
0
 internal static ISyntaxComponent readBinary(byte[] bytes, ref int curCodeIndex, List<string> identifiers, ref int curIdIndex)
 {
     ISyntaxComponent ret = null;
     byte code = readByte(bytes, curCodeIndex);
     if (code == (byte)DslBinaryCode.BeginValue) {
         ValueData data = new ValueData();
         readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, data);
         ret = data;
     } else if (code == (byte)DslBinaryCode.BeginCall) {
         CallData data = new CallData();
         readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, data);
         ret = data;
     } else if (code == (byte)DslBinaryCode.BeginFunction) {
         FunctionData data = new FunctionData();
         readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, data);
         ret = data;
     } else if (code == (byte)DslBinaryCode.BeginStatement) {
         StatementData data = new StatementData();
         readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, data);
         ret = data;
     }
     return ret;
 }
Exemplo n.º 11
0
 protected override bool Load(Dsl.ValueData valData)
 {
     m_VarId = valData.GetId();
     return(true);
 }
Exemplo n.º 12
0
 protected virtual bool Load(Dsl.ValueData valData)
 {
     return(false);
 }
Exemplo n.º 13
0
        public IExpression Load(Dsl.ISyntaxComponent comp)
        {
            Dsl.ValueData    valueData = comp as Dsl.ValueData;
            Dsl.FunctionData funcData  = null;
            if (null != valueData)
            {
                int idType = valueData.GetIdType();
                if (idType == Dsl.ValueData.ID_TOKEN)
                {
                    string id = valueData.GetId();
                    if (id == "true" || id == "false")
                    {
                        ConstGet constExp = new ConstGet();
                        constExp.Load(comp, this);
                        return(constExp);
                    }
                    else
                    {
                        NamedVarGet varExp = new NamedVarGet();
                        varExp.Load(comp, this);
                        return(varExp);
                    }
                }
                else
                {
                    ConstGet constExp = new ConstGet();
                    constExp.Load(comp, this);
                    return(constExp);
                }
            }
            else
            {
                funcData = comp as Dsl.FunctionData;
                if (null != funcData && funcData.HaveParam())
                {
                    var    callData = funcData;
                    string op       = callData.GetId();
                    if (op == "=")  //赋值
                    {
                        IExpression exp  = null;
                        string      name = callData.GetParamId(0);
                        exp = new NamedVarSet();
                        if (null != exp)
                        {
                            exp.Load(comp, this);
                        }
                        else
                        {
                            //error
                            Log("Interpreter error, {0} line {1}", callData.ToScriptString(false), callData.GetLine());
                        }
                        return(exp);
                    }
                }
            }
            IExpression ret   = null;
            string      expId = comp.GetId();

            if (null != funcData && !funcData.IsHighOrder && m_Funcs.ContainsKey(expId))
            {
                ret = new FuncCallExp();
            }
            else
            {
                IExpressionFactory factory;
                if (m_Apis.TryGetValue(expId, out factory))
                {
                    ret = factory.Create();
                }
            }
            if (null != ret)
            {
                if (!ret.Load(comp, this))
                {
                    //error
                    Log("Interpreter error, {0} line {1}", comp.ToScriptString(false), comp.GetLine());
                }
            }
            else
            {
                //error
                Log("Interpreter error, {0} line {1}", comp.ToScriptString(false), comp.GetLine());
            }
            return(ret);
        }