Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed some small things and updated README for hmwk5.
  • Loading branch information
johngunderman committed Nov 19, 2009
1 parent a7de913 commit fa33864
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 43 deletions.
106 changes: 65 additions & 41 deletions README
Expand Up @@ -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.
Expand All @@ -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:
=====
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -200,6 +236,7 @@ join->equality
bool->join
stmt->loc = bool
stmts->stmts stmt
getting next instruction...
loc->ID
loc->ID
factor->loc
Expand Down Expand Up @@ -232,6 +269,7 @@ join->equality
bool->join
stmt->loc = bool
stmts->stmts stmt
getting next instruction...
loc->ID
loc->ID
factor->loc
Expand All @@ -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

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
4 changes: 2 additions & 2 deletions intmdt_code_gen.c
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions test_suite.c
Expand Up @@ -261,6 +261,7 @@ void gen_test() {
}



//======//
// MAIN //
//======//
Expand Down

0 comments on commit fa33864

Please sign in to comment.