Lecture 13-14 Semantic analysis + Code generation


Download 427.34 Kb.
bet1/4
Sana03.12.2023
Hajmi427.34 Kb.
#1806766
  1   2   3   4
Bog'liq
13-14 lecture

Lecture 13-14

Semantic analysis + Code generation

Semantic Analysis

The compilation process is driven by the syntactic structure of the program as discovered by the parser

Semantic routines:

    • interpret meaning of the program based on its syntactic structure
    • two purposes:
      • finish analysis by deriving context-sensitive information
      • begin synthesis by generating the IR or target code
    • associated with individual productions of a context free grammar or sub-trees of a syntax tree

Context-sensitive analysis

What context-sensitive questions might the compiler ask?

    • Is x scalar, an array, or a function?
    • Is x declared before it is used?
    • Are any names declared but not used?
    • Which declaration of x is being referenced?
    • Is an expression type-consistent?
    • Does the dimension of a reference match the declaration?
    • Where can x be stored? (heap, stack, ...)
    • Does *p reference the result of a malloc()?
    • Is x defined before it is used?
    • Is an array reference in bounds?
    • Does function foo produce a constant value?
    • Can p be implemented as a memo-function?

Context-sensitive analysis

  • Why is context-sensitive analysis hard?
    • answers depend on values, not syntax
    • questions and answers involve non-local information
    • answers may involve computation
  • Several alternatives:

Alternatives for semantic processing

  • one-pass: compiler and synthesis
  • two-pass: compiler + peephole
  • two-pass: compiler & IR synthesis + code generation pass
  • multi-pass analysis
  • multi-pass synthesis
  • language-independent and re-targetable compilers

Download 427.34 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling