29.04.2015 Views

Syntax Directed Translation

Syntax Directed Translation

Syntax Directed Translation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Construction of <strong>Syntax</strong> Trees (ASU Ch 5.2 Ex 5.7)<br />

• Intermediate representation<br />

• de-couples translation from<br />

parsing<br />

• condensed form of parse tree<br />

• examples<br />

3<br />

*<br />

3*5+4 if B then S 1 else S 2<br />

+ if-then-else<br />

5<br />

4<br />

B S 1 S 2<br />

• <strong>Syntax</strong> trees for expressions<br />

(cf translation to post-fix form)<br />

• operations<br />

– mknode(op left, right)<br />

– mkleaf(id, entry)<br />

– mkleaf(num, entry)<br />

• e.g. a-4+c<br />

p1 := mkleaf(id, entry-a)<br />

p2 := mkleaf(num, 4)<br />

p3 := mknode(‘-’, p1, p2)<br />

p4 := mkleaf(id, entry-c)<br />

p5 := mknode(‘+’, p3, p4)<br />

see ASU Fig 5.8 for syntax tree<br />

10<br />

14/10/2014 DFR - CC - SDT

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!