// create a new object node in the current scope public Obj NewObj(string name, int kind, int type, int size) { Obj p, last, obj = new Obj(); obj.name = name; obj.kind = kind; obj.type = type; obj.level = curLevel; p = topScope.locals; last = null; obj.size = size; while (p != null) { if (p.name == name) { parser.SemErr("name declared twice"); } last = p; p = p.next; } if (last == null) { topScope.locals = obj; } else { last.next = obj; } if (kind == var) { //Console.WriteLine(topScope.nextAdr); obj.adr = topScope.nextAdr++; //Console.WriteLine("Address of " + obj.name + " is " + obj.adr); topScope.nextAdr += size - 1; //Reserve space on the stack it an array is being created. } //Console.WriteLine("Object stored at: " +name + " : "+ obj.adr); return(obj); }
using System;