public override bool Parse() { if (mInfo.Name != "STMT") { Debug.LogError("error node:" + mInfo); return(false); } VarRef npcId = PeType.GetNpcId(mInfo, mTrigger); int id = (int)npcId.Value; Pathea.PeEntity entity = Pathea.EntityMgr.Instance.Get(id); if (null == entity) { Debug.LogError("can't find entity:" + id); return(false); } mMove = entity.GetCmpt <Pathea.Motion_Move>(); if (null == mMove) { Debug.LogError("can't find move cmpt:"); return(false); } return(true); }
protected override bool Exec() { VarRef timerName = PatheaScript.Util.GetVarRefOrValue(mInfo, "id", VarValue.EType.String, mTrigger); Functor initSecFunctor = mFactory.GetFunctor(mInfo, "set1"); VarRef initSec = PatheaScript.Util.GetVarRefOrValue(mInfo, "sec", VarValue.EType.Float, mTrigger); Functor speedFunctor = mFactory.GetFunctor(mInfo, "set2"); VarRef speed = PatheaScript.Util.GetVarRefOrValue(mInfo, "speed", VarValue.EType.Float, mTrigger); initSecFunctor.Set(new Variable(), initSec.Var); initSecFunctor.Do(); speedFunctor.Set(new Variable(), speed.Var); speedFunctor.Do(); PETimer timer = new PETimer(); timer.Second = (double)((float)initSecFunctor.Target.Value); timer.ElapseSpeed = (float)speedFunctor.Target.Value; //PETimerMgr.Instance.Remove(timerName); PeTimerMgr.Instance.Add((string)timerName.Value, timer); return(true); }
/// <summary> /// Validate a variable reference. /// </summary> /// <param name="e"> /// is the expression. </param> /// <returns> null. </returns> public virtual object visit(VarRef e) { QName @var = e.name(); if (!expandVarQName(@var)) { reportBadPrefix(@var.prefix()); } if (!isVariableInScope(@var)) { reportError(new StaticNameError(StaticNameError.NAME_NOT_FOUND)); } if (getVariableType(@var) == null) { reportError(new StaticNameError(StaticNameError.NAME_NOT_FOUND)); } // The variable is good. If it was not captured, it must be referring to an external var if (!isVariableCaptured(@var)) { _freeVariables.Add(@var.asQName()); } return(null); }
protected override bool Exec() { VarRef timerName = PatheaScript.Util.GetVarRefOrValue(mInfo, "id", VarValue.EType.String, mTrigger); PeTimerMgr.Instance.Remove((string)timerName.Value); return(true); }
public override bool Parse() { mTimerName = PatheaScript.Util.GetVarRefOrValue(mInfo, "id", VarValue.EType.String, mTrigger); mCompare = mFactory.GetCompare(mInfo, "compare"); mRef = PatheaScript.Util.GetVarRefOrValue(mInfo, "sec", VarValue.EType.Float, mTrigger); return(true); }
public override void Build() { ns("MyNameSpace"); declClass(TypePublic, "MyClass"); VarRef testVar = "TestVariable"; declMethod(MemPublic, "System.Void", "MyMethod"); enter(testVar); }
public override bool Parse() { if (false == base.Parse()) { return(false); } mMosterId = PeType.GetMonsterId(mInfo, mTrigger); return(true); }
public override bool Parse() { if (false == base.Parse()) { return(false); } mVarRef = PeType.GetUIId(mInfo, mTrigger); return(true); }
public override bool Parse() { if (false == base.Parse()) { return(false); } mT = PatheaScript.Util.GetVarRefOrValue(mInfo, "t", VarValue.EType.Int, mTrigger); mQ = PatheaScript.Util.GetVarRefOrValue(mInfo, "q", VarValue.EType.Int, mTrigger); return(true); }
public override bool Parse() { mPlayerId = PeType.GetPlayerId(mInfo, mTrigger); mItemId = PeType.GetItemId(mInfo, mTrigger); mItemCount = PatheaScript.Util.GetVarRefOrValue(mInfo, "count", VarValue.EType.Int, mTrigger); mCompare = mFactory.GetCompare(mInfo, "compare"); return(true); }
public override bool Parse() { mCompare = mFactory.GetCompare(mInfo, "compare"); mCount = PatheaScript.Util.GetVarRefOrValue(mInfo, "count", VarValue.EType.Int, mTrigger); mMonsterId = PeType.GetMonsterId(mInfo, mTrigger); PeEvent.Globle.kill.Subscribe(Handler); return(true); }
protected override bool Exec() { VarRef playerId = PeType.GetPlayerId(mInfo, mTrigger); VarRef itemIdVarRef = PeType.GetItemId(mInfo, mTrigger); VarRef count = PatheaScript.Util.GetVarRefOrValue(mInfo, "count", VarValue.EType.Int, mTrigger); Functor modify = mFactory.GetFunctor(mInfo, "modify"); List <Pathea.PeEntity> playerList = PeType.GetPlayer((int)playerId.Value); int itemId = (int)itemIdVarRef.Value; foreach (Pathea.PeEntity player in playerList) { Pathea.PlayerPackageCmpt pkg = player.GetCmpt <Pathea.PlayerPackageCmpt>(); ItemAsset.ItemPackage accessor = pkg.package._playerPak; int itemCount = accessor.GetCount(itemId); modify.Set(new Variable(itemCount), count.Var); modify.Do(); int newItemCount = (int)(modify.Target.Value); if (newItemCount == itemCount) { continue; } else if (newItemCount > itemCount) { int dd = newItemCount - itemCount; if (!accessor.Add(itemId, dd)) { Debug.LogError("Add item:" + itemId + " to player:" + player + " failed."); } else { Debug.Log("Add item:" + itemId + " count:" + dd + " to player:" + player + " succeed."); } } else { int dd = itemCount - newItemCount; accessor.Destroy(itemId, dd); Debug.Log("remove item:" + itemId + " count:" + dd + "from player:" + player + " succeed."); } } return(true); }
private static void SelectedItemChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { if (e.OldValue != e.NewValue && e.NewValue != null) { ItemSelector vsSource = source as ItemSelector; VarRef newRef = e.NewValue as VarRef; foreach (var a in vsSource.lstItems.Items) { VarRef srcRef = a as VarRef; if (newRef != null && srcRef != null && newRef.LinkedVarId == srcRef.LinkedVarId) { vsSource.lstItems.SelectedItem = srcRef; } } } //(source as VariableSelector).lstItems.SelectedItem = (source as VariableSelector).lstItems.Items.where ((VarRef)a).LinkedVarId == ((VarRef)e.NewValue).LinkedVarId select a).FirstOrDefault(); }
protected override bool Exec() { VarRef playerId = PeType.GetPlayerId(mInfo, mTrigger); VarRef varRef = PatheaScript.Util.GetVarRefOrValue(mInfo, "pos", VarValue.EType.Vector3, mTrigger); //TODO:need parse func List <Pathea.PeEntity> playerList = PeType.GetPlayer((int)playerId.Value); foreach (Pathea.PeEntity player in playerList) { Pathea.PeTrans v = player.GetCmpt <Pathea.PeTrans>(); v.position = (Vector3)varRef.Value; } return(true); }
public void Visit(AssignExpr assignExpr, object[] args) { assignExpr.LeftExpr.Accept(this); assignExpr.RightExpr.Accept(this); RightValue v = readRightValue(assignExpr.RightExpr); assignExpr.RightValue = v; if (assignExpr.LeftExpr.LeftValue is VarRef) { VarRef varRef = assignExpr.LeftExpr.LeftValue as VarRef; scopeStack.SetValue(varRef.VarName, v); } else { throw new Exception(); } }
private RightValue readRightValue(LeftValue leftValue, Location loc) { if (leftValue is VarRef) { VarRef var = leftValue as VarRef; RightValue result = scopeStack.GetValue(var.VarName); if (result == null) { throw new RuntimeException(new Error(ErrorType.VariableNotInitialized, loc, var.VarName)); } else { return(result); } } //只有上面一种情况 throw new Exception(); }
private void CreateInspectorForRow(InspectorTypes type, VarRef var, int row) { UserControl control = Inspectors.CreateInspector(type, var); switch (type) { case InspectorTypes.kMatrix4x4: Grid.SetRowSpan(control, 4); break; case InspectorTypes.kMatrix3x3: Grid.SetRowSpan(control, 3); break; } Grid.SetRow(control, row); Grid.SetColumn(control, 1); grid1.Children.Add(control); }
public override void Build() { ns("MyNameSpace"); declClass(TypePublic, "MyClass"); declMethod(MemPublic, "System.Void", "MonMethod"); VarRef testInt = declVar("System.Int32", "testInt", new Literal(0)); forOn(equate(testInt, new Literal(1))); forTest(testInt < new Literal(10)); forInc(testInt + new Literal(1)); hi("for statements come here"); MethodRef writeLine = new MethodRef("System.Console", "WriteLine"); MethodRef testIntToStr = new MethodRef(testInt, "ToString"); enter(ex(writeLine, ex(testIntToStr))); forOff(); }
public override void Build() { ns("MyNameSpace"); declClass(TypePublic, "MyClass"); declMethod(MemPublic, "System.Void", "MyMethod"); Literal stringPrimitive = "Test-String"; Literal intPrimitive = 10; Literal floatPrimitive = new Literal(10.2); Literal nullPrimitive = new Literal(null); VarRef SomeVar = "SomeVar"; enter(equate(SomeVar, stringPrimitive)); enter(equate(SomeVar, intPrimitive)); enter(equate(SomeVar, floatPrimitive)); enter(equate(SomeVar, nullPrimitive)); }
protected override MethodResult Get() { VarRef targetVariable = (VarRef)Parameters[0]; if (targetVariable.Var is IndexedVar == false) { throw SyntaxErrorException.InvalidVarRefType(targetVariable.Var.Name, VarType.Indexed, ParameterLocations[0]); } IndexedVar var = (IndexedVar)targetVariable.Var; VariableChaseData chaseData = GetChaseData(var, TranslateContext); Element[] actions = ArrayBuilder <Element> .Build ( chaseData.Rate.SetVariable(new V_Number(0), targetVariable.Target) ); return(new MethodResult(actions, null)); }
public void AddInspector(string label, InspectorTypes type, VarRef var) { int row = grid1.RowDefinitions.Count - 1; // There is always one row in the designer to fill the item with switch (type) { case InspectorTypes.kMatrix3x3: DefineRows(3); break; case InspectorTypes.kMatrix4x4: DefineRows(4); break; default: DefineRows(1); break; } CreateLabelForRow(label, row); CreateInspectorForRow(type, var, row); }
public override void Build() { ns("MyNameSpace"); declClass(TypePublic, "MyClass"); declMethod(MemPublic, "System.Void", "MonMethod"); VarRef boolVar = "boolVar"; VarRef otherBoolVar = "otherBoolVar"; ifOn(boolVar); hi("If Outer If condition is true execute these statements"); ifOn(otherBoolVar); hi("If the Inner If is true execute these statements"); elseOn(); hi("If the Inner If is false execute these statements"); ifOff(); hi("Continue with Other statements in the Outer If"); elseOn(); hi("Outer Else block. If condition is false, execute these statements."); ifOff(); }
public override bool Parse() { mTimeMs = PatheaScript.Util.GetVarRefOrValue(mInfo, "ms", VarValue.EType.Int, mTrigger); return(true); }
private void Emit(VarRef value) => code.Append($"a[{Math.Abs(value.Varnum) % 100}]");
/// <param name="e"> /// is the veriable reference. </param> /// <returns> e </returns> public virtual object visit(VarRef e) { return(null); }
/// <summary> /// end表示字符串最后一个字符的后一个位置 /// </summary> /// <param name="begin"></param> /// <param name="end"></param> /// <returns></returns> private Expression parse(int begin, int end) { if (begin >= end) { kernel.IssueError(ErrorType.ExpressionSyntaxError, loc.Offset(begin)); return(null); } while (isWhiteSpace(expr[begin])) { begin++; } while (isWhiteSpace(expr[end - 1])) { end--; } int currentParenLevel; bool hasSideParren = true; while (expr[begin] == '(' && hasSideParren) { currentParenLevel = 0; int currentPos; for (currentPos = begin; currentPos < end; currentPos++) { if (expr[currentPos] == '(') { currentParenLevel++; } else if (expr[currentPos] == ')') { currentParenLevel--; if (currentParenLevel == 0) { if (currentPos == end - 1) { begin++; end--; } else { hasSideParren = false; } break; } } } if (currentPos == end && currentParenLevel > 0) { kernel.IssueError(ErrorType.SingleParen, loc.Offset(begin)); return(null); } } currentParenLevel = 0; OpLevel currentLevel = OpLevel.Null; OpLevel minLevel = OpLevel.Null; int minPos = -1; int minOpLength = 0; bool findOp = false; string op = null; MatchTokenResult matchTokenResult; //找到当前应处理的操作符 for (int currentPos = begin; currentPos < end; currentPos = matchTokenResult.EndPos) { //if (expr[currentPos] == ' ' || expr[currentPos] == '\t' || expr[currentPos] == '\n' // || Environment.NewLine.IndexOf(expr[currentPos]) != -1) //{ // op = null; // continue; //} matchTokenResult = MatchToken(currentPos, end); if (matchTokenResult.TokenType == TokenType.Error) { return(null); } if (matchTokenResult.TokenType != TokenType.Operator) { continue; } op = matchTokenResult.Matched; if (op != "(" && op != ")") { findOp = true; } if (op == "(") { currentParenLevel++; continue; } else if (op == ")") { currentParenLevel--; continue; } else if (currentParenLevel > 0) { continue; } else if (currentParenLevel < 0) { kernel.IssueError(ErrorType.SingleParen, loc.Offset(currentPos)); return(null); } if (currentParenLevel == 0 && ( (int)(currentLevel = getOpLevel(op)) < (int)minLevel) || ((int)currentLevel == (int)minLevel && op != "=") //=为右结合 ) { minLevel = currentLevel; minPos = matchTokenResult.BeginPos; minOpLength = op.Length; } } if (currentParenLevel != 0) { kernel.IssueError(ErrorType.SingleParen, loc.Offset(begin)); return(null); } if (!findOp) //单个数据 { string str = expr.Substring(begin, end - begin); int currentPos = begin; matchTokenResult = MatchToken(currentPos, end); switch (matchTokenResult.TokenType) { case TokenType.Int: RightValueExpr intResult = new RightValueExpr(); IntConst intConst = new IntConst(); intConst.Value = int.Parse(matchTokenResult.Matched); intResult.DataType = DataType.Int; intResult.RightValue = intConst; intResult.Location = loc.Offset(begin); return(intResult); case TokenType.Float: RightValueExpr floatResult = new RightValueExpr(); FloatConst floatConst = new FloatConst(); floatConst.Value = float.Parse(matchTokenResult.Matched); floatResult.DataType = DataType.Float; //modified by Wander @ 2011 floatResult.RightValue = floatConst; floatResult.Location = loc.Offset(begin); return(floatResult); case TokenType.String: RightValueExpr strResult = new RightValueExpr(); StringConst strConst = new StringConst(); strConst.Value = matchTokenResult.Matched; strResult.DataType = DataType.String; strResult.RightValue = strConst; strResult.Location = loc.Offset(begin); return(strResult); case TokenType.Bool: RightValueExpr boolResult = new RightValueExpr(); BoolConst boolConst = new BoolConst(); boolConst.Value = bool.Parse(matchTokenResult.Matched); boolResult.DataType = DataType.Bool; boolResult.RightValue = boolConst; boolResult.Location = loc.Offset(begin); return(boolResult); case TokenType.Variable: VarRef varRef = new VarRef(); varRef.VarName = matchTokenResult.Matched; LeftValueExpr leftValueResult = new LeftValueExpr(); leftValueResult.DataType = DataType.Unknown; leftValueResult.Location = loc.Offset(begin); leftValueResult.LeftValue = varRef; return(leftValueResult); default: kernel.IssueError(ErrorType.ExpressionSyntaxError, loc.Offset(begin)); return(null); } } Expression left; Expression right; matchTokenResult = MatchToken(minPos, end); op = matchTokenResult.Matched; left = (begin != minPos) ? parse(begin, minPos) : null; //null表示单目运算符 right = parse(matchTokenResult.EndPos, end); Location currentLoc = loc.Offset(begin); if (right == null) { return(null); } switch (op) { case "=": if (!(left is LeftValueExpr)) { kernel.IssueError(ErrorType.NotLeftValue, currentLoc); return(null); } AssignExpr assignExpr = new AssignExpr(); assignExpr.LeftExpr = left as LeftValueExpr; assignExpr.RightExpr = right; assignExpr.DataType = right.DataType; assignExpr.Location = currentLoc; return(assignExpr); case "&&": return(processBinaryLogicExpr( new AndExpr(), left, right, currentLoc)); case "||": return(processBinaryLogicExpr( new OrExpr(), left, right, currentLoc)); case "==": return(processBinaryCmpExpr(new EquExpr(), left, right, currentLoc)); case "!=": return(processBinaryCmpExpr(new NeqExpr(), left, right, currentLoc)); case ">": return(processBinaryCmpExpr(new GreatExpr(), left, right, currentLoc)); case ">=": return(processBinaryCmpExpr(new GreatEquExpr(), left, right, currentLoc)); case "<": return(processBinaryCmpExpr(new LessExpr(), left, right, currentLoc)); case "<=": return(processBinaryCmpExpr(new LessEquExpr(), left, right, currentLoc)); case "+": return(processBinaryAlgoExpr(new AddExpr(), left, right, currentLoc)); case "-": if (left == null) { NegativeExpr negExpr = new NegativeExpr(); if (right.DataType == DataType.Bool || right.DataType == DataType.String) { kernel.IssueError(ErrorType.OprandTypeError, currentLoc); return(null); } else if (right.DataType == DataType.Int) { negExpr.DataType = DataType.Int; } else if (right.DataType == DataType.Float) { negExpr.DataType = DataType.Float; } else { negExpr.DataType = DataType.Unknown; } negExpr.Op = right; negExpr.Location = currentLoc; return(negExpr); } else { return(processBinaryAlgoExpr(new SubExpr(), left, right, currentLoc)); } case "*": return(processBinaryAlgoExpr(new MulExpr(), left, right, currentLoc)); case "/": return(processBinaryAlgoExpr(new DivExpr(), left, right, currentLoc)); case "^": return(processBinaryAlgoExpr(new PowExpr(), left, right, currentLoc)); case "!": if (left != null) { kernel.IssueError(ErrorType.ExpressionSyntaxError, currentLoc); return(null); } else { NotExpr notExpr = new NotExpr(); notExpr.DataType = DataType.Bool; notExpr.Op = right; notExpr.Location = currentLoc; return(notExpr); } } return(null); }
internal RightValue GetValue(VarRef varRef) { return(GetValue(varRef.VarName)); }