public void Assign(String var, SGLValue value, Boolean newVar, String type) { if (Resolve(var) != null) { if (newVar) throw new Exception("There is already such a variable"); // There is already such a variable, re-assign it this.ReAssign(var, value); } else { if (!newVar) throw new Exception("The variable " + var + " doesn't exists."); if (IsGlobalScope()) Console.WriteLine("This is the global scope year!"); // A newly declared variable varValues.Add(var, value); varTypes.Add(var, type); } }
public SGLValue Evaluate() { // Resolve value SGLValue value = scope.Resolve(identifier); if (value == null) { throw new SGLCompilerException(GetLine(), "unknown variable", "'" + value + "' cannot be resolved to a variable"); } // integer if (value.IsInteger()) { SGLValue newValue = new SGLValue(value.AsInteger() + 1); scope.Assign(identifier, newValue, false, ""); if (returnValue) { return newValue; } else { return SGLValue.VOID; } } // float if (value.IsFloat()) { SGLValue newValue = new SGLValue(value.AsFloat() + 1); scope.Assign(identifier, newValue, false, ""); if (returnValue) { return newValue; } else { return SGLValue.VOID; } } throw new SGLCompilerException(GetLine(), "type mismatch", "cannot convert from " + value.GetVarType() + " to int"); }
private void CheckRange(String ident, SGLValue value, int start, int end) { if (value.AsFloat() < start || value.AsFloat() > end) { throw new SGLCompilerException(GetLine(), "unexpected value", "the value for '" + ident + "' should be between " + start + " and " + end); } }
private void CheckRange(String ident, SGLValue value, int start) { if (value.AsFloat() < start) { throw new SGLCompilerException(GetLine(), "unexpected value", "the value for '" + ident + "' should not be lower than " + start); } }
public RootNode(SGLValue a, SGLValue b) { this.a = a; this.b = b; }
public PrintlnNode(StringBuilder sb, SGLValue expression) { this.sb = sb; this.expression = expression; }
private void ReAssign(String identifier, SGLValue value) { if (varValues.ContainsKey(identifier)) { // The variable is declared in this scope String type = varTypes[identifier]; if (type.Equals("int")) { if (value.IsInteger()) { varValues[identifier] = value; } else if (value.IsFloat()) { // Convert float expression to int varValues[identifier] = new SGLValue((int)Math.Floor(value.AsFloat())); } else { throw new Exception("Can't assign " + value.ToString() + " to an integer variable"); } } else if (type.Equals("float")) { if (value.IsNumber()) { varValues[identifier] = value; } else { throw new Exception("Can't assign " + value.ToString() + " to a float variable"); } } else if (type.Equals("boolean")) { if (value.IsBoolean()) { varValues[identifier] = value; } else { throw new Exception("Can't assign " + value.ToString() + " to a boolean variable"); } } else if (type.Equals("string")) { if (value.IsString()) { varValues[identifier] = value; } else { throw new Exception("Can't assign " + value.ToString() + " to a string variable"); } } else if (type.Equals("Object")) { if (value.IsObject()) { // Add this object to the spriteObjects before the reassignment, so it don't get lost spriteObjects.Add(varValues[identifier].AsObject()); varValues[identifier] = value; } else { throw new Exception("Can't assign " + value.ToString() + " to a string variable"); } } } else if (parent != null) { // The variable was not declared in this scope, so let // the parent scope re-assign it parent.ReAssign(identifier, value); } }
public AtomNode(Object v, int line) { value = (v == null) ? SGLValue.NULL : new SGLValue(v); this.line = line; }
public AtomNode(Object v) { value = (v == null) ? SGLValue.NULL : new SGLValue(v); }
public PowNode(SGLValue a, SGLValue b) { this.a = a; this.b = b; }
public RandomIntegerNode(SGLValue start, SGLValue end) { this.start = start; this.end = end; }