From fa33864b503847851b9665238dc395fd42950600 Mon Sep 17 00:00:00 2001 From: John Gunderman Date: Thu, 19 Nov 2009 10:59:48 -0500 Subject: [PATCH] fixed some small things and updated README for hmwk5. --- README | 106 ++++++++++++++++++++++++++++------------------ intmdt_code_gen.c | 4 +- test_suite.c | 1 + 3 files changed, 68 insertions(+), 43 deletions(-) diff --git a/README b/README index b526616..534d0f5 100644 --- a/README +++ b/README @@ -10,6 +10,24 @@ The test suite can be compiled by running 'make test'. It will create the './test_suite' executable, which can then be run. +So, you may notice that, while everything works well in the code for +Hmwk 5, there is a definite lack of test cases. This is largely due to +the fact that it is 3 in the morning, and I'm not feeling particularly +friendly towards test driven development. Fortunately, this code isn't +going into production, so the lack of test cases won't cause customers +to suffer. Unfortunately, it may cause my grade to suffer. If so, I +would ask that the TA have pity on my soul and only dock me a few points. + +If it counts for anything, my output is pretty :D + +Locations of variables are printed out when the symbol table gets printed out. + +KNOWN PROBLEM: +If-else statements aren't working due to an unfortunate glitch in bison that I +don't know how to fix. Yet. Everything else is working like magic though, +including standard 'if' statements. + + Error Handing: ============= Error handling in this parser is quite simple: don't type it wrong. @@ -20,6 +38,9 @@ to spare). I'll get around to adding line number error handling at some point, but at least yacc tells you that you have a problem. Strategy: Do it right the first time. +UPDATE: you may get a segfault if you try and treat a number as a boolean +or vice versa. + NOTE: ===== @@ -69,6 +90,8 @@ type-> type [ NUM ] decl-> type ID decls->decls decl stmts->empty +getting next instruction... +getting next instruction... factor->TRUE urnary->factor term->urnary @@ -77,8 +100,15 @@ 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 @@ -120,6 +150,8 @@ join->equality bool->join stmt->DO stmt WHILE ( bool ) ; stmts->stmts stmt +getting next instruction... +getting next instruction... loc->ID loc->ID factor->loc @@ -161,6 +193,7 @@ join->equality bool->join stmt->DO stmt WHILE ( bool ) ; stmts->stmts stmt +getting next instruction... loc->ID factor->loc urnary->factor @@ -175,9 +208,12 @@ 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 @@ -200,6 +236,7 @@ join->equality bool->join stmt->loc = bool stmts->stmts stmt +getting next instruction... loc->ID loc->ID factor->loc @@ -232,6 +269,7 @@ join->equality bool->join stmt->loc = bool stmts->stmts stmt +getting next instruction... loc->ID loc->ID factor->loc @@ -256,60 +294,46 @@ stmt->loc = bool stmts->stmts stmt block->decls stmts stmt->block -stmt->WHILE ( bool ) stmt -stmts->stmts stmt -block->decls stmts - -Key: @4 -Value: {unknown_type,0,0,NULL,NULL} -Key: @5 -Value: {&int_var,0,0,NULL,NULL} +Leaving Scope -Key: @6 -Value: {unknown_type,0,0,NULL,NULL} - -Key: @7 -Value: {unknown_type,0,0,NULL,NULL} +stmt->WHILE ( bool ) stmt +stmts->stmts stmt +block->decls stmts -Key: @8 -Value: {unknown_type,0,0,NULL,NULL} +Environment Table (Top - 0) Key: i -Value: {&int_var,0,0,NULL,NULL} +Value: {loc=0, &int_var,0,0,NULL,NULL} Key: j -Value: {&int_var,0,0,NULL,NULL} +Value: {loc=4, &int_var,0,0,NULL,NULL} Key: v -Value: {&float_var,0,0,NULL,NULL} +Value: {loc=8, &float_var,0,0,NULL,NULL} Key: x -Value: {&float_var,0,0,NULL,NULL} - -Key: @1 -Value: {&true_var,0,0,NULL,NULL} +Value: {loc=12, &float_var,0,0,NULL,NULL} Key: a -Value: {&float_var,1,100,{&float_var,0,0,NULL,0x9b71510},NULL} - -Key: @2 -Value: {&int_var,0,0,NULL,NULL} - -Key: @3 -Value: {unknown_type,0,0,NULL,NULL} +Value: {loc=16, &float_var,1,100,{loc=16, &float_var,0,0,NULL,0x8ba4538},NULL} Intermediate Code: -Op Arg1 Arg2 Result -OP: + Symbol: i Symbol: @2 Symbol: @3 -OP: = Symbol: @3 Symbol: i -OP: < Symbol: a Symbol: v Symbol: @4 -OP: - Symbol: j Symbol: @5 Symbol: @6 -OP: = Symbol: @6 Symbol: j -OP: > Symbol: a Symbol: v Symbol: @7 -OP: >= Symbol: i Symbol: j Symbol: @8 -OP: = Symbol: a Symbol: x -OP: = Symbol: a Symbol: a -OP: = Symbol: x Symbol: a - \ No newline at end of file +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 \ No newline at end of file diff --git a/intmdt_code_gen.c b/intmdt_code_gen.c index 6631c6b..f808f33 100644 --- a/intmdt_code_gen.c +++ b/intmdt_code_gen.c @@ -140,7 +140,7 @@ unsigned int sizeofidtype(id_type_t *t) { void intmdt_addr_print(intmdt_addr_t *t) { if (t == NULL) { - printf("NULL\t\t"); + printf("\t\t"); return; } @@ -250,7 +250,7 @@ list_entry_t *widen(intmdt_code_t* code, env_t *top, intmdt_addr_t *a, id_type_t to hash_pretty_print(); */ void print_id_type (void *id) { - printf("{"); + printf("{loc=%d, ", ((id_type_t*)id)->location); switch (*(unsigned int *)((id_type_t *)id)->type) { case 1: printf("&int_var"); diff --git a/test_suite.c b/test_suite.c index 57f036e..e1cfe19 100644 --- a/test_suite.c +++ b/test_suite.c @@ -261,6 +261,7 @@ void gen_test() { } + //======// // MAIN // //======//