-
Notifications
You must be signed in to change notification settings - Fork 1
/
symtab.h
79 lines (64 loc) · 2.12 KB
/
symtab.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/****************************************************/
/* File: symtab.h */
/* Symbol table interface for the TINY compiler */
/* (allows only one symbol table) */
/* C- Compiler Project */
/* ZEBRA */
/****************************************************/
#ifndef _SYMTAB_H_
#define _SYMTAB_H_
/* SIZE is the size of the hash table */
#define SIZE 211
/* MAX_SCOPE is maximum allowed scope can be changed for larger programs*/
#define MAX_SCOPE 8
/* the list of line numbers of the source
* code in which a variable is referenced
*/
typedef struct LineListRec
{ int lineno;
struct LineListRec * next;
} * LineList;
/* The record in the bucket lists for
* each variable, including name,
* assigned memory location, and
* the list of line numbers in which
* it appears in the source code
*/
typedef struct BucketListRec
{ char * name;
LineList lines;
int memloc ; /* memory location for variable */
int scope; /* scope of the variable */
int isParam; /* param */
int fun_start; /*function start location */
struct BucketListRec * next;
} * BucketList;
/* the hash table */
//static BucketList hashTable[SIZE];
static struct ScopeList{
BucketList hashTable[SIZE];
} Scope[MAX_SCOPE];
/* Procedure st_insert inserts line numbers and
* memory locations into the symbol table
* loc = memory location is inserted only the
* first time, otherwise ignored
*/
void st_insert( char * name, int lineno, int loc ,int scope,int isparam);
/* Function st_lookup returns the memory
* location of a variable or -1 if not found
*/
int st_lookup ( char * name,int scope );
/* Function fun_lookup returns the bucket
* location of a funtion or NULL if not found
*/
BucketList fun_lookup ( char * name ,int sp);
/* Function var_lookup returns the bucket
* location of a var or NULL if not found
*/
BucketList var_lookup ( char * name ,int sp);
/* Procedure printSymTab prints a formatted
* listing of the symbol table contents
* to the listing file
*/
void printSymTab(FILE * listing);
#endif