csc402-ln008

csc402-ln008 - Tree Walking As we observed in the past two...

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

View Full Document Right Arrow Icon
Tree Walking As we observed in the past two examples, all except for the simplest of language applications build ASTs as their IRs These ASTs need to be processed Tree Walking Read Chapter 5 AST Input Output build write rewrite Tree walking
Background image of page 1

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

View Full DocumentRight Arrow Icon
Tree Walking Tree walking is usually done in “depth first” manner operators and operands can be processed in different orders: Pre-order: root node first then children, e.g. (+ (* 3 2) 4) In-order: nodes are processed in lexical order , e.g. (3 * 2) + 4 Post-order: children nodes are processed first and then the root node, e.g. ((3 2 *) 4 +) + * 4 2 3 root
Background image of page 2
Tree Walking We have seen tree walking already in the two previous applications Bytecode interpreter Pretty printer with a twist
Background image of page 3

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

View Full DocumentRight Arrow Icon
Bytecode Instruction IR // abstract base class for our bytecode instruction set public abstract class Instr { private Instr nextInstr = null; public Instr() { nextInstr = null; } public Instr(Instr i) { nextInstr = i; } public void putNext(Instr i) {
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/03/2011 for the course CSC 402 taught by Professor Staff during the Fall '09 term at Rhode Island.

Page1 / 9

csc402-ln008 - Tree Walking As we observed in the past two...

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

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