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); }
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.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); }
public void AddStatement(StatementData statement) { m_Statements.Add(statement); if ((int)ExtentClassEnum.EXTENT_CLASS_STATEMENT != m_ExtentClass) { m_ExtentClass = (int)ExtentClassEnum.EXTENT_CLASS_STATEMENT; } }
public void AddParams(StatementData param) { m_Params.Add(param); if ((int)ParamClassEnum.PARAM_CLASS_NOTHING == m_ParamClass) { m_ParamClass = (int)ParamClassEnum.PARAM_CLASS_PARENTHESIS; } }
internal static void writeBinary(MemoryStream stream, List<string> identifiers, StatementData data) { stream.WriteByte((byte)DslBinaryCode.BeginStatement); foreach (FunctionData funcData in data.Functions) { writeBinary(stream, identifiers, funcData); } stream.WriteByte((byte)DslBinaryCode.EndStatement); }
internal static void readBinary(byte[] bytes, ref int curCodeIndex, List<string> identifiers, ref int curIdIndex, StatementData data) { byte code = readByte(bytes, curCodeIndex++); if (code == (byte)DslBinaryCode.BeginStatement) { for (; ; ) { code = readByte(bytes, curCodeIndex); if (code == (byte)DslBinaryCode.BeginFunction) { FunctionData funcData = new FunctionData(); readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, funcData); data.Functions.Add(funcData); } else if (code == (byte)DslBinaryCode.EndStatement) { ++curCodeIndex; break; } else { break; } } } }
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; }
public static void writeStatementData(StringBuilder stream, StatementData data, int indent) { #if FULL_VERSION FunctionData tempData = data.First; CallData callData = tempData.Call; if (null != callData && callData.GetParamClass() == (int)CallData.ParamClassEnum.PARAM_CLASS_TERNARY_OPERATOR) { if (callData.HaveId() && callData.HaveParam() && tempData.HaveStatement()) { string line = string.Format("{0} {1} {2}", callData.GetParam(0).ToScriptString(true), callData.GetId(), tempData.GetStatement(0).ToScriptString(true)); if (data.Functions.Count == 2) { FunctionData funcData = data.Functions[1]; if (funcData.HaveId() && funcData.HaveStatement()) line = string.Format("{0} {1} {2}", line, funcData.GetId(), funcData.GetStatement(0).ToScriptString(true)); } writeContent(stream, line + ";", indent); } } else { int ct = data.Functions.Count; bool isLastOfStatement = false; if (ct == 0) isLastOfStatement = true; for (int i = 0; i < ct; ++i) { if (i == ct - 1) isLastOfStatement = true; FunctionData func = data.Functions[i]; writeFunctionData(stream, func, indent, isLastOfStatement); } } #endif }
public void CopyFrom(StatementData other) { CopyComments(other); m_Functions = other.m_Functions; }
public void CopyFrom(StatementData other) { m_Functions = other.m_Functions; }
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); }
protected virtual bool Load(Dsl.StatementData statementData) { return(false); }