THINGS THAT WORK { int a a=0 while (8 != a) { print(a) a=1+a } } { char x int y y = 5 print(2 + y) x = "on and " while true print(x) } { int a a = 0 while true { while (4 != a) { print(a) a=1+a } a = 0 print("here forever") } } { int x x = 4 bool a a = true bool b b = ( 5 != x ) print ((false == (true == b))) } { int x x = 5 if (7 == 1 + x) print("hey") if (7 == 2 + x) { print("ho") if true print(x) } } THINGS THAT DON'T WORK [Everything that didn't work in previous homeworks still does not work. When an error is caught during semantic analysis, code generation and the abstract syntax tree generation are not run. If code gets through the lexer and semantic analysis, there will be no errors.] { bool x x = true bool y y = (x != ) } if "badstring" print(1) { char a a = "dog" bool x x = (true == a) } SAMPLE COMPILED OUTPUT Compilation Started Didn't find $ at EOF, but that's okay, appending one anyway. Lex returned [{,int,a,a,=,0,while,true,{,while,(,4,!,=,a,),{,print,(,a,),a,=,1,+,a,},a,=,0,print,(,",h,e,r,e, ,f,o,r,e,v,e,r,",),},}] Parsing [{,int,a,a,=,0,while,true,{,while,(,4,!,=,a,),{,print,(,a,),a,=,1,+,a,},a,=,0,print,(,",h,e,r,e, ,f,o,r,e,v,e,r,",),},}] Current token:{ Parsing Statement, expecting print, a-z, int, char, bool, while, if, or { got { ! Current token:int Parsing StatementList, expecting statement or end of statement list Parsing Statement, expecting print, a-z, int, char, bool, while, if, or { got int ! Current token:a Parsing VarDecl, expecting an id Found id a, checking if already declared... Not already declared, now declaring a as type int Current token:a Parsing StatementList, expecting statement or end of statement list Parsing Statement, expecting print, a-z, int, char, bool, while, if, or { got a ! checking that id a has been declared... It has! Current token:= Expecting = Got it Current token:0 Parse Expr, expecting a number, character, boolean value (true or false), ( (indicating BoolExpr), or " (indicating CharList) Got the number 0, parsing IntExpr Current token:while Expecting an op or end of IntExpr operator was not found: this is the end of this IntExpr Type checking... type 1 is int and type 2 is int Success! Parsing StatementList, expecting statement or end of statement list Parsing Statement, expecting print, a-z, int, char, bool, while, if, or { Found 'while', entering whileloop statement... Current token:true Parse Expr, expecting a number, character, boolean value (true or false), ( (indicating BoolExpr), or " (indicating CharList) Got true, this is beginning of BoolExpr Non compound BoolExpr: just true End of this BoolExpr... Current token:{ condition is true, evaluating body of loop once for syntactical errors Parsing Statement, expecting print, a-z, int, char, bool, while, if, or { got { ! Current token:while Parsing StatementList, expecting statement or end of statement list Parsing Statement, expecting print, a-z, int, char, bool, while, if, or { Found 'while', entering whileloop statement... Current token:( Parse Expr, expecting a number, character, boolean value (true or false), ( (indicating BoolExpr), or " (indicating CharList) Got (, this is beginning of BoolExpr Current token:4 Parse Expr, expecting a number, character, boolean value (true or false), ( (indicating BoolExpr), or " (indicating CharList) Got the number 4, parsing IntExpr Current token:! Expecting an op or end of IntExpr operator was not found: this is the end of this IntExpr Expecting == or != Current token:= Got != Current token:a Parse Expr, expecting a number, character, boolean value (true or false), ( (indicating BoolExpr), or " (indicating CharList) got id a, checking Current token:) checking that id a has been declared... not found in this symbol table, testing parent symbol table It has! Found ), this is the end of this compound boolean expression. Current token:{ condition is true, evaluating body of loop once for syntactical errors Parsing Statement, expecting print, a-z, int, char, bool, while, if, or { got { ! Current token:print Parsing StatementList, expecting statement or end of statement list Parsing Statement, expecting print, a-z, int, char, bool, while, if, or { got print ! Current token:( Expecting ( Got it Current token:a Parse Expr, expecting a number, character, boolean value (true or false), ( (indicating BoolExpr), or " (indicating CharList) got id a, checking Current token:) checking that id a has been declared... not found in this symbol table, testing parent symbol table not found in this symbol table, testing parent symbol table It has! Expecting ) Got it Current token:a Parsing StatementList, expecting statement or end of statement list Parsing Statement, expecting print, a-z, int, char, bool, while, if, or { got a ! checking that id a has been declared... not found in this symbol table, testing parent symbol table not found in this symbol table, testing parent symbol table It has! Current token:= Expecting = Got it Current token:1 Parse Expr, expecting a number, character, boolean value (true or false), ( (indicating BoolExpr), or " (indicating CharList) Got the number 1, parsing IntExpr Current token:+ Expecting an op or end of IntExpr Got the op: + Current token:a the op is + Parse Expr, expecting a number, character, boolean value (true or false), ( (indicating BoolExpr), or " (indicating CharList) got id a, checking Current token:} checking that id a has been declared... not found in this symbol table, testing parent symbol table not found in this symbol table, testing parent symbol table It has! Type checking... type 1 is int and type 2 is int Success! End of this IntExpr... Type checking... type 1 is int and type 2 is int Success! Parsing StatementList, expecting statement or end of statement list Found end of StatementList checking to see if any variables in this scope are unused... Expecting } Got it Current token:a Parsing StatementList, expecting statement or end of statement list Parsing Statement, expecting print, a-z, int, char, bool, while, if, or { got a ! checking that id a has been declared... not found in this symbol table, testing parent symbol table It has! Current token:= Expecting = Got it Current token:0 Parse Expr, expecting a number, character, boolean value (true or false), ( (indicating BoolExpr), or " (indicating CharList) Got the number 0, parsing IntExpr Current token:print Expecting an op or end of IntExpr operator was not found: this is the end of this IntExpr Type checking... type 1 is int and type 2 is int Success! Parsing StatementList, expecting statement or end of statement list Parsing Statement, expecting print, a-z, int, char, bool, while, if, or { got print ! Current token:( Expecting ( Got it Current token:" Parse Expr, expecting a number, character, boolean value (true or false), ( (indicating BoolExpr), or " (indicating CharList) Got " Got "! Parsing CharExpr Current token:h Got the character h, parsing CharList, expecting Char, Space, or end of charList Current token:e Got the character e, parsing CharList, expecting Char, Space, or end of charList Current token:r Got the character r, parsing CharList, expecting Char, Space, or end of charList Current token:e Got the character e, parsing CharList, expecting Char, Space, or end of charList Current token: Got the character , parsing CharList, expecting Char, Space, or end of charList Current token:f Got the character f, parsing CharList, expecting Char, Space, or end of charList Current token:o Got the character o, parsing CharList, expecting Char, Space, or end of charList Current token:r Got the character r, parsing CharList, expecting Char, Space, or end of charList Current token:e Got the character e, parsing CharList, expecting Char, Space, or end of charList Current token:v Got the character v, parsing CharList, expecting Char, Space, or end of charList Current token:e Got the character e, parsing CharList, expecting Char, Space, or end of charList Current token:r Got the character r, parsing CharList, expecting Char, Space, or end of charList Current token:" Got the character ", parsing CharList, expecting Char, Space, or end of charList Found end of CharList Expecting " Got it Current token:) End of this CharExpr... Expecting ) Got it Current token:} Parsing StatementList, expecting statement or end of statement list Found end of StatementList checking to see if any variables in this scope are unused... Expecting } Got it Current token:} Parsing StatementList, expecting statement or end of statement list Found end of StatementList checking to see if any variables in this scope are unused... Expecting } Got it checking to see if any variables in this scope are unused... EOF reached! Errors: Warnings: Parsing found 0 error(s) and 0 warning(s). Abstract syntax tree: program ~statement list ~~declare ~~~a ~~assign ~~~a ~~~0 ~~while ~~~true ~~~statement list ~~~~while ~~~~~!= ~~~~~~4 ~~~~~~a ~~~~~statement list ~~~~~~print ~~~~~~~a ~~~~~~assign ~~~~~~~a ~~~~~~~+ ~~~~~~~~1 ~~~~~~~~a ~~~~assign ~~~~~a ~~~~~0 ~~~~print ~~~~~"here forever A9 00 A9 00 8D 7E 00 A9 00 8D 7E 00 AD 7E 00 8D 00 00 A9 01 A2 04 EC 00 00 D0 02 A9 00 8D 01 00 A9 01 8D 00 00 AE 01 00 EC 00 00 D0 15 AC 7E 00 A2 01 FF A9 01 6D 7E 00 8D 7E 00 A2 00 EC 7E 00 D0 CA A9 00 8D 7E 00 A0 71 A2 02 FF D0 BE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 68 65 72 65 20 66 6F 72 65 76 65 72 00 00 00