Structure and function of Compiler

Any compiler must perform two major tasks

  • analysis of the source program
  • synthesis of a machine language program

 
Structure of Compiler
Fig: Structure of a compiler
Scanner

  • the scanner begins the analysis of the source program by reading the input, character by character, and grouping characters into individual words and symbols (tokens)
    • RE (Regular Expression)
    • NFA (Non-deterministic finite automata)
    • DFA (Deterministic finite automata)
    • LXA

Parser

  • Given a format syntax specification (typically as a context-free grammar [CFG]), the parser reads tokens and groups them into units as specified by the productions of the CFG being used.
  • As syntactic structure is recognized, the parser either calls corresponding semantic routines directly or builds a syntax tree.
    • CFG (Context Free Grammar)
    • BNF (Backus-Naur Form)
    • GAA (Grammar Analysis Algorithms)
    • LL, LR, SLR, LALR Parsers
    • YACC

Semantic Routines

  • perform two functions
    • check the static semantics of each construct
    • Do the actual translation
    • heart of the compiler
      • syntax Directed Translation
      • semantic Processing Techniques
      • IR (intermediate Representation)

Optimizer

  • The IR generated by the semantic routines is analyzed and transformed into functionally equivalent but improved IR code
  • This phase can be very complex and slow
  • peehole optimization
  • loop optimization, register allocation, code scheduling
    • register and temporary management
    • peehole optimization

Code Generator

  • interpretive code generation
  • generating code from Tree/Dag
  • Grammar-Based code generator

Leave a Reply

Your email address will not be published. Required fields are marked *