CSE443 Compilers
- Dr. Carl Alphonce
alphonce@buffalo.edu 343 Davis Hall
http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei
CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis - - PowerPoint PPT Presentation
CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei WW @ 4/5 handling of type checking in: 'assignable
alphonce@buffalo.edu 343 Davis Hall
http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei
Figure 1.6, page 5 of text
1. x = y op z 2. x = op y (treat i2r and r2i as unary ops) 3. x = y
5. if x goto L / ifFalse x goto L 6. if x relop y goto L 7. function calls:
8. x = y[i] and x[i] = y 9. x = &y, x = *y, *x = y
Record field initialization now done with declaration Record field initialization now done with declaration
We now have allow multi- dimensional arrays
Function types must now be named before use Function types must now be named before use
type Node: ( integer datum:=0 ; Node rest:=null )
type indicates size type indicates storage location primitives: in current environment records: on heap arrays: on heap functions: code in static, locals on stack need to determine how to lay out records, arrays, invocation records in memory
# dims size of dimension 1 (integer) (0) (1) (2) (3) (5) 1 5 V A X E S
https:/ / en.wikipedia.org/wiki/VAX
What is the size of a multi- dimensional array of type T? # of dimensions (X): 1 byte sizes of dimensions (Si): X*4 bytes data: (∏i∈X Si) * sizeOf(T)
2 # dims size of first dimension 2 size of second dimension 3 a(0,0) first row a(0,1) a(0,2) a(1,0) second row a(1,1) a(1,2)
w = 4 int w = 4 array(3,int) w = 12 array(2,array(3,int)) w = 24 array(2,array(3,int)) w = 24
character w = 1
w = 6 w = 3 9+array(2,arr(3,character)) w = 9 + 6 * 1 = 15 w = 2 * 3
dblocks (6.3.5 and 6.3.6)
records (in separate symbol table), sequence of declarations at start of sblock
definition —> type identifier ':' dblock { st.put(identifier.lexeme, TYPE, dblock.type, dblock.width } dblock —> '(' { Env.push(st); st = new Env(); Stack.push(offset); offset = 0; } declaration-list ')' { dblock.type=record(st); dblock.width=offset; st=Env.pop(); offset=Stack.pop(); } declaration-list —> declaration ';' declaration-list declaration-list —> declaration declaration —> identifier ':' { id-list.type = identifier; } <— however you store types identifier-list (maybe pointer into st?) identifier-list —> identifier ( sBinOp constant ) ',' { st.put(identifier.lexeme, VAR, identifier-list.type, offset);
identifier-list identifier-list —> identifier ( sBinOp constant ) { st.put(identifier.lexeme, VAR, identifier-list.type, offset);
Just suggestions, not to be taken literally Just suggestions, not to be taken literally