Mod 2 (introduction) Flashcards
Language processing diagram (stages of language processing)
preprocessor -> compiler -> assembler -> linker/loader
role of preprocessor
a program may be divided into modules stored in a separate file
the task of collecting the source program in entrusted to the preprocessor
the preprocess is also required to expand on shorthands, called as macros
role of compiler
the modified source program is fed into the compiler.
the compiler produces an assembly language with the modified source program
role of assembler
the assembler processes the assembly program
it produces a relocatable machine code as its output
role of linker/loader
large programs need to be compiled in pieces.
the relocatable machine code may have to be linked together with other relocatable machine code and library files, so the program can actually run on the machine.
Structure of compiler
lexical analyzer syntax analyzer symantic analyzer intermediate code generator code optimizer code generator
Role of lexical analyzer
reads the input from the source program and produces a meaningful sequence of character called as lexemes
these lexemes are sent to the next stages of the compiler as tokens
these lexemes are also stored into a symbol table for further referencing
Role of syntax analyzer
it uses the tokens generated in the prev stage of the analysis and generates an intermediate tree like representation, called the syntax tree
a syntax tree consists of interior nodes that represent the operations and the children of the node represent the arguments of the operation
Role of semantic analyzer
it uses the syntax tree and the symbol table from the previous steps to check for the type consistency with the language
it gathers the type information and saves it for either the syntax tree or the symbol table for subsequent use during the intermediate code generation
Role of intermediate code generator
most compilers generate a intermediate low level or machine like intermediate representation
this intermediate representation should have two important properties
- it should be easy to produce
- it should be easy to translate it to target machine code
Role of code optimizer
it attempts to improve the intermediate code so that it will result in a better target code
better usually means faster, but it can also shorter code, or it consumes less power
Role of code generator
the main role is to generate the target machine code of the given source code
it takes the intermediate code representation and maps it to the target language
if the target is machine code, it maps the memory location or registers for each variable
it is then translated into sequences of machine instructions
the crucial part is the judicious assignment of the registers for the local variables