Compiler: It is a language translator which translates from one language to other
Contents:
- Lexical analysis, parsing, syntax-directed translation
- Runtime environments
- Intermediate code generation
- Local optimization
- Data flow analysis: constant propagation, liveness analysis, common subexpression elimination.
Language Processing System:
Phase | Usage |
---|---|
Lexical Analysis --> | create new entites for new Identifiers |
Syntax Analysis:--> | Adds information regarding attributes like type, scope, dimension, line of reference & line of use |
Semantic Analysis:--> | Use the available information to check for semantics & is updated |
Intermediate code--> generation | to add temporary variables |
code optimization --> | Information in symbol table used in machine-dependent optimization by considering addresses & aliased variables information. |
Target code generator-> | Generates the code by using the addresses information of identifiers. |
Symbol table entries
Each entry in the symbol table is assciated with attributes that support the compiler in different phases
Attributes are: Name, Size, Dimension, Type, Line of declaration, line of usage, Address.
Lexical analysis:
- We need to define the rules to construct the expression based on source code.
- The lexer takes the regular expression as input and then converts it into the equivalent FA
- Every string which is scanned for source code is given as an input for Finite Automata to check the validity of the string.
- If the string is accepted by FA, then the string becomes a token
Lexeme is a token name, where token contains token name and attribute value.
Design of Lexical Analyzer
We can either write a manual program for lexical analyzer or use tool.(Lex tool)
Manual design: Token -> Pattern -> reg Exp -> FA -> Transistion table -> transistion function
Secondary Function of a Lexical analyzer
- Elimination
of white spaces.
- Removal
of comment lines
- Correlating
the error msg by tracing the line number
Lexical Error Recovery