diff --git a/src/analyze.c b/src/analyze.c index 9d7ec5c..8d65cb2 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -131,8 +131,8 @@ static void insertNode(TreeNode *t) { case DeclK: switch (t->kind.decl) { case FuncK: { - BucketList entry; - if (st_lookup(t->attr.name) != NULL) { + BucketList entry = st_lookup(t->attr.name); + if (entry != NULL) { fprintf(listing, "Error: Symbol \"%s\" is redefined at line %d (already defined at line", t->attr.name, t->lineno); LineList lines = entry->lines; while (lines != NULL) { @@ -140,7 +140,9 @@ static void insertNode(TreeNode *t) { fprintf(listing, "%d", lines->lineno); lines = lines->next; } + st_entry_insert_line(entry, t->lineno); fprintf(listing, ")\n"); + Error = TRUE; } else { func_entry = st_try_insert(t->attr.name, SymbolFunc, t->type, t->lineno); diff --git a/src/cminus.y b/src/cminus.y index 4ab1bdc..6084fe1 100644 --- a/src/cminus.y +++ b/src/cminus.y @@ -18,7 +18,7 @@ static int savedNumber; static int savedLineNo; /* ditto */ static TreeNode * savedTree; /* stores syntax tree for later return */ static int yylex(void); // added 11/2/11 to ensure no conflict with lex - +int yyerror(char * message); %} %token IF ELSE WHILE RETURN INT VOID @@ -120,13 +120,16 @@ param_list : param_list COMMA param { } | param {$$ = $1; }; param : type_specifier name_specifier { - $$ = newDeclNode(NonArrParamK ); + $$ = newDeclNode(NonArrParamK); $$->attr.name = savedName; $$->type = $1->type; } | type_specifier name_specifier LBRACE RBRACE { $$ = newDeclNode(ArrParamK); - $$->type = $1->type; $$->attr.name = savedName; + if ($1->type == Integer) + $$->type = IntegerArray; + else + $$->type = Void; }; compound_stmt : LCURLY local_declarations statement_list RCURLY { diff --git a/src/main.c b/src/main.c index f63adde..98a062a 100644 --- a/src/main.c +++ b/src/main.c @@ -39,7 +39,7 @@ FILE *code; /* allocate and set tracing flags */ int EchoSource = FALSE; int TraceScan = FALSE; -int TraceParse = FALSE; +int TraceParse = TRUE; int TraceAnalyze = TRUE; int TraceCode = FALSE; diff --git a/src/test.cm b/src/test.cm index 2e575b5..cc817e0 100644 --- a/src/test.cm +++ b/src/test.cm @@ -1,16 +1,42 @@ -int main(void) +int zero(void) { - x(1, 2); + return 0; } -/* -int main(void) { - if (x) { - int x; - x = 3; - } else { - int y; - y = 0; - x = 5; - } - output(x); -}*/ \ No newline at end of file + +int first(int data[]) +{ + return data[0]; +} + +void scopedemo(void) +{ + int outer; + outer = 1; + { + int outer; + outer = outer + 2; + } +} + +void output(void) +{ + return; +} + +int input; + +void main(void) +{ + int arr[2]; + arr[0] = 5; + scopedemo(); + first(arr); + zero(); + zero(1); + { + int blockOnly; + blockOnly = arr[0]; + } + blockOnly; + return; +} \ No newline at end of file