【正文】
constant 6 address a+R0 Major Data Structures in Compiler ? There is a strong interaction between the algorithms used by the phases of a piler and the data structures that support these phases. ? Algorithms need to be implemented in efficient manner. ? The choice of data structures is important Tokens ? When a scanner collects characters into a token, it represents the token symbolically – as a value of an enumerated data type representing a set of tokens of the source language ? Sometimes, it is necessary to preserve the character string itself or other information derived from it – The name associated with an identifier token – The value of a number token ? In most languages the scanner needs to generate one token at a time (single symbol lookahead) – A single global variable can be used to hold the token information. The Syntax Tree ? The syntax tree is constructed as a standard pointerbased structure that is dynamically allocated as parsing proceeds. ? The tree can be kept as a single variable pointing to the root node. ? Each node is a record. Its fields represent the information collected by the parser and the semantic analyzer. – Sometimes these fields are dynamically allocated The Symbol Table ? This data structure keeps information associated with identifiers: functions, variables, constants, and data types. ? The symbol table interacts with almost every phase of the piler. ? The insertion, deletion access operations need to be efficient. ? A standard data type for this purpose is the hash table. The Literal Table ? Stores constants and strings used in the program. ? Quick insertion and lookup are essential. ? Need not allow deletions. Intermediate Code ? Depending on the kind of intermediate code, it may be kept as – An array of text strings – A temporary text file – Linked list of structures Temporary Files ? Computers did not possess enough memory for an entire program to be kept in memory during pilation. ? This was solved by using temporary files to hold the products of intermediate steps. ? Memory constrains are now much smaller problem. ? Occasionally, pilers generate intermediate files during some of the steps. Passes ? A piler often processed the entire source program several times before generating code. ? These repetitions are referred as passes. ? Passes may or may not correspond to phases. ? Depending on the language, a piler may be one pass. – Efficient pilation, but not efficient target code. – Examples: Pascal and C. ? Most pilers with optimizations use more than one pass: 1. Scanning and parsing 2. Semantic analysis and sourcelevel optimization 3. Code generation and target code optimization Language Definition ? The description of the lexical, syntactic, and semantics of a programming language is collected in a language reference manual, or language definition. ? With a new language, a language definition and piler are often developed together. ? More mon situation is when a piler is written for wellknown language which has an exiting language definition. Error Handling ? One of the most important functions of a piler. ? Errors can be detected during almost every ph