static void Designator(out DesType des) { string name; int indexType; Ident(out name); Entry entry = Table.Find(name); if (!entry.declared) { SemError("undeclared identifier"); } des = new DesType(entry); if (entry.kind == Kinds.Var) { CodeGen.LoadAddress(entry); } if (la.kind == lbrack_Sym) { Get(); if (IsArray(des.type)) { des.type--; } else { SemError("unexpected subscript"); } if (des.entry.kind != Kinds.Var) { SemError("unexpected subscript"); } CodeGen.Dereference(); Expression(out indexType); if (!IsArith(indexType)) { SemError("invalid subscript type"); } CodeGen.Index(); Expect(rbrack_Sym); } }
static void OneVar(StackFrame frame, int type) { int expType; Entry var = new Entry(); Ident(out var.name); var.kind = Kinds.Var; var.type = type; var.offset = frame.size; frame.size++; if (la.kind == equal_Sym) { AssignOp(); CodeGen.LoadAddress(var); Expression(out expType); if (!Assignable(var.type, expType)) { SemError("incompatible types in assignment"); } CodeGen.Assign(var.type); } Table.Insert(var); }