Skip to content

Commit

Permalink
심볼테이블에 배열 정보 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
zfanta committed Dec 19, 2014
1 parent e235eab commit 89b873d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 11 additions & 3 deletions symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 69,7 @@ ScopeList getScope(char * scope)
* loc = memory location is inserted only the
* first time, otherwise ignored
*/
void st_insert_( ScopeList scope, char * name, ExpType type, int lineno, int loc )
void st_insert_( ScopeList scope, char * name, ExpType type, int lineno, int loc, int isArray )
{ int h = hash(name);
BucketList l = scope->bucket[h];
while ((l != NULL) && (strcmp(name,l->name) != 0))
Expand All @@ -83,6 83,7 @@ void st_insert_( ScopeList scope, char * name, ExpType type, int lineno, int loc
l->memloc = loc;
l->lines->next = NULL;
l->next = scope->bucket[h];
l->isArray = isArray;
scope->bucket[h] = l; }
else /* found in table, so just add line number */
{ LineList t = l->lines;
Expand All @@ -93,7 94,7 @@ void st_insert_( ScopeList scope, char * name, ExpType type, int lineno, int loc
}
}

void st_insert( char * scope, char * name, ExpType type, int lineno, int loc )
void st_insert( char * scope, char * name, ExpType type, int lineno, int loc, int isArray )
{ int h = hash(scope);
ScopeList l = scopeHashTable[h];
while ((l != NULL) && (strcmp(scope,l->name) != 0))
Expand All @@ -106,7 107,7 @@ void st_insert( char * scope, char * name, ExpType type, int lineno, int loc )
strcpy(l->name, scope);
l->next = scopeHashTable[h];
scopeHashTable[h] = l; }
st_insert_(l, name, type, lineno, loc);
st_insert_(l, name, type, lineno, loc, isArray);
}/* st_insert */

/* Function st_lookup returns the memory
Expand Down Expand Up @@ -168,6 169,13 @@ BucketList st_lookup_excluding_parent ( char * scope, char * name )
return st_lookup_(l, name);
}

int checkArray(char *scope, char *name)
{ BucketList bucketList = st_lookup(scope, name);
if(bucketList == NULL)
return -1;
return bucketList->isArray;
}

void addline( char * scope, char * name, int lineno )
{ BucketList bucket;
LineList lineList;
Expand Down
4 changes: 3 additions & 1 deletion symtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 30,7 @@ typedef struct LineListRec
typedef struct BucketListRec
{ char * name;
ExpType type;
int isArray;
LineList lines;
int memloc ; /* memory location for variable */
struct BucketListRec * next;
Expand All @@ -51,7 52,7 @@ typedef struct ScopeListRec
* loc = memory location is inserted only the
* first time, otherwise ignored
*/
void st_insert( char * scope, char * name, ExpType type, int lineno, int loc );
void st_insert( char * scope, char * name, ExpType type, int lineno, int loc, int isArray );

/* Function st_lookup returns the memory
* location of a variable or -1 if not found
Expand All @@ -60,6 61,7 @@ BucketList st_lookup ( char * scope, char * name );
BucketList st_lookup_excluding_parent ( char * scope, char * name );
int st_get_location( char * scope, char * name );
ScopeList getScope(char * scope);
int checkArray(char *scope, char *name);

/* Procedure printSymTab prints a formatted
* listing of the symbol table contents
Expand Down

0 comments on commit 89b873d

Please sign in to comment.