protected virtual object EvalWithinBlock(ParseTree tree, params object[] paramlist) { List <Object> exprlist = new List <Object>(); String id = (String)this.GetValue(tree, TokenType.IDENTIFIER, 0); int ii = 0; Object currentExpr = this.GetValue(tree, TokenType.Expr, ii); while (currentExpr != null) { //Expr returns a list of variable declerations. We need to add the within block //identifier to each of those, and return that new list. List <Object> withinExprs = (List <Object>)currentExpr; for (int jj = 0; jj < withinExprs.Count; ++jj) { Object thisExpr = withinExprs[jj]; if (thisExpr is sinter.PSE.variableDecleration) { sinter.PSE.variableDecleration thisDecl = (sinter.PSE.variableDecleration)withinExprs[jj++]; thisDecl.name = id + "." + thisDecl.name; } else if (thisExpr is sinter.PSE.variableAssignment) { sinter.PSE.variableAssignment thisAssign = (sinter.PSE.variableAssignment)withinExprs[jj++]; if (thisAssign.gPROMSPath != "**invalid**") //Don't modify the sentinal value { thisAssign.gPROMSPath = id + "." + thisAssign.gPROMSPath; } } } exprlist.AddRange(withinExprs); ii++; currentExpr = this.GetValue(tree, TokenType.Expr, ii); } return(exprlist); }
protected virtual object EvalVariableExpr(ParseTree tree, params object[] paramlist) { List <Object> varList = new List <Object>(); Object maybeVarDef = this.GetValue(tree, TokenType.VariableDef, 0); if (maybeVarDef != null) { //First we have a canonical variableDecl from the first VariableDef, then we clone that for any others. sinter.PSE.variableDecleration varDef = (sinter.PSE.variableDecleration)maybeVarDef; System.Tuple <String, bool> varref = (System.Tuple <String, bool>) this.GetValue(tree, TokenType.VariableRef, 0); if ((bool)varref.Item2 == false) //We can't use an array reference here, just ignore any array ref { varDef.name = (String)varref.Item1; varList.Add(varDef); } int ii = 1; varref = (System.Tuple <String, bool>) this.GetValue(tree, TokenType.VariableRef, ii); while (varref != null) { sinter.PSE.variableDecleration thisVarDef = (sinter.PSE.variableDecleration)varDef.Clone(); if ((bool)varref.Item2 == false) //We can't use an array reference here, just ignore any array ref { thisVarDef.name = (String)varref.Item1; varList.Add(thisVarDef); } ii++; varref = (System.Tuple <String, bool>) this.GetValue(tree, TokenType.VariableRef, ii); } } else { sinter.PSE.variableAssignment varAssign = (sinter.PSE.variableAssignment) this.GetValue(tree, TokenType.Assignment, 0); System.Tuple <String, bool> varRef = (System.Tuple <String, bool>) this.GetValue(tree, TokenType.VariableRef, 0); varAssign.gPROMSPath = (String)varRef.Item1; varList.Add(varAssign); // if((bool)varRef.Item2 == false) { //We can't use an array reference here, just ignore any array ref // } int ii = 1; varRef = (System.Tuple <String, bool>) this.GetValue(tree, TokenType.VariableRef, ii); while (varRef != null) { sinter.PSE.variableAssignment thisVarAssign = (sinter.PSE.variableAssignment)varAssign.Clone(); thisVarAssign.gPROMSPath = (String)varRef.Item1; varList.Add(thisVarAssign); ii++; varRef = (System.Tuple <String, bool>) this.GetValue(tree, TokenType.VariableRef, ii); } } return(varList); }
protected virtual object EvalExpr(ParseTree tree, params object[] paramlist) { List <Object> varExpr = (List <Object>) this.GetValue(tree, TokenType.VariableExpr, 0); if (varExpr != null) { List <Object> retList = new List <Object>(); foreach (Object expr in varExpr) { //If it's a variableAssignement, we check to make sure it's not an array reference, if it's a decleration, it's good just return it. if (expr is sinter.PSE.variableAssignment) { sinter.PSE.variableAssignment varAssign = (sinter.PSE.variableAssignment)expr; if (!varAssign.isVec) //VariableExpr here is not a ForBlock, so we just ignore any array references. { retList.Add(expr); } } else { retList.Add(expr); } } //If VariableDef returns a list of variable declerations //so just return that list. return(retList); } Object forBlock = this.GetValue(tree, TokenType.ForBlock, 0); if (forBlock != null) { return(forBlock); } else { //Within Block also returns a list a varaible declerations, //so just return that list. return(this.GetValue(tree, TokenType.WithinBlock, 0)); } }
protected virtual object EvalAssignment(ParseTree tree, params object[] paramlist) { String value; String number = (String)this.GetValue(tree, TokenType.NUMBER, 0); String str = (String)this.GetValue(tree, TokenType.STRING, 0); bool isVec = false; if (number != null) { value = number; } else if (str != null) { value = str; //Maybe we need a type afterall? } else { value = (String)this.GetValue(tree, TokenType.IDENTIFIER, 0); if (this.GetValue(tree, TokenType.LPAREN, 0) != null) { String insideParensID = (String)this.GetValue(tree, TokenType.IDENTIFIER, 1); if (insideParensID != null) { value += "(" + insideParensID + ")"; isVec = true; } else { value += "()"; } } } //OK, I don't know the path yet, that's in the one up from here, value is determined, and this should never be an array reference //(by my arbitrary assumption that array references should only happen in for loops.) sinter.PSE.variableAssignment varAssign = new sinter.PSE.variableAssignment("", value, isVec); return(varAssign); }
protected virtual object EvalForBlock(ParseTree tree, params object[] paramlist) { List <Object> exprlist = new List <Object>(); int ii = 0; List <Object> currentVarExpr = (List <Object>) this.GetValue(tree, TokenType.VariableExpr, ii); while (currentVarExpr != null) { foreach (Object thisObj in currentVarExpr) { if (thisObj is sinter.PSE.variableAssignment) //Declerations shouldn't even exist, we certainly can't do anything with them { sinter.PSE.variableAssignment thisAssign = (sinter.PSE.variableAssignment)thisObj; if (thisAssign.isVec && thisAssign.gPROMSPath != "**invalid**") //Has to be a vector with an understandable path and id { exprlist.Add(thisAssign); } } } ++ii; currentVarExpr = (List <Object>) this.GetValue(tree, TokenType.VariableExpr, ii); } return(exprlist); }