csc402-ln007

csc402-ln007 - Abstract Syntax Trees Our Exp1bytecode...

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

View Full Document Right Arrow Icon
Abstract Syntax Trees Our Exp1bytecode language was so straightforward that the best IR was an abstract representation of the instructions In more complex languages, especially higher level languages it usually not possible to design such a simple IR Instead we use Abstract Syntax Trees (ASTs)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Abstract Syntax Trees One way to think about ASTs is as parse trees with all the derivation information deleted + * 4 2 3 Parse Tree AST root
Background image of page 2
Abstract Syntax Trees Because every valid program has a parse tree, it is always possible to construct an AST for every input program. In this way ASTs are the IR of choice because it doesn’t matter how complex the input language, there will always be an AST representation. Besides being derived from the parse tree, AST design typically follows three rules of thumb: Dense : no unnecessary nodes Convenient : easy to understand, easy to process Meaningful : emphasize the operators, operands, and the relationship between them; emphasize the computations
Background image of page 3

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

View Full DocumentRight Arrow Icon
A Pretty Printer with a Twist Our next language is a simple scripting language Our pretty printer will do the following things: It will read the script file and construct an AST It will compute whether a particular variable is used in the script It will output a pretty printed version of the input script but will flag and comment out assignment statements to variables which are not used in the script
Background image of page 4
The Scripting Language prog : stmt+ ;
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.

Page1 / 12

csc402-ln007 - Abstract Syntax Trees Our Exp1bytecode...

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