protected override bool Load(Dsl.StatementData statementData) { //简化语法while(exp) func(args);语法的处理 if (statementData.GetFunctionNum() == 2) { var first = statementData.First; var second = statementData.Second; var firstId = first.GetId(); var secondId = second.GetId(); if (firstId == "while" && !first.HaveStatement() && !first.HaveExternScript() && !string.IsNullOrEmpty(secondId) && !second.HaveStatement() && !second.HaveExternScript()) { if (first.GetParamNum() > 0) { Dsl.ISyntaxComponent cond = first.GetParam(0); m_Condition = Interpreter.Load(cond); } else { //error Interpreter.Log("Interpreter error, {0} line {1}", first.ToScriptString(false), first.GetLine()); } IExpression subExp = Interpreter.Load(second); m_Expressions.Add(subExp); return(true); } } return(false); }
protected override bool Load(Dsl.FunctionData callData) { Dsl.ISyntaxComponent param1 = callData.GetParam(0); Dsl.ISyntaxComponent param2 = callData.GetParam(1); m_VarId = param1.GetId(); m_Val = Interpreter.Load(param2); return(true); }
protected override bool Load(FunctionData funcData) { if (!funcData.IsHighOrder && funcData.HaveParam()) { m_Func = funcData.GetId(); int num = funcData.GetParamNum(); for (int ix = 0; ix < num; ++ix) { Dsl.ISyntaxComponent param = funcData.GetParam(ix); m_Args.Add(Interpreter.Load(param)); } return(true); } return(false); }
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); }
protected override bool Load(Dsl.FunctionData funcData) { if (funcData.IsHighOrder) { Dsl.ISyntaxComponent cond = funcData.LowerOrderFunction.GetParam(0); m_Condition = Interpreter.Load(cond); for (int ix = 0; ix < funcData.GetParamNum(); ++ix) { IExpression subExp = Interpreter.Load(funcData.GetParam(ix)); m_Expressions.Add(subExp); } } else { //error Interpreter.Log("Interpreter error, {0} line {1}", funcData.ToScriptString(false), funcData.GetLine()); } return(true); }
protected override bool Load(Dsl.StatementData statementData) { Dsl.FunctionData funcData1 = statementData.First; Dsl.FunctionData funcData2 = statementData.Second; if (funcData1.IsHighOrder && funcData1.HaveLowerOrderParam() && funcData2.GetId() == ":" && funcData2.HaveParamOrStatement()) { Dsl.ISyntaxComponent cond = funcData1.LowerOrderFunction.GetParam(0); Dsl.ISyntaxComponent op1 = funcData1.GetParam(0); Dsl.ISyntaxComponent op2 = funcData2.GetParam(0); m_Op1 = Interpreter.Load(cond); m_Op2 = Interpreter.Load(op1); m_Op3 = Interpreter.Load(op2); } else { //error Interpreter.Log("Interpreter error, {0} line {1}", statementData.ToScriptString(false), statementData.GetLine()); } return(true); }
protected override bool Load(Dsl.StatementData statementData) { //简化语法if(exp) func(args);语法的处理 int funcNum = statementData.GetFunctionNum(); if (funcNum == 2) { var first = statementData.First; var second = statementData.Second; var firstId = first.GetId(); var secondId = second.GetId(); if (firstId == "if" && !first.HaveStatement() && !first.HaveExternScript() && !string.IsNullOrEmpty(secondId) && !second.HaveStatement() && !second.HaveExternScript()) { IfExp.Clause item = new IfExp.Clause(); if (first.GetParamNum() > 0) { Dsl.ISyntaxComponent cond = first.GetParam(0); item.Condition = Interpreter.Load(cond); } else { //error Interpreter.Log("Interpreter error, {0} line {1}", first.ToScriptString(false), first.GetLine()); } IExpression subExp = Interpreter.Load(second); item.Expressions.Add(subExp); m_Clauses.Add(item); return(true); } } //标准if语句的处理 foreach (var fData in statementData.Functions) { if (fData.GetId() == "if" || fData.GetId() == "elseif") { IfExp.Clause item = new IfExp.Clause(); if (fData.IsHighOrder && fData.LowerOrderFunction.GetParamNum() > 0) { Dsl.ISyntaxComponent cond = fData.LowerOrderFunction.GetParam(0); item.Condition = Interpreter.Load(cond); } else { //error Interpreter.Log("Interpreter error, {0} line {1}", fData.ToScriptString(false), fData.GetLine()); } for (int ix = 0; ix < fData.GetParamNum(); ++ix) { IExpression subExp = Interpreter.Load(fData.GetParam(ix)); item.Expressions.Add(subExp); } m_Clauses.Add(item); } else if (fData.GetId() == "else") { if (fData != statementData.Last) { //error Interpreter.Log("Interpreter error, {0} line {1}", fData.ToScriptString(false), fData.GetLine()); } else { IfExp.Clause item = new IfExp.Clause(); for (int ix = 0; ix < fData.GetParamNum(); ++ix) { IExpression subExp = Interpreter.Load(fData.GetParam(ix)); item.Expressions.Add(subExp); } m_Clauses.Add(item); } } else { //error Interpreter.Log("Interpreter error, {0} line {1}", fData.ToScriptString(false), fData.GetLine()); } } return(true); }
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); }