private TestScriptExpression ParseExpression() { bool isLeftHandSide; TestScriptExpression leftHandSide = ParseUnaryExpression(out isLeftHandSide); return(ParseExpression(leftHandSide, isLeftHandSide)); }
private static TestScriptValue Eval(TestScriptExpression expression, TestScriptEvalContext context) { switch (expression.Type) { case TestScriptExpressionType.String: return(new TestScriptValue(((TestScriptString)expression).Text, TestScriptValueType.String)); case TestScriptExpressionType.Integer: return(new TestScriptValue(((TestScriptInteger)expression).Value, TestScriptValueType.Long)); case TestScriptExpressionType.EnumValue: { TestScriptEnumValue enumExp = (TestScriptEnumValue)expression; ProtoSpecModule module = context.ProtoSpec.Modules.GetByName(enumExp.Module, true); if (module == null) { Error("上下文中并不包含模块“" + module + "”的定义"); } long value = module.EnumValues.GetValueByName(enumExp.Name, true); if (value < 0) { Error("模块“" + module + "”中并不包含枚举值“" + enumExp.Name + "”的定义"); } return(TestScriptValue.CreateEnum(enumExp.Module, enumExp.Name, value)); } case TestScriptExpressionType.FunctionCall: { TestScriptFunctionCall funExp = (TestScriptFunctionCall)expression; ProtoSpecModule module = context.ProtoSpec.Modules.GetByName(funExp.Module, true); if (module == null) { Error("上下文中不存在模块“" + module + "”"); } ProtoSpecAction action = module.Actions.GetByName(funExp.Function, true); if (action == null) { Error("模块“" + module + "”中不存在操作“" + funExp.Function + "”"); } return(SendData(context, action, funExp.ParamList)); } } return(null); }
private TestScriptStatement ParseStatement() { TestScriptExpression expression = ParseExpression(); if (expression != null) { NextToken(); if (CurrentToken.Type != TestScriptTokenType.Semicolon) { Error("语句必须以“;”作为末尾"); } return(new TestScriptStatement(expression)); } return(null); }
public TestScriptStatement(TestScriptExpression expression) { Expression = expression; }
private static TestScriptValue Eval(TestScriptExpression expression, TestScriptEvalContext context) { switch (expression.Type) { case TestScriptExpressionType.String: return(new TestScriptValue(((TestScriptString)expression).Text, TestScriptValueType.String)); case TestScriptExpressionType.Integer: return(new TestScriptValue(((TestScriptInteger)expression).Value, TestScriptValueType.Long)); case TestScriptExpressionType.EnumValue: { TestScriptEnumValue enumExp = (TestScriptEnumValue)expression; ProtoSpecModule module = context.ProtoSpec.Modules.GetByName(enumExp.Module, true); if (module == null) { Error("上下文中并不包含模块“" + module + "”的定义"); } long value = module.EnumValues.GetValueByName(enumExp.Name, true); if (value < 0) { Error("模块“" + module + "”中并不包含枚举值“" + enumExp.Name + "”的定义"); } return(TestScriptValue.CreateEnum(enumExp.Module, enumExp.Name, value)); } case TestScriptExpressionType.FunctionCall: { TestScriptFunctionCall funExp = (TestScriptFunctionCall)expression; if (funExp.Module == "proto") { switch (funExp.Function) { case "clean": if (funExp.ParamList.Count == 0) { Clean(context, 1000); } else if (funExp.ParamList.Count == 1 && funExp.ParamList[0].Type == TestScriptExpressionType.Integer) { Clean(context, (int)((TestScriptInteger)funExp.ParamList[0]).Value); } else { Error("函数“proto:clean()”的参数个数应该为0个或1个"); } break; } return(null); } else { ProtoSpecModule module = context.ProtoSpec.Modules.GetByName(funExp.Module, true); if (module == null) { Error("上下文中不存在模块“" + module + "”"); } ProtoSpecAction action = module.Actions.GetByName(funExp.Function, true); if (action == null) { Error("模块“" + module + "”中不存在操作“" + funExp.Function + "”"); } return(SendData(context, action, funExp.ParamList)); } } } return(null); }
private TestScriptExpression ParseUnaryExpression(out bool isLeftHandSide) { TestScriptExpression expression = null; isLeftHandSide = false; switch (CurrentToken.Type) { case TestScriptTokenType.Integer: expression = new TestScriptInteger(long.Parse(CurrentToken.Text)); isLeftHandSide = false; break; case TestScriptTokenType.String: expression = new TestScriptString(CurrentToken.StringText); isLeftHandSide = false; break; case TestScriptTokenType.Identifier: string module = CurrentToken.Text; NextToken(); if (CurrentToken.Type != TestScriptTokenType.Colon) { Error("模块名后应该要有“:”"); } NextToken(); if (CurrentToken.Type != TestScriptTokenType.Identifier) { Error("缺少成员名称"); } string name = CurrentToken.Text; NextToken(); if (CurrentToken.Type == TestScriptTokenType.LeftParen) { TestScriptExpressionList paramList = new TestScriptExpressionList(); do { NextToken(); TestScriptExpression param = ParseExpression(); if (param != null) { paramList.Add(param); NextToken(); } }while (CurrentToken.Type == TestScriptTokenType.Comma); if (CurrentToken.Type != TestScriptTokenType.RightParen) { Error("缺少右括号"); } expression = new TestScriptFunctionCall(module, name, paramList); isLeftHandSide = false; } else { expression = new TestScriptEnumValue(module, name); isLeftHandSide = false; } break; } return(expression); }
private TestScriptExpression ParseExpression(TestScriptExpression leftHandSide, bool canAssign) { return(leftHandSide); }