/// <summary> /// /// </summary> /// <param name="code"></param> /// <returns></returns> AttrAssignment CreateAttrAssignment(StringBuilder code) { int ix = code.ToString().IndexOf("="); if (ix == -1) { throw new Exception("Invalid attr assignment:" + code); } string left = code.ToString().Substring(0, ix).Trim(); string right = code.ToString().Substring(ix + 1).Trim(); string[] toks = left.Split('.'); string obj = toks[0].Trim(); string attr = toks[1].Trim(); IIntResult lhs = ToIIntResult(obj); IIntResult rhs = BuildExprTree(new StringBuilder(right)); //look up the lhs by name and set its value // int objid = game.GetObjectId(obj); // if (objid == -1) // throw new Exception("game doesn't have an object named " + obj + " (in GetObjAttr)"); return(new AttrAssignment() { objName = obj, attrName = attr, Left = lhs, Right = rhs }); }
PropAssignment CreatePropAssignment(StringBuilder code) { int ix = code.ToString().IndexOf("="); if (ix == -1) { throw new Exception("Invalid prop assignment:" + code); } string left = code.ToString().Substring(0, ix).Trim(); string right = code.ToString().Substring(ix + 1).Trim(); string[] toks = left.Split('.'); string obj = toks[0].Trim(); string attr = toks[1].Trim(); if (game.GetObjectId(obj) == -1 && !game.IsVariable(obj)) { throw new Exception("game has no object or variable named " + obj); } IIntResult lhs = ToIIntResult(obj); IIntResult rhs = BuildExprTree(new StringBuilder(right)); return(new PropAssignment() { objName = obj, propName = attr, Left = lhs, Right = rhs }); }
public PropAssignment(string name, string attr, IIntResult lhs, IIntResult rhs) { objName = name; propName = attr; Left = lhs; Right = rhs; }
public VarAssignment CreateVarAssignment(StringBuilder code) { string s = code.ToString().Trim(); string name = GetOperand(code); if (!game.IsVariable(name)) { throw new Exception(s + " is not a valid variable"); } s = code.ToString().Trim(); if (s[0] != '=') { throw new Exception("expected = near " + s); } s = s.Substring(1).Trim(); // if (!Char.IsLetter(s[0])) // throw new Exception("unexpected symbol near " + s); IIntResult rhs = BuildExprTree(new StringBuilder(s)); VarAssignment v = new VarAssignment() { VarName = name, Right = rhs }; return(v); }
public AttrAssignment(string obj, string attr, IIntResult lhs, IIntResult rhs) { objName = obj; attrName = attr; Left = lhs; Right = rhs; }
/// <summary> /// Private method for building an integer /// expression tree /// </summary> /// <param name="toks"></param> /// <param name="minPrec"></param> /// <returns></returns> IIntResult PrecedenceClimb(List <string> toks, int minPrec) { IIntResult atom_lhs = FindAtom(toks); BinaryOperator lhs = null; while (toks.Count > 0 && IsBinaryOperator(toks.First()) && (ToBinaryOp(toks.First()).Precedence >= minPrec)) { string optxt = toks.First(); toks.Pop(); //remove operator BinaryOperator op = ToBinaryOp(optxt); int prec = op.Precedence; int next_min_prec = prec + 1; //Console.WriteLine("operator=" + optxt); IIntResult rhs = PrecedenceClimb(toks, next_min_prec); op.Right = rhs; if (lhs == null) { op.Left = atom_lhs; } else { op.Left = lhs; } lhs = op; } if (lhs == null) { return(atom_lhs); } return(lhs); }
public Rand(IIntResult inner) { //get the inner code upper = inner; }
public PrintObjectName(IIntResult inner) { objectId = inner; }
public AttributeRVal(string name, IIntResult lhs, string attr) { this.Left = lhs; this.ObjName = name; this.AttrName = attr; }
public PropertyRVal(string name, IIntResult lhs, string property) { Left = lhs; this.ObjName = name; this.PropName = property; }