Production | Semantic Rules |
---|---|
pd → PROC np IS ds BEG ss END ; | ds.offset = 0 |
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 → ID |
f.addr = get(ID.lexeme) f.code = "" |
f → ID 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 |