CS212 Spring 2002 4/10/2002 Lecture 11: Abstract Syntax Trees ; Part 4 ; Software Engineering issues ------------------------------------------------------------------------------- [0] Announcements: + Part 3 extended due date 4/15, 1:00:00 pm + have you noted Bali changes? things like declarations being INSIDE the {} (see online Announcements for full list) ------------------------------------------------------------------------------- [1] Summary from last time: + compilers/translators + process of translation + parsing and expressions + abstract syntax trees ------------------------------------------------------------------------------- [2] Overview + more on ASTs + OOP and ASTs for Part 4 + software engineering issues ------------------------------------------------------------------------------- [3] A bit more on Abstract Syntax Trees + 2 more examples from L10 ------------------------------------------------------------------------------- [4] Example ASTs for Sam-Code + int leaf + name leaf + expression + assignment statement + block (list) + 1-statement block |=================================| Page 1 |=================================| [4] Example ASTs continued + selection statement + do-while repetition statement + return statement + more? - generally, think node, list, and/or tree - will write along with Part 4 ------------------------------------------------------------------------------- [5] OOP Aspects + store Bali program as tree in the compiler + use ASTs for convenience and elegance // main idea: interface AST { String toString(); String codeGen(Function F); } class BC { // read in functions // output sam-code } class Function implements AST { // stuff for you to write } + Grammar classes - write classes according to hierarchy - think of the grammar as tree abstract class Statement implements AST { } class Declaration extends Statement { } class Selection extends Statement { } // and more + how many trees are there? 2...don't confuse them: - AST for storing code - OOP design to write classes |=================================| Page 2 |=================================| [6] Software Engineering Issues According to DIS (A) Process of Programming high-level: + Problem -> Approach -> Solution + iterate if necessary medium-level: + programming as writing + brainstorm, research, outline, draft, rewrite, polish - brainstorm - research: traditional research, class formation - outline: algorithms - draft - rewrite: iteration - polish: bells and whistles low-level: + stepwise refinement: "baby steps" + stubbing + top-down + bottom-up tricks of the trade - how to stub - commenting as you go/partial debugging - mixing top-down/bottom up - personal reuse database