Compiler Design Part-1

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:
    

       Structure of a compiler/Phases of a compiler



    Usage of Symbol Table

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
P     Problem Example

     Difference between lexeme and 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

     LA uses DFA for Tokenization, It is the only phase that reads the program char by char

Lexical Error: will be updated
Lexical Error Recovery

    Left Factoring:
     To get rid of non-determinism and common prefixes.
     Eliminationg non-determinism doesn't effect Ambuguity.

Popular Post

MindMaps

Featured post

Question 1: Reverse Words in a String III

  def reverseWords(s: str) -> str: words = s.split() return ' '.join(word[::-1] for word in words)