Professional Documents
Culture Documents
I Am Sharing 'CSC338 CS224 Chap01' With You 240130 081415
I Am Sharing 'CSC338 CS224 Chap01' With You 240130 081415
Goals:
- Compilers are used everyday in most computers.
Introduction
1. Terminology
3. Compiler structure
4. Example
4
Terminology
Translation operation
Source Code Compiler Object Code Linker Executable Code
Compiler structure
❑Compiler is divided into two parts: Front End
and Back End.
❑The Front End translates a program from
source language to an intermediate
language.
❑The back End translates from the
intermediate language to the machine
language.
Source Intermediate
Program code
Intermediate code
Lexical analyzer
generator
Tokens
Abstract
Syntax tree
Optimized
Intermediate
Optimized
code
Object code
Lexical analysis
❑ The lexical analyzer reads the input program
as a character stream and produces a stream
of lexemes (or token strings) as output.
❑The lexical analyzer reads the input program
character by character until it reads a word
(symbol).
❑The lexical analyzer searches the current
work in a table (called symbol table) and adds
it if not found. The lexical analyzer produces
an output for each symbol called token.
Tokens are generally integer numbers.
11
Syntactic Analysis
❑Syntactic Analyzer (or parser): takes as input
the Token stream produced by the lexical
analyzer.
Semantic Analysis
❑The semantic analyzer determines if the
meaning is respected in the user program.
❑The syntax rules may be respected without
respecting the meaning.
❑Semantic analysis is mainly to be sure that
data types are used properly.
❑Semantic analysis is part of syntactic
analysis.
13
if x > N Y -= 3 else Y += 3;
This is a syntax error
14
Intermediate code generation
Object Code
❑The target code is the machine code.
Miscellaneous
❑Symbol Table : contains all keywords and
symbols.
❑Symbol Table Handler: manages the symbol table.
❑Error Handling : gives a clear description of
errors.
19
Resume:
Source Program
Lexical analysis
Syntax analysis
code optimization
code generation
Target program