{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

03-04sddToSdt - 1 CSE 450 Compilers K Stirewalt Semantic...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 CSE 450: Compilers K. Stirewalt Semantic analysis Part 4: Syntax trees and type checking (continued) Topics: – transforming an SDD into an SDT in detail – Subtleties involved in using embedded actions and inherited attributes in yacc – type conversions CSE 450: Compilers K. Stirewalt SDD for the language prog → func_call func_call → ID expr_list expr_list → ‘(‘ expr_seq ‘)’ expr_seq → expr expr_seq → expr_seq 1 ‘,’ expr expr → LITERAL expr → expr 1 ‘+’ expr 2 expr → func_call prog_call.s = func_call.s func_call.s = new FuncCall(ID.str, expr_list.s) expr_list.s = expr_seq.s expr_seq.i = new ExprList expr_seq.s = expr_seq.i ++ expr.s expr_seq.s = expr_seq 1 .s ++ expr.s expr_seq 1 .i = expr_seq.i expr.s = new Literal(LITERAL.num) expr.s = new AddOp(expr 1 .s, expr 2 .s) expr.s = func_call.s CSE 450: Compilers K. Stirewalt From an SDD to an SDT The rules for turning an L-attributed SDD into an SDT are as follows: 1. Embed the action that computes the inherited attributes for a non-terminal A before that occurrence of A in the body of the production. If several inherited attributes for A depend on one another in acyclic fashion, order them appropriately. 2. Place the actions that compute a synthesized attribute for the head of a production at the end of the body of that production CSE 450: Compilers K. Stirewalt Rules with no inherited attrs.. prog → func_call func_call → ID expr_list expr_list → ‘(‘ expr_seq ‘)’ expr_seq → expr expr_seq → expr_seq 1 ‘,’ expr expr → LITERAL expr → expr 1 ‘+’ expr 2 expr → func_call prog_call.s = func_call.s func_call.s = new FuncCall(ID.str, expr_list.s) expr_list.s = expr_seq.s expr_seq.i = new ExprList expr_seq.s = expr_seq.i ++ expr.s expr_seq.s = expr_seq 1 .s ++ expr.s expr_seq 1 .i = expr_seq.i expr.s = new Literal(LITERAL.num) expr.s = new AddOp(expr 1 .s, expr 2 .s) expr.s = func_call.s CSE 450: Compilers K. Stirewalt Applied transformation 2 to get… prog: func_call func_call: ID expr_list expr_list → ‘(‘ expr_seq ‘)’ expr_seq → expr expr_seq → expr_seq 1 ‘,’ expr expr : LITERAL | expr ‘+’ expr | func_call { $1->print(cout); … } ; { $$=new FuncCall(*$1, *$2);} ; expr_list.s = expr_seq.s expr_seq.i = new ExprList expr_seq.s = expr_seq.i ++ expr.s expr_seq.s = expr_seq 1 .s ++ expr.s expr_seq 1 .i = expr_seq.i { $$=new Literal($1); } { $$=new AddOp($1, $3); } { $$=$1; } ; CSE 450: Compilers K. Stirewalt Applied transformation 2 to get… prog: func_call func_call: ID expr_list expr_list → ‘(‘ expr_seq ‘)’ expr_seq → expr expr_seq → expr_seq 1 ‘,’ expr expr : LITERAL | expr ‘+’ expr | func_call { $1->print(cout); … } ; { $$=new FuncCall(*$1, *$2);} ; expr_list.s = expr_seq.s expr_seq.i = new ExprList expr_seq.s = expr_seq.i ++ expr.s expr_seq.s = expr_seq 1 .s ++ expr.s expr_seq 1 .i = expr_seq.i { $$=new Literal($1); } { $$=new AddOp($1, $3); } { $$=$1; } ; 2 CSE 450: Compilers K. StirewaltK....
View Full Document

{[ snackBarMessage ]}

Page1 / 6

03-04sddToSdt - 1 CSE 450 Compilers K Stirewalt Semantic...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online