Symbol Table

Only available on StudyMode
  • Topic: Hash function, Hash table, Bloom filter
  • Pages : 5 (1792 words )
  • Download(s) : 75
  • Published : May 20, 2013
Open Document
Text Preview
A compiler uses a symbol table to keep track of scope and binding information about names. The symbol table is searched every time a name is encountered in the source text. Changes to the symbol table occur if a new name or new information about an existing name is discovered. A symbol table mechanism must allow us to add new entries and find existing entries. The two symbol table mechanisms are linear lists and hash tables. Each scheme is evaluated on the basis of time required to add n entries and make e inquiries. A linear list is the simplest to implement, but its performance is poor when n and e are large. Hashing schemes provide better performance for greater programming effort and space overhead. It is useful for a compiler to be able to grow the symbol table dynamically at compile time. If the symbol table is fixed when the compiler is written, the size must be chosen large enough to handle any source program that might be presented. SYMBOL-TABLE ENTRIES

Each entry in the symbol table is for the declaration of a name. The format of entries does have to be uniform, because the information saved about a same depends on the usage of time. Each entry can be implemented as a record consisting of a sequence of consecutive words of memory. To keep symbol table entries uniform, it may be convenient for some of the information about a name to be kept outside the table entry, with only a pointer to this information stored in the record. Information is entered into the symbol table at various times. Keywords are entered initially. The lexical analyzer looks up sequences of letters and digits in the symbol table to determine if a reserved keyword or a name has been collected. With this approach, keywords must be in the symbol table before lexical analysis begins. Alternatively, if lexical analyzer intercepts reserved keywords, they should be entered into the symbol table with a warning of their possible use as a keyword. The symbol table entry itself can be set up when the role of a name becomes clear, with the attribute values being filled in as the information become available. In some cases, the entry can be initiated from the lexical analyzer as soon as a name is seen in the input. More often, one name may denote several different objects, even in the same block or procedure. For example, the C declarations

int x;
struct x {float y, z;};
use x as both an integer and as the tag of a structure with two fields. In such cases, the lexical analyzer can only return to the parser the name itself rather than a pointer to the symbol table entry. The record in the symbol table is created when the syntactic role played by the name is discovered. Attributes of a name are entered in response to declarations. Labels are identifiers followed by a colon, so one action associated with recognizing such an identifier may be to enter this fact into symbol table. CHARACTERS IN A NAME There is a distinction between the token id for an identifier or name, the lexeme consisting of the character string forming the name, and the attributes of the name. The lexeme is needed when a symbol table entry is set up for the first time and when we look up a lexeme found in the input to determine whether it is a name that has already appeared. A common representation of a name is a pointer to a symbol table entry for it. If there is a modest upper bound on the length of a name, then the characters in the name can be stored in the symbol table entry as shown in figure. If there is no limit on the length of a name the indirect scheme can be used. Rather than allocating in each symbol table entry the maximum possible amount of space to hold a lexeme, utilize space more efficiently if there is only space for a pointer in the symbol table entry. In the record for a name, a pointer is placed to a separate...
tracking img