void Decl() { var isNew = false; var type = ScriptVarType.Undefined; ScriptVar v; var isCalling = false; string name = null; var isAssigned = false; if (la.kind == 24) { Get(); isNew = true; } if (NotBrace()) { Expect(1); name = t.val; if (!_isParsing) { var isExists = Vars.IsFunctionExists(name) || Vars.IsHostFunctionExists(name); if (isExists) { SemErr(string.Format("Function '{0}' exists and cant be assigned as variable", name)); } isExists = Vars.IsVarExists(name); if (isNew && isExists) { SemErr(string.Format("Variable '{0}' already declared", name)); } if (isExists) { type = Vars.GetVar(name).Type; } if (!isNew && !isExists) { SemErr(string.Format("Variable '{0}' not declared", name)); } } } else if (StartOf(2)) { if (isNew) { SemErr("Invalid usage of variable declaration"); } Expr(out v); isCalling = true; } else { SynErr(33); } if (la.kind == 25) { if (isCalling) { SemErr("Only variable can be assigned, not expression"); } Get(); Expr(out v); if (!_isParsing) { if (type != ScriptVarType.Undefined && v.Type != type) { SemErr(string.Format("Variable '{0}' type cant be changed", name)); } Vars.RegisterVar(name, v); } else { isAssigned = true; } } Expect(11); if (_isParsing && isNew && !isCalling && !isAssigned) { SemErr(string.Format("Variable '{0}' should be initialized", name)); } }
public int GetID(string varName) { return(Vars.GetVar(varName).Number); }