Skip to content

Commit

Permalink
IdArrayK 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
zfanta committed Dec 14, 2014
1 parent d87db86 commit 1cd10c1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion yacc/cminus.y
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 199,7 @@ var : ID
$$->lineno = lineStackPop();
}
| ID LBRACE expression RBRACE
{ $$ = newExpNode(IdK);
{ $$ = newExpNode(IdArrayK);
$$->attr.name = nameStackPop();
$$->child[0] = $3;
$$->lineno = lineStackPop();
Expand Down

0 comments on commit 1cd10c1

Please sign in to comment.