Compiler 강의 노트 CH3

유형주·2022년 4월 17일
0

Compiler structure

  • All the modern compiler are consisit of front end and back end. The division between two phases is the Intermediate code.
  • Front end and Back end are completely separeted.
    - Front : It only related to source code, makes IR. Scanner(spelling), Parser(grammar), Sementic analyzer. Optionally optimizes.
    - Back : It only related to IR, translates IR into target program. Generages objec code(assembly). Optimize.

Scanner

  1. Reads source program as stream of characters
  2. Performs lexical analysis - collects sequence of chracters into meaninful units called lexems/toekns
  3. <token Name , attribute Value> ex)<main-function, main()>
  4. Performs spelling check
  5. white space eliminated

Parser

  1. Uses tokens to build syntax or parse tree.
  2. Performs synxat analysis using token obtained from the scanner
  3. grammatical analysis based on CFG
    • we have CFG, CSG.
    • CSG is for analyzing natural language.

Semantic analyzer

  • static semantic : language features can be determinde prior to execution. It can't be expressed in syntax. ex)declaration, type check
  • dynamic semantic : determined during execution. ex) array bound checking

This makes full use of symmbol table. makes annotated parse tree.

annotated parse tree

  • It is related to semantic checking.

syntax tree and parse tree

  • Parse tree : It has some grammar, consist of grammar symbol such as nonterminals.

  • Syntax tree : Removes grammar nonterminals.

0개의 댓글