Public void visitwhilenode p cse341 programming cse341

Info iconThis preview shows page 1. Sign up to view the full content.

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: Fall 2011 staVc type of w.cond (ExpNd). •  Typically an error (usually no “visit(ExpNd e)”). Winter 2013 dynamic type of w.cond (e.g., LessThan). •  Accept staVcally selects correct visit method. UW CSE 401 (Michael Ringenburg) 4 How do we traverse AST? public void visit(WhileNode p) {
 CSE341: Programming CSE341: Programming Languages Languages p.expr.accept(this);! p.stmt.accept(this);! Lecture …! Lecture 1 1 }!ourse Mechanics Mechanics Course C ML Variable Bindings M o Variable Bindings •  Visitors L Pen control the traversal –  The visitor knows what kDan of traversal it needs – may ind Grossman Dan Grossman be different for different operaVons/nodes. Fall 2011 Fall opVmizaVon eliminates code that will –  E.g., imagine an 2011 never execute (this is called “Dead Code EliminaVon”). •  No need to traverse porVons of the tree that you’ve proved won’t execute. –  Or, imagine a pass that records all variable declaraVons •  No need traverse parts of the AST where declaraVons can’t occur. Winter 2013 UW CSE 401 (Michael Ringenburg) 5 What Do Visitors Do? CSE341: Programming •  A CSE341: Programming Languages Languages visitor funcVon has a reference to the node it is visiVng (the parameter)...
View Full Document

Ask a homework question - tutors are online