This compiler is a project for Case Western Reserve University's EECS 337 course (Compiler Design). By John Gunderman The parser runs seperately from the test suite. Compiling the parser is as easy as a 'make -B parser', and running it is as easy as a './parser [filename]', where filename is one of the three source files in the project. These source files are named test.code, test2.code, and test3.code. The test suite can be compiled by running 'make test'. It will create the './test_suite' executable, which can then be run. Locations of variables are printed out when the symbol table gets printed out. Error Handing: ============= Error handling is rather primitive, but generally prints a vague message about where the error might be. UPDATE: you may get a segfault if you try and treat a number as a boolean or vice versa. Also, implicit widening does not occur in the given test program, but it can be shown to work by adding the line x = i + v; to the end of the main block. TEST PROGRAM: { int i; int j; float v; float x; float[100] a; while (true) { do i = i+1; while(a[i] < v); do j = j-1; while(a[j] > v); if(i >= j) break; x = a[i]; a[i] = a[j]; a[j] = x; } } Other test programs can be found in the root directory of this project. Their output is not included here for the simple reason that it would make this document way to long (aka I'm running low on printer paper). Feel free to run them and check them out. OUTPUT: decls->empty type-> BASIC decl-> type ID decls->decls decl type-> BASIC decl-> type ID decls->decls decl type-> BASIC decl-> type ID decls->decls decl type-> BASIC decl-> type ID decls->decls decl type-> BASIC type-> type [ NUM ] decl-> type ID decls->decls decl stmts->empty getting next instruction... getting next instruction... factor->TRUE urnary->factor term->urnary expr->term rel->expr equality->rel join->equality bool->join getting next instruction... Entering New Scope decls->empty stmts->empty getting next instruction... getting next instruction... loc->ID loc->ID factor->loc urnary->factor term->urnary expr->term factor->NUM urnary->factor term->urnary expr->expr + expr rel->expr equality->rel join->equality bool->join stmt->loc = bool loc->ID loc->ID factor->loc urnary->factor term->urnary expr->term rel->expr equality->rel join->equality bool->join loc-> loc [ bool ] factor->loc urnary->factor term->urnary expr->term loc->ID factor->loc urnary->factor term->urnary expr->term rel->expr < expr equality->rel join->equality bool->join stmt->DO stmt WHILE ( bool ) ; stmts->stmts stmt getting next instruction... getting next instruction... loc->ID loc->ID factor->loc urnary->factor term->urnary expr->term factor->NUM urnary->factor term->urnary expr->expr - expr rel->expr equality->rel join->equality bool->join stmt->loc = bool loc->ID loc->ID factor->loc urnary->factor term->urnary expr->term rel->expr equality->rel join->equality bool->join loc-> loc [ bool ] factor->loc urnary->factor term->urnary expr->term loc->ID factor->loc urnary->factor term->urnary expr->term rel->expr > expr equality->rel join->equality bool->join stmt->DO stmt WHILE ( bool ) ; stmts->stmts stmt getting next instruction... loc->ID factor->loc urnary->factor term->urnary expr->term loc->ID factor->loc urnary->factor term->urnary expr->term rel->expr >= expr equality->rel join->equality bool->join getting next instruction... getting next instruction... stmt->BREAK ; stmt->IF ( bool ) stmt stmts->stmts stmt getting next instruction... loc->ID loc->ID loc->ID factor->loc urnary->factor term->urnary expr->term rel->expr equality->rel join->equality bool->join loc-> loc [ bool ] factor->loc urnary->factor term->urnary expr->term rel->expr equality->rel join->equality bool->join stmt->loc = bool stmts->stmts stmt getting next instruction... loc->ID loc->ID factor->loc urnary->factor term->urnary expr->term rel->expr equality->rel join->equality bool->join loc-> loc [ bool ] loc->ID loc->ID factor->loc urnary->factor term->urnary expr->term rel->expr equality->rel join->equality bool->join loc-> loc [ bool ] factor->loc urnary->factor term->urnary expr->term rel->expr equality->rel join->equality bool->join stmt->loc = bool stmts->stmts stmt getting next instruction... loc->ID loc->ID factor->loc urnary->factor term->urnary expr->term rel->expr equality->rel join->equality bool->join loc-> loc [ bool ] loc->ID factor->loc urnary->factor term->urnary expr->term rel->expr equality->rel join->equality bool->join stmt->loc = bool stmts->stmts stmt block->decls stmts stmt->block Leaving Scope stmt->WHILE ( bool ) stmt stmts->stmts stmt block->decls stmts Environment Table (Top - 0) Key: i Value: {loc=0, &int_var,0,0,NULL,NULL} Key: j Value: {loc=4, &int_var,0,0,NULL,NULL} Key: v Value: {loc=8, &float_var,0,0,NULL,NULL} Key: x Value: {loc=12, &float_var,0,0,NULL,NULL} Key: a Value: {loc=16, &float_var,1,100,{loc=16, &float_var,0,0,NULL,0x8ba4538},NULL} Intermediate Code: Op Arg1 Arg2 Result goto Code: 0x804d47d + Symbol: i Symbol: @1 Symbol: @2 = Symbol: @2 Symbol: i < Symbol: a Symbol: v Code: 0x804d47d goto Code: 0x804d491 - Symbol: j Symbol: @4 Symbol: @5 = Symbol: @5 Symbol: j > Symbol: a Symbol: v Code: 0x804d491 goto Code: 0x804d44b >= Symbol: i Symbol: j Code: 0x804d284 goto Code: 0x804d251 goto Code: 0x804d251 = Symbol: a Symbol: x = Symbol: a Symbol: a = Symbol: x Symbol: a goto Code: 0x804d284