Ch5b - 1 ! Syntax-Directed Translation" Part II! Chapter 5!...

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

View Full Document Right Arrow Icon
1 Syntax-Directed Translation Part II Chapter 5 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2011
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Translation Schemes using Marker Nonterminals S ! if E M then S { backpatch( M .loc, pc- M .loc) } M ! " { M .loc := pc; emit( ifeq , 0) } S ! if E {push(pc); emit( ifeq , 0) } then S { backpatch(top(), pc-top()); pop() } Need a stack to keep track of gotos to backpatch! (to handle nested if-then) Synthesized attribute (automatically stacked in shift-reduce parser!) Insert marker nonterminal
Background image of page 2
3 Translation Schemes using Marker Nonterminals in Yacc S : IF E M THEN S { backpatch($3, pc-$3); } ; M : /* empty */ { $$ = pc; emit3(ifeq, 0); } ;
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Replacing Inherited Attributes with Synthesized Lists D ! T L { for all id # L .list : addtype ( id .entry, T .type) } T ! int { T .type := ‘integer’ } T ! real { T .type := ‘real’ } L ! L 1 , id { L .list := L 1 .list + [ id ] } L ! id { L .list := [ id ] } D T .type = ‘real’ L .list = [ id 1 , id 2 , id 3 ] L .list = [ id 1 , id 2 ] L .list = [ id 1 ] id 2 .entry id 1 .entry id 3 .entry real , ,
Background image of page 4
5 Replacing Inherited Attributes
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/01/2012 for the course COP 5621 taught by Professor Vanengelen during the Spring '11 term at FSU.

Page1 / 15

Ch5b - 1 ! Syntax-Directed Translation" Part II! Chapter 5!...

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

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