Berkeley YACC  1993-03-03
Berkeley's version of Yet Another Compiler Compiler
 All Data Structures Files Functions Variables Typedefs Macros Groups
symtab.c File Reference
#include "defs.h"
+ Include dependency graph for symtab.c:

Go to the source code of this file.

Macros

#define TABLE_SIZE   1024
 

Functions

int hash (char *name)
 
bucketmake_bucket (char *name)
 
bucketlookup (char *name)
 
 create_symbol_table ()
 
 free_symbol_table ()
 
 free_symbols ()
 

Variables

bucket ** symbol_table
 
bucketfirst_symbol
 
bucketlast_symbol
 

Macro Definition Documentation

#define TABLE_SIZE   1024

Definition at line 7 of file symtab.c.

Referenced by create_symbol_table(), and hash().

Function Documentation

create_symbol_table ( )

Definition at line 83 of file symtab.c.

References bucket::class, hash(), bucket::index, make_bucket(), MALLOC, no_space(), TABLE_SIZE, and TERM.

Referenced by reader().

84 {
85  register int i;
86  register bucket *bp;
87 
88  symbol_table = (bucket **) MALLOC(TABLE_SIZE*sizeof(bucket *));
89  if (symbol_table == 0) no_space();
90  for (i = 0; i < TABLE_SIZE; i++)
91  symbol_table[i] = 0;
92 
93  bp = make_bucket("error");
94  bp->index = 1;
95  bp->class = TERM;
96 
97  first_symbol = bp;
98  last_symbol = bp;
99  symbol_table[hash("error")] = bp;
100 }
#define MALLOC(n)
Definition: defs.h:103
bucket ** symbol_table
Definition: symtab.c:10
#define TERM
Definition: defs.h:71
int hash(char *name)
Definition: symtab.c:16
bucket * make_bucket(char *name)
Definition: symtab.c:33
no_space()
Definition: error.c:27
char class
Definition: defs.h:121
bucket * first_symbol
Definition: symtab.c:11
bucket * last_symbol
Definition: symtab.c:12
short index
Definition: defs.h:119
#define TABLE_SIZE
Definition: symtab.c:7
Definition: defs.h:112

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

free_symbol_table ( )

Definition at line 103 of file symtab.c.

References FREE.

Referenced by reader().

104 {
106  symbol_table = 0;
107 }
bucket ** symbol_table
Definition: symtab.c:10
#define FREE(x)
Definition: defs.h:102

+ Here is the caller graph for this function:

free_symbols ( )

Definition at line 110 of file symtab.c.

References FREE, and bucket::next.

Referenced by reader().

111 {
112  register bucket *p, *q;
113 
114  for (p = first_symbol; p; p = q)
115  {
116  q = p->next;
117  FREE(p);
118  }
119 }
bucket * first_symbol
Definition: symtab.c:11
#define FREE(x)
Definition: defs.h:102
struct bucket * next
Definition: defs.h:115
Definition: defs.h:112

+ Here is the caller graph for this function:

int hash ( char *  name)

Definition at line 16 of file symtab.c.

References TABLE_SIZE.

Referenced by create_symbol_table(), and lookup().

18 {
19  register char *s;
20  register int c, k;
21 
22  assert(name && *name);
23  s = name;
24  k = *s;
25  while (c = *++s)
26  k = (31*k + c) & (TABLE_SIZE - 1);
27 
28  return (k);
29 }
#define TABLE_SIZE
Definition: symtab.c:7

+ Here is the caller graph for this function:

bucket* lookup ( char *  name)

Definition at line 60 of file symtab.c.

References hash(), bucket::link, make_bucket(), bucket::name, and bucket::next.

62 {
63  register bucket *bp, **bpp;
64 
65  bpp = symbol_table + hash(name);
66  bp = *bpp;
67 
68  while (bp)
69  {
70  if (strcmp(name, bp->name) == 0) return (bp);
71  bpp = &bp->link;
72  bp = *bpp;
73  }
74 
75  *bpp = bp = make_bucket(name);
76  last_symbol->next = bp;
77  last_symbol = bp;
78 
79  return (bp);
80 }
bucket ** symbol_table
Definition: symtab.c:10
char * name
Definition: defs.h:116
int hash(char *name)
Definition: symtab.c:16
struct bucket * link
Definition: defs.h:114
bucket * make_bucket(char *name)
Definition: symtab.c:33
bucket * last_symbol
Definition: symtab.c:12
struct bucket * next
Definition: defs.h:115
Definition: defs.h:112

+ Here is the call graph for this function:

bucket* make_bucket ( char *  name)

Definition at line 33 of file symtab.c.

References bucket::assoc, bucket::index, bucket::link, MALLOC, bucket::name, bucket::next, no_space(), bucket::prec, strcpy(), bucket::tag, TOKEN, UNDEFINED, UNKNOWN, and bucket::value.

Referenced by create_symbol_table(), and lookup().

35 {
36  register bucket *bp;
37 
38  assert(name);
39  bp = (bucket *) MALLOC(sizeof(bucket));
40  if (bp == 0) no_space();
41  bp->link = 0;
42  bp->next = 0;
43  bp->name = MALLOC(strlen(name) + 1);
44  if (bp->name == 0) no_space();
45  bp->tag = 0;
46  bp->value = UNDEFINED;
47  bp->index = 0;
48  bp->prec = 0;
49  bp-> class = UNKNOWN;
50  bp->assoc = TOKEN;
51 
52  if (bp->name == 0) no_space();
53  strcpy(bp->name, name);
54 
55  return (bp);
56 }
char * tag
Definition: defs.h:117
#define TOKEN
Definition: defs.h:56
#define MALLOC(n)
Definition: defs.h:103
#define UNDEFINED
Definition: defs.h:77
char * name
Definition: defs.h:116
#define UNKNOWN
Definition: defs.h:70
short prec
Definition: defs.h:120
struct bucket * link
Definition: defs.h:114
no_space()
Definition: error.c:27
short index
Definition: defs.h:119
struct bucket * next
Definition: defs.h:115
short value
Definition: defs.h:118
char assoc
Definition: defs.h:122
char * strcpy()
Definition: defs.h:112

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

bucket* first_symbol

Definition at line 11 of file symtab.c.

Referenced by check_symbols(), pack_names(), and pack_symbols().

bucket* last_symbol

Definition at line 12 of file symtab.c.

Referenced by insert_empty_rule().

bucket** symbol_table

Definition at line 10 of file symtab.c.