Course 1
Course 1
Compiler Design
Simona Motogna
S. Motogna - LFTC
Compiler
Historical reasons
Formal Design
Languages
Be a better programmer
Performant algorithms
FLCD
S. Motogna - LFTC
Organization Issues
PRESENCE IS MANDATORY
S. Motogna - LFTC
Most interesting stuff for students
• Moodle:
• All course resources
• Homeworks
• Assignments
• Labs
• Points / grades
S. Motogna - LFTC
Minimal Conditions to Pass
Bonus
Lab work
• 10 laboratory tasks
• Weighted grades:
Lab grade
Bonus points:
- “awesome” solutions
- Extra work
I wish …
S. Motogna - LFTC
S. Motogna - LFTC
What is a compiler?
Interpreter?
S. Motogna - LFTC
S. Motogna - LFTC
A little bit of history …
Java
1995
C
Pascal J. Gosling
1969 - 1973
1968 - 1970 D. Ritchie
Lisp
N. Wirth
1962
Fortran McCarthy
1954-1957
Backus
S. Motogna - LFTC
Structure of a compiler Take
notes!
Source code/
analysis Error handling
Scanning (lexical
program analysis)
Parsing (syntactical
Tokens & ST analysis)
Intermediary code
Adnotated syntax generation synthesis
tree
Intermediary
Symbol Table Intermediary code optimization
management code
Object code /
Optimized Object code program
generation
intermediary code
S. Motogna - LFTC
Chapter 1. Scanning
Definition = treats the source program as a sequence of characters,
detect lexical tokens, classify and codify them
Algorithm Scanning v1
While (not(eof)) do
detect(token);
classify(token);
codify(token);
End_while
S. Motogna - LFTC
Take
Detect notes!
I am a student.I am
Simona
if (x==y) {x=y+2}
S. Motogna - LFTC
Classify
• Classes of tokens:
• Identifiers
• Constants
• Reserved words (keywords)
• Separators
• Operators
S. Motogna - LFTC
Codify
• May be codification table
OR
code for identifiers and constants
identifier, constant
S. Motogna - LFTC
Algorithm Scanning v2
While (not(eof)) do
detect(token);
if token is reserved word OR operator OR separator
then genPIF(token, 0)
else a=a+b
endif ST
1 a
endif 2 b
endwhile
S. Motogna - LFTC
Remarks:
• genPIF = adds a pair (token, position) to PIF
S. Motogna - LFTC
Example (sem?)
• https://babeljs.io/docs/en/
• https://www.antlr.org/ and https://github.com/antlr/antlr4
• https://www.programiz.com/python-programming/online-compiler/
• https://www.w3schools.com/python/python_compiler.asp
S. Motogna - LFTC