diff --git a/analyze.c b/analyze.c index e4db749..8912272 100644 --- a/analyze.c +++ b/analyze.c @@ -114,6 +114,7 @@ static void insertNode( TreeNode * t) fprintf(listing, "error:%d: %s is already declared\n", t->lineno, t->attr.name); break; case IdK: + case IdArrayK: case CallK: if (st_lookup(scope,t->attr.name) == NULL) fprintf(listing, "error:%d: %s is not declared\n", t->lineno, t->attr.name); @@ -191,10 +192,12 @@ static void checkNode(TreeNode * t) break; case IdK: break; + case IdArrayK: + break; case CallK: break; case AssignK: - if (t->child[1]->kind.exp == IdK || t->child[1]->kind.exp == CallK) + if (t->child[1]->kind.exp == IdK || t->child[1]->kind.exp == CallK || t->child[1]->kind.exp == IdArrayK) { bucket = st_lookup(scope, t->child[1]->attr.name); if (bucket->type != Integer) typeError(t->child[1], "rvalue must be instger type"); diff --git a/globals.h b/globals.h index 6ef0f3d..e5d4def 100644 --- a/globals.h +++ b/globals.h @@ -64,7 +64,7 @@ extern int lineno; /* source line number for listing */ typedef enum {StmtK,ExpK} NodeKind; typedef enum {IfK,FunctionK,CompoundK,WhileK,ReturnK} StmtKind; -typedef enum {OpK,VarK,VarArrayK,ConstK,IdK,CallK,AssignK,SingleParamK,ArrayParamK} ExpKind; +typedef enum {OpK,VarK,VarArrayK,ConstK,IdK,IdArrayK,CallK,AssignK,SingleParamK,ArrayParamK} ExpKind; /* ExpType is used for type checking */ typedef enum {Void,Integer} ExpType; diff --git a/util.c b/util.c index 9a7c4e1..c2d8d73 100644 --- a/util.c +++ b/util.c @@ -168,6 +168,7 @@ void printTree( TreeNode * tree ) fprintf(listing,"Const : %d\n",tree->attr.val); break; case IdK: + case IdArrayK: fprintf(listing,"Id : %s\n",tree->attr.name); break; case VarK: diff --git a/yacc/cminus.y b/yacc/cminus.y index 87d0fb9..a46b562 100644 --- a/yacc/cminus.y +++ b/yacc/cminus.y @@ -199,7 +199,7 @@ var : ID $$->lineno = lineStackPop(); } | ID LBRACE expression RBRACE - { $$ = newExpNode(IdK); + { $$ = newExpNode(IdArrayK); $$->attr.name = nameStackPop(); $$->child[0] = $3; $$->lineno = lineStackPop();