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 EvalArrayDef(ParseTree tree, params object[] paramlist) { String type = ""; String typename = (String)this.GetValue(tree, TokenType.TypeName, 0); if (typename != null) { type = typename; } else { type = (String)this.GetValue(tree, TokenType.SelectorDef, 0); } //We can only handle 1D vectors with pure numbers, so otherwise we pass ArrayLen = 0 int arrayLen = 0; if (this.GetValue(tree, TokenType.AddExpr, 1) == null) { Object maybe_arrayLen = this.GetValue(tree, TokenType.AddExpr, 0); if (!(maybe_arrayLen is String)) //If AddExpr returns a string, we can't use it, otherwise it should return some kind of number { arrayLen = Convert.ToInt32(this.GetValue(tree, TokenType.AddExpr, 0)); } } sinter.PSE.variableDecleration varDef = new sinter.PSE.variableDecleration("unknown", type, arrayLen); return(varDef); }
protected virtual object EvalVariableDef(ParseTree tree, params object[] paramlist) { Object arrayDef = this.GetValue(tree, TokenType.ArrayDef, 0); sinter.PSE.variableDecleration varDef = null; if (arrayDef != null) { varDef = (sinter.PSE.variableDecleration)arrayDef; } else { varDef = (sinter.PSE.variableDecleration) this.GetValue(tree, TokenType.ScalarDef, 0); } if (this.GetValue(tree, TokenType.DEFAULT, 0) != null) { Object addexpr = this.GetValue(tree, TokenType.AddExpr, 0); if (varDef.type == sinter_Variable.sinter_IOType.si_INTEGER || varDef.type == sinter_Variable.sinter_IOType.si_INTEGER_VEC) { if (addexpr is String) { varDef.dfault = 0; } else { varDef.dfault = Convert.ToInt32(this.GetValue(tree, TokenType.AddExpr, 0)); } } else if (varDef.type == sinter_Variable.sinter_IOType.si_DOUBLE || varDef.type == sinter_Variable.sinter_IOType.si_DOUBLE_VEC) { if (addexpr is String) { varDef.dfault = 0; } else { varDef.dfault = (double)this.GetValue(tree, TokenType.AddExpr, 0); //AddExpr should always return a string or a double } } else if (varDef.type == sinter_Variable.sinter_IOType.si_STRING || varDef.type == sinter_Variable.sinter_IOType.si_STRING_VEC) { if (addexpr is String) { varDef.dfault = (String)this.GetValue(tree, TokenType.AddExpr, 0); //AddExpr should always return a string or a double } else { varDef.dfault = ""; } } } return(varDef); //varDef = (sinter.PSE.variableDecleration) this.GetValue(tree, TokenType.ArrayDef, 0); }
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 EvalScalarDef(ParseTree tree, params object[] paramlist) { String type = ""; String typename = (String)this.GetValue(tree, TokenType.TypeName, 0); if (typename != null) { type = typename; } else { type = (String)this.GetValue(tree, TokenType.SelectorDef, 0); } sinter.PSE.variableDecleration varDef = new sinter.PSE.variableDecleration("unknown", type, -1); return(varDef); }