Declarations & Assignment Statements
(with One-Dimensional Arrays)

Declarations and Assignment Statements (with 1D Arrays)
ProductionSemantic Rules
pd → PROC np IS ds BEG ss END ;
ds.offset = 0
pd.code = ss.code
np → di ( ps ) | di not used yet
ds → d ds1 d.offset = ds.offset
ds1.offset = d.newoffset
ds.totalSize = ds1.totalSize
ds → ε ds.totalSize = ds.offset
d → di : ty ; addType(di.entry, ty.type)
addBaseType(di.entry, ty.basetype)
addSize(di.entry, ty.size)
addOffset(di.entry, d.offset)
d.newoffset = d.offset + ty.size
di → ID di.entry = ID.entry
ty → ARRAY [ NUM ] OF ty1 ty.type = array(NUM.value, ty1.type)
ty.basetype = ty1.basetype
ty.size = NUM.value * ty1.size
ty → INT ty.type = integer
ty.basetype = integer
ty.size = 4
ty → REAL ty.type = real
ty.basetype = real
ty.size = 8
e → t e.addr = t.addr
e.code = t.code
e → e1 ADDOP t e.addr = new Temp()
e.code = e1.code || t.code ||
gen(e.addr = e1.addr ADDOP.lexeme t.addr)
t → f t.addr = f.addr
t.code = f.code
t → t1 MULOP f t.addr = new Temp()
t.code = t1.code || f.code ||
gen(t.addr = t1.addr MULOP.lexeme f.addr)
f → ( e ) f.addr = e.addr
f.code = e.code
f → NUM f.addr = get(NUM.lexeme)
f.code = ""
f → IDENTIFIER f.addr = get(IDENTIFIER.lexeme)
f.code = ""
f → IDENTIFIER i f.t1 = new Temp()
f.addr = new Temp
f.code = i.code ||
      gen(f.t1 = i.addr * getBaseWidth(ID.entry)) ||
      gen(f.addr = get(ID.lexeme)[f.t1])
i → [ e ] i.addr = e.addr
i.code = e.code
ss → s ss1 ss.code = s.code || ss1.code
ss → ε ss.code = ""
s → ids s.code = ids.code
ids → IDENTIFIER re
re.id = ID.entry
ids.code = re.code
re → ra
ra.id = re.id
re.code = ra.code
ra → := e ; ra.code = e.code ||
        gen(ra.id.lexeme=e.addr)
ra → i := e ; ra.t1 = newTemp()
ra.code = i.code || e.code ||
        gen(ra.t1 = i.addr * getBaseWidth(ra.id)||
        gen(ra.id.lexeme[ra.t1]=e.addr)