SlideShare a Scribd company logo
CS4200 Compiler Construction
Eelco Visser
TU Delft
September 2018
Lecture 1: What is a Compiler?
!1
Course Organization
2
!3
No use of electronic devices during lectures
!4
http://eelcovisser.org
!5
Brightspace: Announcements
!6
Course Website
!7
https://tudelft-cs4200-2018.github.io/
CS4200-A: Compiler Construction (5 ECTS)
- Study concepts and techniques

- Lectures 

- Papers

- Homework assignments: apply to small problems

- Assessment: exams in November and January

CS4200-B: Compiler Construction Project (5 ECTS)
- Build a compiler and programming environment for a subset of Java

- Assessment: code submitted for lab assignments
CS4200: Two Courses
!8
CS4200-A: Compiler Construction
Concepts and Techniques
9
!10
CS4200-A: Homework Assignments
!11
WebLab for Homework, Exams, Grade Registration
!12
https://weblab.tudelft.nl/cs4200/2018-2019/
Sign in to WebLab using “Single Sign On for TU Delft”
!13
Enroll for Course CS4200 in WebLab
!14
https://weblab.tudelft.nl/in4303/2017-2018/
Academic Misconduct
!15
DON’T!
CS4200-B: Compiler Construction Project
Building a compiler and IDE for MiniJava
16
Assignment text
!17
https://tudelft-cs4200-2018.github.io
!18
Lab on Friday afternoon
Assignment text
!19
Assignment text
!20
Spoofax Documentation
!21
http://www.metaborg.org
Private GitLab repository per student
- https://gitlab.ewi.tudelft.nl/CS4200-B/2018-2019/

Submit by Merge Request
Multiple submissions possible
Limited early feedback provided
Details online:
- https://tudelft-cs4200-2018.github.io/project/#submission
Assignment Submission
!22
Assignment deadlines
!23
To pass you need to meet all of these criteria:
- Each assignment grade >= 4

- Each milestone average >= 5

- Overall average >= 6
Project grades
!24
Project grades and registration
!25
https://weblab.tudelft.nl/cs4200/2018-2019/assignment/20207/info
Lab on Fridays. 13:45-17:45 DW-PC 2
Walk-in hours on Wednesdays. 9:30-11:00 E4.420 (Building 28)
Contact hours
!26
https://tudelft-cs4200-2018.github.io/team/
What is a Compiler?
27
Etymology
!28
Latin
Etymology
From con- (“with, together”) + pīlō (“ram down”).

Pronunciation
	•	(Classical) IPA(key): /komˈpiː.loː/, [kɔmˈpiː.ɫoː]

Verb
compīlō (present infinitive compīlāre, perfect active compīlāvī, supine
compīlātum); first conjugation

	1.	I snatch together and carry off; plunder, pillage, rob, steal.

https://en.wiktionary.org/wiki/compilo#Latin
Dictionary
!29
English
Verb
compile (third-person singular simple present compiles, present participle compiling, simple past and
past participle compiled)

	1.	 (transitive) To put together; to assemble; to make by gathering things from various sources. Samuel
Johnson compiled one of the most influential dictionaries of the English language.

	2.	 (obsolete) To construct, build. quotations 

	3.	 (transitive, programming) To use a compiler to process source code and produce executable code.
After I compile this program I'll run it and see if it works.

	4.	 (intransitive, programming) To be successfully processed by a compiler into executable code. There
must be an error in my source code because it won't compile.

	5.	 (obsolete, transitive) To contain or comprise. quotations 

	6.	 (obsolete) To write; to compose.
https://en.wiktionary.org/wiki/compile
Etymology
!30
The first compiler was written by Grace Hopper, in 1952, for the A-0
System language. The term compiler was coined by Hopper.[1][2] The A-0
functioned more as a loader or linker than the modern notion of a compiler.
https://en.wikipedia.org/wiki/History_of_compiler_construction
Compiling = Translating
!31
High-Level
Language
compiler
Low-Level
Language
A compiler translates high-level programs to low-level programs
Compiling = Translating
!32
C gcc X86
GCC translates C programs to object code for X86 (and other architectures)
Compiling = Translating
!33
Java javac
JVM
bytecode
A Java compiler translates Java programs to bytecode instructions for Java Virtual Machine
Architecture: Multi-Pass Compiler
!34
Java Type Check
JVM
bytecode
A modern compiler typically consists of sequence of stages or passes
Parse CodeGenOptimize
Intermediate Representations
!35
Java Type Check
JVM
bytecode
A compiler is a composition of a series of translations between intermediate languages
Parse CodeGenOptimize
Abstract
Syntax
Tree
Annotated
AST
Transformed
AST
Compiler Components
!36
Java Type Check
JVM
bytecode
Parse CodeGenOptimize
Abstract
Syntax
Tree
Annotated
AST
Transformed
AST
Parser
•Reads in program text

•Checks that it complies with the syntactic rules of the language

•Produces an abstract syntax tree

•Represents the underlying (syntactic) structure of the program.
Compiler Components
!37
Java Type Check
JVM
bytecode
Parse CodeGenOptimize
Abstract
Syntax
Tree
Annotated
AST
Transformed
AST
Type checker
•Consumes an abstract syntax tree

•Checks that the program complies with the static semantic rules of the language

•Performs name analysis, relating uses of names to declarations of names

•Checks that the types of arguments of operations are consistent with their specification
Compiler Components
!38
Java Type Check
JVM
bytecode
Parse CodeGenOptimize
Abstract
Syntax
Tree
Annotated
AST
Transformed
AST
Optimizer
•Consumes a (typed) abstract syntax tree

•Applies transformations that improve the program in various dimensions 

‣ execution time

‣ memory consumption

‣ energy consumption.
Compiler Components
!39
Java Type Check
JVM
bytecode
Parse CodeGenOptimize
Abstract
Syntax
Tree
Annotated
AST
Transformed
AST
Code generator
•Transforms abstract syntax tree to instructions for a particular computer architecture

•aka instruction selection

Register allocator
•Assigns physical registers to symbolic registers in the generated instructions
Back-EndFront-End
Compiler = Front-end + Back-End
!40
Java Type Check
JVM
bytecode
A compiler can typically be divided in a front-end (analysis) and a back-end (synthesis)
Parse CodeGenOptimize
Annotated
AST
Back-EndFront-End
Compiler = Front-end + Back-End
!41
C Type Check X86Parse CodeGenOptimizeLLVM
A compiler can typically be divided in a front-end (analysis) and a back-end (synthesis)
Back-End
Front-End
Repurposing Back-End
!42
C Type Check
X86
Repurposing: reuse a back-end for a different source language
Parse
CodeGenOptimizeLLVM
Front-End
C++ Type CheckParse
Back-EndFront-End
Retargeting Compiler
!43
C Type Check X86
Retargeting: compile to different hardware architecture
Parse CodeGenOptimize
LLVM
Back-End
ArmCodeGenOptimize
Front-End
C++ Type CheckParse
What is a Compiler?
!44
Java Type Check
JVM
bytecode
Parse CodeGenOptimize
Compiler Construction = Building Variants of Java?
A bunch of components for translating programs
Compiler
- translates high-level programs to machine code for a computer

Bytecode compiler
- generates code for a virtual machine

Just-in-time compiler
- defers (some aspects of) compilation to run time

Source-to-source compiler (transpiler)
- translate between high-level languages

Cross-compiler
- runs on different architecture than target architecture
Types of Compilers (1)
!45
Interpreter
- directly executes a program (although prior to execution program is
typically transformed)

Hardware compiler
- generate configuration for FPGA or integrated circuit

De-compiler
- translates from low-level language to high-level language
Types of Compilers (2)
!46
Why Compilers?
47
- fetch data from memory

- store data in register

- perform basic operation on data in register

- fetch instruction from memory

- update the program counter

- etc.
Programming = Instructing Computer
!48
!49
"Computational thinking is the thought processes
involved in formulating a problem and expressing its
solution(s) in such a way that a computer—human or
machine—can effectively carry out."
Jeanette M. Wing. Computational Thinking Benefits Society. 

In Social Issues in Computing. January 10, 2014. 

http://socialissues.cs.toronto.edu/index.html
!50
Problem
Domain
Solution
Domain
Programming is expressing intent
!51
Intermediate
Language
linguistic abstraction | liNGˈgwistik abˈstrakSHən |
noun
1. a programming language construct that captures a programming design pattern
the linguistic abstraction saved a lot of programming effort
he introduced a linguistic abstraction for page navigation in web programming
2. the process of introducing linguistic abstractions
linguistic abstraction for name binding removed the algorithmic encoding of name resolution
Problem
Domain
Solution
Domain
From Instructions to Expressions
!52
mov &a, &c
add &b, &c
mov &a, &t1
sub &b, &t1
and &t1,&c
Source: http://sites.google.com/site/arch1utep/home/course_outline/translating-complex-expressions-into-assembly-language-using-expression-trees
c = a
c += b
t1 = a
t1 -= b
c &= t1
c = (a + b) & (a - b)
From Calling Conventions to Procedures
!53
f(e1)
calc:
push eBP ; save old frame pointer
mov eBP,eSP ; get new frame pointer
sub eSP,localsize ; reserve place for locals
.
. ; perform calculations, leave result in AX
.
mov eSP,eBP ; free space for locals
pop eBP ; restore old frame pointer
ret paramsize ; free parameter space and return
push eAX ; pass some register result
push byte[eBP+20] ; pass some memory variable (FASM/TASM syntax)
push 3 ; pass some constant
call calc ; the returned result is now in eAX
def f(x)={ ... }
http://en.wikipedia.org/wiki/Calling_convention
function definition and call in Scala
From Malloc to Garbage Collection
!54
/* Allocate space for an array with ten elements of type int. */
int *ptr = (int*)malloc(10 * sizeof (int));
if (ptr == NULL) {
/* Memory could not be allocated, the program
should handle the error here as appropriate. */
} else {
/* Allocation succeeded. Do something. */
free(ptr); /* We are done with the int objects,
and free the associated pointer. */
ptr = NULL; /* The pointer must not be used again,
unless re-assigned to using malloc again. */
}
http://en.wikipedia.org/wiki/Malloc
int [] = new int[10];
/* use it; gc will clean up (hopefully) */
Linguistic Abstraction
!55
identify pattern
use new abstraction
language A language B
design abstraction
Compiler Automates Work of Programmer
!56
Problem
Domain
Solution
Domain
General-
Purpose
Language
CompilerProgrammer
Compilers for modern high-level languages

- Reduce the gap between problem domain and program

- Support programming in terms of computational
concepts instead of machine concepts

- Abstract from hardware architecture (portability)

- Protect against a range of common programming errors
Domain-Specific Languages
57
- Systems programming

- Embedded software

- Web programming

- Enterprise software

- Database programming

- Distributed programming

- Data analytics

- ...
Domains of Computation
!58
Problem
Domain
Solution
Domain
General-
Purpose
Language
!59
Problem
Domain
Solution
Domain
General-
Purpose
Language
“A programming language is low level when its
programs require attention to the irrelevant”
Alan J. Perlis. Epigrams on Programming.
SIGPLAN Notices, 17(9):7-13, 1982.
!60
Solution
Domain
Problem
Domain
Domain-specific language (DSL)
noun
1. a programming language that provides notation, analysis,
verification, and optimization specialized to an application
domain
2. result of linguistic abstraction beyond general-purpose
computation
General-
Purpose
Language
Domain-
Specific
Language
Domain Analysis
- What are the features of the domain?

Language Design
- What are adequate linguistic abstractions?

- Coverage: can language express everything in the domain?

‣ often the domain is unbounded; language design is making choice what to cover

- Minimality: but not more

‣ allowing too much interferes with multi-purpose goal

Semantics
- What is the semantics of such definitions?

- How can we verify the correctness / consistency of language definitions?

Implementation
- How do we derive efficient language implementations from such definitions?

Evaluation
- Apply to new and existing languages to determine adequacy
Language Design Methodology
!61
!62
Solution
Domain
Problem
Domain
General-
Purpose
Language
Domain-
Specific
Language
!63
Solution
Domain
Problem
Domain
General-
Purpose
Language
Domain-
Specific
Language
Making programming languages
is probably very expensive?
!64
General-
Purpose
Language
Making programming languages
is probably very expensive?
Solution
Domain
Problem
Domain
General-
Purpose
Language
Domain-
Specific
Language
Language
Design
Compiler +
Editor (IDE)
!65
Compiler +
Editor (IDE)
Meta-Linguistic Abstraction
Language
Design
General-
Purpose
Language
Declarative
Meta
Languages
Solution
Domain
Problem
Domain
General-
Purpose
Language
Domain-
Specific
Language
Language
Design
Applying compiler construction to the domain of compiler construction
!66
Compiler +
Editor (IDE)
Language
Design
General-
Purpose
Language
Declarative
Meta
Languages
Solution
Domain
Problem
Domain
General-
Purpose
Language
Language
Design
That also applies to the definition of (compilers for) general purpose languages
!67
Compiler +
Editor (IDE)
Language
Design
Declarative
Meta
Languages
!68
Language Workbench
Language Design
Syntax
Definition
Static
Semantics
Dynamic
Semantics
Transforms
Meta-DSLs
Compiler +
Editor (IDE)
!69
A Language Designer’s Workbench
Language Design
SDF3 Stratego
Consistency
Proof
NaBL2 DynSem
Responsive
Editor (IDE)
Tests
Incremental
Compiler
Syntax
Definition
Static
Semantics
Dynamic
Semantics
Transforms
Objective
- A workbench supporting design and implementation of programming languages

Approach
- Declarative multi-purpose domain-specific meta-languages

Meta-Languages
- Languages for defining languages

Domain-Specific
- Linguistic abstractions for domain of language definition (syntax, names, types, …)

Multi-Purpose
- Derivation of interpreters, compilers, rich editors, documentation, and verification from single
source

Declarative
- Focus on what not how; avoid bias to particular purpose in language definition
Declarative Language Definition
!70
Representation
- Standardized representation for <aspect> of programs

- Independent of specific object language

Specification Formalism
- Language-specific declarative rules

- Abstract from implementation concerns

Language-Independent Interpretation
- Formalism interpreted by language-independent algorithm

- Multiple interpretations for different purposes

- Reuse between implementations of different languages
Separation of Concerns
!71
SDF3: Syntax definition
- context-free grammars + disambiguation + constructors + templates

- derivation of parser, formatter, syntax highlighting, …

NaBL2: Names & Types
- name resolution with scope graphs

- type checking/inference with constraints

- derivation of name & type resolution algorithm

Stratego: Program Transformation
- term rewrite rules with programmable rewriting strategies

- derivation of program transformation system

FlowSpec: Data-Flow Analysis
- extraction of control-flow graph and specification of data-flow rules

- derivation of data-flow analysis engine

DynSem: Dynamic Semantics
- specification of operational (natural) semantics 

- derivation of interpreter
Meta-Languages in Spoofax Language Workbench
!72
The Spoofax Language Workbench
- Lennart C. L. Kats, Eelco Visser

- OOPSLA 2010 

A Language Designer's Workbench
- A one-stop-shop for implementation and verification of language designs 

- Eelco Visser, Guido Wachsmuth, Andrew P. Tolmach, Pierre Neron, Vlad A. Vergu, Augusto
Passalaqua, Gabriël D. P. Konat

- Onward 2014
Literature
!73
A Taste of Compiler
Construction
74
Language Definition in Spoofax Language Workbench
!75
SDF3: Syntax
Definition
NaBL2: Static
Semantics
DynSem: Dynamic
Semantics
Programming
Environment+ + Stratego: Program
Transformation+
Calc: A Little Calculator Language
!76
rY = 0.017; // yearly interest rate
Y = 30; // number of years
P = 379,000; // principal
N = Y * 12; // number of months
c = if(rY == 0) // no interest
P / N
else
let r = rY / 12 in
let f = (1 + r) ^ N in
(r * P * f) / (f - 1);
c; // payment per month
https://github.com/MetaBorgCube/metaborg-calc
http://www.metaborg.org/en/latest/source/langdev/meta/lang/tour/index.html
Calc: Syntax Definition
!77
context-free syntax // numbers
Exp = <(<Exp>)> {bracket}
Exp.Num = NUM
Exp.Min = <-<Exp>>
Exp.Pow = <<Exp> ^ <Exp>> {right}
Exp.Mul = <<Exp> * <Exp>> {left}
Exp.Div = <<Exp> / <Exp>> {left}
Exp.Sub = <<Exp> - <Exp>> {left, prefer}
Exp.Add = <<Exp> + <Exp>> {left}
Exp.Eq = <<Exp> == <Exp>> {non-assoc}
Exp.Neq = <<Exp> != <Exp>> {non-assoc}
Exp.Gt = [[Exp] > [Exp]] {non-assoc}
Exp.Lt = [[Exp] < [Exp]] {non-assoc}
context-free syntax // variables and functions
Exp.Var = ID
Exp.Let = <
let <ID> = <Exp> in
<Exp>
>
Exp.Fun = < <ID+> . <Exp>>
Exp.App = <<Exp> <Exp>> {left}
Calc: Type System
!78
rules // numbers
[[ Num(x) ^ (s) : NumT() ]].
[[ Pow(e1, e2) ^ (s) : NumT() ]] :=
[[ e1 ^ (s) : NumT() ]],
[[ e2 ^ (s) : NumT() ]].
[[ Mul(e1, e2) ^ (s) : NumT() ]] :=
[[ e1 ^ (s) : NumT() ]],
[[ e2 ^ (s) : NumT() ]].
[[ Add(e1, e2) ^ (s) : NumT() ]] :=
[[ e1 ^ (s) : NumT() ]],
[[ e2 ^ (s) : NumT() ]].
rules // variables and functions
[[ Var(x) ^ (s) : ty ]] :=
{x} -> s, {x} |-> d, d : ty.
[[ Let(x, e1, e2) ^ (s) : ty2 ]] :=
new s_let, {x} <- s_let, {x} : ty, s_let -P-> s,
[[ e1 ^ (s) : ty ]],
[[ e2 ^ (s_let) : ty2 ]].
[[ Fun([x], e) ^ (s) : FunT(ty1, ty2) ]] :=
new s_fun, {x} <- s_fun, {x} : ty1, s_fun -P-> s,
[[ e ^ (s_fun) : ty2 ]].
[[ App(e1, e2) ^ (s) : ty_res ]] :=
[[ e1 ^ (s) : ty_fun ]],
[[ e2 ^ (s) : ty_arg ]],
FunT(ty_arg, ty_res) instOf ty_fun.
Calc: Dynamic Semantics
!79
rules // numbers
Num(n) --> NumV(parseB(n))
Pow(NumV(i), NumV(j)) --> NumV(powB(i, j))
Mul(NumV(i), NumV(j)) --> NumV(mulB(i, j))
Div(NumV(i), NumV(j)) --> NumV(divB(i, j))
Sub(NumV(i), NumV(j)) --> NumV(subB(i, j))
Add(NumV(i), NumV(j)) --> NumV(addB(i, j))
Lt(NumV(i), NumV(j)) --> BoolV(ltB(i, j))
Eq(NumV(i), NumV(j)) --> BoolV(eqB(i, j))
rules // variables and functions
E |- Var(x) --> E[x]
E |- Fun([x], e) --> ClosV(x, e, E)
E |- Let(x, v1, e2) --> v
where E {x |--> v1, E} |- e2 --> v
App(ClosV(x, e, E), v_arg) --> v
where E {x |--> v_arg, E} |- e --> v
Calc: Code Generation
!80
rules // numbers
exp-to-java : Num(v) -> $[BigDecimal.valueOf([v])]
exp-to-java :
Add(e1, e2) -> $[[je1].add([je2])]
with
<exp-to-java> e1 => je1
; <exp-to-java> e2 => je2
exp-to-java :
Sub(e1, e2) -> $[[je1].subtract([je2])]
with
<exp-to-java> e1 => je1
; <exp-to-java> e2 => je2
rules // variables and functions
exp-to-java : Var(x) -> $[[x]]
exp-to-java :
Let(x, e1, e2) -> $[(([jty]) [x] -> [je2]).apply([je1])]
with
<nabl2-get-ast-type> e1 => ty1
; <nabl2-get-ast-type> e2 => ty2
; <type-to-java> FunT(ty1, ty2) => jty
; <exp-to-java> e1 => je1
; <exp-to-java> e2 => je2
exp-to-java :
f@Fun([x], e) -> $[(([jty]) [x] -> [je])]
with
<nabl2-get-ast-type> f => ty
; <type-to-java> ty => jty
; <exp-to-java> e => je
exp-to-java:
App(e1, e2) -> $[[e1].apply([e2])]
with
<exp-to-java> e1 => je1
; <exp-to-java> e2 => je2
Lecture Language: Tiger
!81
https://github.com/MetaBorgCube/metaborg-tiger
Studying Compiler
Construction
82
The Basis
!83
Java Type Check
JVM
bytecode
Parse CodeGenOptimize
!84
Compiler construction techniques
are applicable in a wide range of
software (development) applications
Specific
• Understanding a specific compiler

• Understanding a programming language (MiniJava)

• Understanding a target machine (Java Virtual Machine)

• Understanding a compilation scheme (MiniJava to Byte Code)

Architecture
• Understanding architecture of compilers

• Understanding (concepts of) programming languages

• Understanding compilation techniques

Domains
• Understanding (principles of) syntax definition and parsing

• Understanding (principles of) static semantics and type checking

• Understanding (principles of) dynamic semantics and interpretation/code generation

Meta
• Understanding meta-languages and their compilation
Levels of Understanding Compilers
!85
Syntax
• concrete syntax, abstract syntax

• context-free grammars

• derivations, ambiguity, disambiguation,
associativity, priority

• parsing, parse trees, abstract syntax trees,
terms

• pretty-printing

• parser generation

• syntactic editor services

Transformation
• rewrite rules, rewrite strategies

• simplification, desugaring
Course Topics
!86
Statics
• static semantics and type checking

‣ name binding, name resolution, scope graphs

‣ types, type checking, type inference, subtyping

‣ unification, constraints

• semantic editor services

• Data-flow analysis

‣ control-flow, data-flow

‣ monotone frameworks, worklist algorithm

Dynamics
• dynamic semantics and interpreters

• operational semantics, program execution

• virtual machines, assembly code, byte code

• code generation

• memory management, garbage collection
Q1
• What is a compiler? (Introduction)

• Syntax Definition

• Basic Parsing

• Syntactic Editor Services

• Transformation

• Static Semantics & Name Resolution

• Type Constraints

• Constraint Resolution

• More Constraint Resolution
Lectures (Tentative)
!87
Lectures: Tuesday, 17:45 in
Lecture Hall Boole at EWI
Lectures: Tuesday, 10:45 in
Lecture Hall CT-CZ D
Q2
• Data-Flow Analysis

• Virtual Machines & Code Generation

• Optimization

• Garbage Collection

• Dynamic Semantics & Interpreters

• Applications

• Reserve

• Overview
Homework Assignments
88
This award winning paper describes the design of the
Spoofax Language Workbench.
It provides an alternative architecture for
programming languages tooling from the compiler
pipeline discussed in this lecture.
Read the paper and make the homework assignments on
WebLab.
Note that the details of some of the technologies in
Spoofax have changed since the publication. The
https://doi.org/10.1145/1932682.1869497
Assignment
Read this paper in preparation for Lecture 2
http://swerl.tudelft.nl/twiki/pub/Main/TechnicalReports/TUD-SERG-2010-019.pdf
https://doi.org/10.1145/1932682.1869535
Next Lecture
91
Next: Syntax Definition
!92
Lecture: Friday, 13:45 in
Lecture Hall Chip at EWI
Java Type Check
JVM
bytecode
Parse CodeGenOptimize
Specification of syntax definition from which we can derive parsers
Ad

More Related Content

What's hot (20)

Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
Compiler Design Unit 4
Compiler Design Unit 4Compiler Design Unit 4
Compiler Design Unit 4
Jena Catherine Bel D
 
Target language in compiler design
Target language in compiler designTarget language in compiler design
Target language in compiler design
Muhammad Haroon
 
Parsing
ParsingParsing
Parsing
khush_boo31
 
3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl
Sampath Kumar S
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
Kuppusamy P
 
Intro automata theory
Intro automata theory Intro automata theory
Intro automata theory
Rajendran
 
Language processing activity
Language processing activityLanguage processing activity
Language processing activity
Dhruv Sabalpara
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
Mir Majid
 
Language for specifying lexical Analyzer
Language for specifying lexical AnalyzerLanguage for specifying lexical Analyzer
Language for specifying lexical Analyzer
Archana Gopinath
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
Anusuya123
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
Kuppusamy P
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
Akshaya Arunan
 
Lex
LexLex
Lex
BBDITM LUCKNOW
 
Semantics analysis
Semantics analysisSemantics analysis
Semantics analysis
Bilalzafar22
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
Kuppusamy P
 
Structure of the compiler
Structure of the compilerStructure of the compiler
Structure of the compiler
Sudhaa Ravi
 
System programming note
System programming noteSystem programming note
System programming note
SANTOSH RATH
 
compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
nadarmispapaulraj
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
Richa Sharma
 
Target language in compiler design
Target language in compiler designTarget language in compiler design
Target language in compiler design
Muhammad Haroon
 
3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl
Sampath Kumar S
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
Kuppusamy P
 
Intro automata theory
Intro automata theory Intro automata theory
Intro automata theory
Rajendran
 
Language processing activity
Language processing activityLanguage processing activity
Language processing activity
Dhruv Sabalpara
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
Mir Majid
 
Language for specifying lexical Analyzer
Language for specifying lexical AnalyzerLanguage for specifying lexical Analyzer
Language for specifying lexical Analyzer
Archana Gopinath
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
Anusuya123
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
Kuppusamy P
 
Semantics analysis
Semantics analysisSemantics analysis
Semantics analysis
Bilalzafar22
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
Kuppusamy P
 
Structure of the compiler
Structure of the compilerStructure of the compiler
Structure of the compiler
Sudhaa Ravi
 
System programming note
System programming noteSystem programming note
System programming note
SANTOSH RATH
 
compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
nadarmispapaulraj
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
Richa Sharma
 

Similar to Compiler Construction | Lecture 1 | What is a compiler? (20)

CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
Eelco Visser
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
Eelco Visser
 
First session quiz
First session quizFirst session quiz
First session quiz
Keroles karam khalil
 
First session quiz
First session quizFirst session quiz
First session quiz
Keroles karam khalil
 
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
corehard_by
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
Rebaz Najeeb
 
Embedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals master
Hossam Hassan
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
Stalongiles Philip
 
Ch1
Ch1Ch1
Ch1
kinnarshah8888
 
C intro
C introC intro
C intro
Mohit Patodia
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptx
ZiyadMohammed17
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introduction
mengistu23
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptx
AshenafiGirma5
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
Mpho Mphego
 
Chapter1.pdf
Chapter1.pdfChapter1.pdf
Chapter1.pdf
tharwatabdulhmed
 
CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733...
CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733...CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733...
CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733...
DrmagedAlazony
 
LANGUAGE TRANSLATOR
LANGUAGE TRANSLATORLANGUAGE TRANSLATOR
LANGUAGE TRANSLATOR
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
Amin Mesbahi
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
Keroles karam khalil
 
Ch1_4.ppt
Ch1_4.pptCh1_4.ppt
Ch1_4.ppt
jeronimored
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
Eelco Visser
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
Eelco Visser
 
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
corehard_by
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
Rebaz Najeeb
 
Embedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals master
Hossam Hassan
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptx
ZiyadMohammed17
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introduction
mengistu23
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptx
AshenafiGirma5
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
Mpho Mphego
 
CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733...
CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733...CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733...
CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733...
DrmagedAlazony
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
Amin Mesbahi
 
Ad

More from Eelco Visser (20)

CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
Eelco Visser
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
Eelco Visser
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
Eelco Visser
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
Eelco Visser
 
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation Rules
Eelco Visser
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
Eelco Visser
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Eelco Visser
 
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Eelco Visser
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory Management
Eelco Visser
 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | Interpreters
Eelco Visser
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
Eelco Visser
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
Eelco Visser
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
Eelco Visser
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
Eelco Visser
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
Eelco Visser
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type Constraints
Eelco Visser
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
Eelco Visser
 
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Eelco Visser
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Eelco Visser
 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
Eelco Visser
 
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
Eelco Visser
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
Eelco Visser
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
Eelco Visser
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
Eelco Visser
 
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation Rules
Eelco Visser
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
Eelco Visser
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Eelco Visser
 
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Eelco Visser
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory Management
Eelco Visser
 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | Interpreters
Eelco Visser
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
Eelco Visser
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
Eelco Visser
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
Eelco Visser
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
Eelco Visser
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
Eelco Visser
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type Constraints
Eelco Visser
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
Eelco Visser
 
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Eelco Visser
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Eelco Visser
 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
Eelco Visser
 
Ad

Recently uploaded (20)

Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 

Compiler Construction | Lecture 1 | What is a compiler?

  • 1. CS4200 Compiler Construction Eelco Visser TU Delft September 2018 Lecture 1: What is a Compiler? !1
  • 3. !3 No use of electronic devices during lectures
  • 5. !5
  • 8. CS4200-A: Compiler Construction (5 ECTS) - Study concepts and techniques - Lectures - Papers - Homework assignments: apply to small problems - Assessment: exams in November and January CS4200-B: Compiler Construction Project (5 ECTS) - Build a compiler and programming environment for a subset of Java - Assessment: code submitted for lab assignments CS4200: Two Courses !8
  • 10. !10
  • 12. WebLab for Homework, Exams, Grade Registration !12 https://weblab.tudelft.nl/cs4200/2018-2019/
  • 13. Sign in to WebLab using “Single Sign On for TU Delft” !13
  • 14. Enroll for Course CS4200 in WebLab !14 https://weblab.tudelft.nl/in4303/2017-2018/
  • 16. CS4200-B: Compiler Construction Project Building a compiler and IDE for MiniJava 16
  • 18. !18 Lab on Friday afternoon
  • 22. Private GitLab repository per student - https://gitlab.ewi.tudelft.nl/CS4200-B/2018-2019/ Submit by Merge Request Multiple submissions possible Limited early feedback provided Details online: - https://tudelft-cs4200-2018.github.io/project/#submission Assignment Submission !22
  • 24. To pass you need to meet all of these criteria: - Each assignment grade >= 4 - Each milestone average >= 5 - Overall average >= 6 Project grades !24
  • 25. Project grades and registration !25 https://weblab.tudelft.nl/cs4200/2018-2019/assignment/20207/info
  • 26. Lab on Fridays. 13:45-17:45 DW-PC 2 Walk-in hours on Wednesdays. 9:30-11:00 E4.420 (Building 28) Contact hours !26 https://tudelft-cs4200-2018.github.io/team/
  • 27. What is a Compiler? 27
  • 28. Etymology !28 Latin Etymology From con- (“with, together”) + pīlō (“ram down”). Pronunciation • (Classical) IPA(key): /komˈpiː.loː/, [kɔmˈpiː.ɫoː] Verb compīlō (present infinitive compīlāre, perfect active compīlāvī, supine compīlātum); first conjugation 1. I snatch together and carry off; plunder, pillage, rob, steal. https://en.wiktionary.org/wiki/compilo#Latin
  • 29. Dictionary !29 English Verb compile (third-person singular simple present compiles, present participle compiling, simple past and past participle compiled) 1. (transitive) To put together; to assemble; to make by gathering things from various sources. Samuel Johnson compiled one of the most influential dictionaries of the English language. 2. (obsolete) To construct, build. quotations 3. (transitive, programming) To use a compiler to process source code and produce executable code. After I compile this program I'll run it and see if it works. 4. (intransitive, programming) To be successfully processed by a compiler into executable code. There must be an error in my source code because it won't compile. 5. (obsolete, transitive) To contain or comprise. quotations 6. (obsolete) To write; to compose. https://en.wiktionary.org/wiki/compile
  • 30. Etymology !30 The first compiler was written by Grace Hopper, in 1952, for the A-0 System language. The term compiler was coined by Hopper.[1][2] The A-0 functioned more as a loader or linker than the modern notion of a compiler. https://en.wikipedia.org/wiki/History_of_compiler_construction
  • 31. Compiling = Translating !31 High-Level Language compiler Low-Level Language A compiler translates high-level programs to low-level programs
  • 32. Compiling = Translating !32 C gcc X86 GCC translates C programs to object code for X86 (and other architectures)
  • 33. Compiling = Translating !33 Java javac JVM bytecode A Java compiler translates Java programs to bytecode instructions for Java Virtual Machine
  • 34. Architecture: Multi-Pass Compiler !34 Java Type Check JVM bytecode A modern compiler typically consists of sequence of stages or passes Parse CodeGenOptimize
  • 35. Intermediate Representations !35 Java Type Check JVM bytecode A compiler is a composition of a series of translations between intermediate languages Parse CodeGenOptimize Abstract Syntax Tree Annotated AST Transformed AST
  • 36. Compiler Components !36 Java Type Check JVM bytecode Parse CodeGenOptimize Abstract Syntax Tree Annotated AST Transformed AST Parser •Reads in program text •Checks that it complies with the syntactic rules of the language •Produces an abstract syntax tree •Represents the underlying (syntactic) structure of the program.
  • 37. Compiler Components !37 Java Type Check JVM bytecode Parse CodeGenOptimize Abstract Syntax Tree Annotated AST Transformed AST Type checker •Consumes an abstract syntax tree •Checks that the program complies with the static semantic rules of the language •Performs name analysis, relating uses of names to declarations of names •Checks that the types of arguments of operations are consistent with their specification
  • 38. Compiler Components !38 Java Type Check JVM bytecode Parse CodeGenOptimize Abstract Syntax Tree Annotated AST Transformed AST Optimizer •Consumes a (typed) abstract syntax tree •Applies transformations that improve the program in various dimensions ‣ execution time ‣ memory consumption ‣ energy consumption.
  • 39. Compiler Components !39 Java Type Check JVM bytecode Parse CodeGenOptimize Abstract Syntax Tree Annotated AST Transformed AST Code generator •Transforms abstract syntax tree to instructions for a particular computer architecture •aka instruction selection Register allocator •Assigns physical registers to symbolic registers in the generated instructions
  • 40. Back-EndFront-End Compiler = Front-end + Back-End !40 Java Type Check JVM bytecode A compiler can typically be divided in a front-end (analysis) and a back-end (synthesis) Parse CodeGenOptimize Annotated AST
  • 41. Back-EndFront-End Compiler = Front-end + Back-End !41 C Type Check X86Parse CodeGenOptimizeLLVM A compiler can typically be divided in a front-end (analysis) and a back-end (synthesis)
  • 42. Back-End Front-End Repurposing Back-End !42 C Type Check X86 Repurposing: reuse a back-end for a different source language Parse CodeGenOptimizeLLVM Front-End C++ Type CheckParse
  • 43. Back-EndFront-End Retargeting Compiler !43 C Type Check X86 Retargeting: compile to different hardware architecture Parse CodeGenOptimize LLVM Back-End ArmCodeGenOptimize Front-End C++ Type CheckParse
  • 44. What is a Compiler? !44 Java Type Check JVM bytecode Parse CodeGenOptimize Compiler Construction = Building Variants of Java? A bunch of components for translating programs
  • 45. Compiler - translates high-level programs to machine code for a computer Bytecode compiler - generates code for a virtual machine Just-in-time compiler - defers (some aspects of) compilation to run time Source-to-source compiler (transpiler) - translate between high-level languages Cross-compiler - runs on different architecture than target architecture Types of Compilers (1) !45
  • 46. Interpreter - directly executes a program (although prior to execution program is typically transformed) Hardware compiler - generate configuration for FPGA or integrated circuit De-compiler - translates from low-level language to high-level language Types of Compilers (2) !46
  • 48. - fetch data from memory - store data in register - perform basic operation on data in register - fetch instruction from memory - update the program counter - etc. Programming = Instructing Computer !48
  • 49. !49 "Computational thinking is the thought processes involved in formulating a problem and expressing its solution(s) in such a way that a computer—human or machine—can effectively carry out." Jeanette M. Wing. Computational Thinking Benefits Society. In Social Issues in Computing. January 10, 2014. http://socialissues.cs.toronto.edu/index.html
  • 51. !51 Intermediate Language linguistic abstraction | liNGˈgwistik abˈstrakSHən | noun 1. a programming language construct that captures a programming design pattern the linguistic abstraction saved a lot of programming effort he introduced a linguistic abstraction for page navigation in web programming 2. the process of introducing linguistic abstractions linguistic abstraction for name binding removed the algorithmic encoding of name resolution Problem Domain Solution Domain
  • 52. From Instructions to Expressions !52 mov &a, &c add &b, &c mov &a, &t1 sub &b, &t1 and &t1,&c Source: http://sites.google.com/site/arch1utep/home/course_outline/translating-complex-expressions-into-assembly-language-using-expression-trees c = a c += b t1 = a t1 -= b c &= t1 c = (a + b) & (a - b)
  • 53. From Calling Conventions to Procedures !53 f(e1) calc: push eBP ; save old frame pointer mov eBP,eSP ; get new frame pointer sub eSP,localsize ; reserve place for locals . . ; perform calculations, leave result in AX . mov eSP,eBP ; free space for locals pop eBP ; restore old frame pointer ret paramsize ; free parameter space and return push eAX ; pass some register result push byte[eBP+20] ; pass some memory variable (FASM/TASM syntax) push 3 ; pass some constant call calc ; the returned result is now in eAX def f(x)={ ... } http://en.wikipedia.org/wiki/Calling_convention function definition and call in Scala
  • 54. From Malloc to Garbage Collection !54 /* Allocate space for an array with ten elements of type int. */ int *ptr = (int*)malloc(10 * sizeof (int)); if (ptr == NULL) { /* Memory could not be allocated, the program should handle the error here as appropriate. */ } else { /* Allocation succeeded. Do something. */ free(ptr); /* We are done with the int objects, and free the associated pointer. */ ptr = NULL; /* The pointer must not be used again, unless re-assigned to using malloc again. */ } http://en.wikipedia.org/wiki/Malloc int [] = new int[10]; /* use it; gc will clean up (hopefully) */
  • 55. Linguistic Abstraction !55 identify pattern use new abstraction language A language B design abstraction
  • 56. Compiler Automates Work of Programmer !56 Problem Domain Solution Domain General- Purpose Language CompilerProgrammer Compilers for modern high-level languages - Reduce the gap between problem domain and program - Support programming in terms of computational concepts instead of machine concepts - Abstract from hardware architecture (portability) - Protect against a range of common programming errors
  • 58. - Systems programming - Embedded software - Web programming - Enterprise software - Database programming - Distributed programming - Data analytics - ... Domains of Computation !58 Problem Domain Solution Domain General- Purpose Language
  • 59. !59 Problem Domain Solution Domain General- Purpose Language “A programming language is low level when its programs require attention to the irrelevant” Alan J. Perlis. Epigrams on Programming. SIGPLAN Notices, 17(9):7-13, 1982.
  • 60. !60 Solution Domain Problem Domain Domain-specific language (DSL) noun 1. a programming language that provides notation, analysis, verification, and optimization specialized to an application domain 2. result of linguistic abstraction beyond general-purpose computation General- Purpose Language Domain- Specific Language
  • 61. Domain Analysis - What are the features of the domain? Language Design - What are adequate linguistic abstractions? - Coverage: can language express everything in the domain? ‣ often the domain is unbounded; language design is making choice what to cover - Minimality: but not more ‣ allowing too much interferes with multi-purpose goal Semantics - What is the semantics of such definitions? - How can we verify the correctness / consistency of language definitions? Implementation - How do we derive efficient language implementations from such definitions? Evaluation - Apply to new and existing languages to determine adequacy Language Design Methodology !61
  • 64. !64 General- Purpose Language Making programming languages is probably very expensive? Solution Domain Problem Domain General- Purpose Language Domain- Specific Language Language Design Compiler + Editor (IDE)
  • 65. !65 Compiler + Editor (IDE) Meta-Linguistic Abstraction Language Design General- Purpose Language Declarative Meta Languages Solution Domain Problem Domain General- Purpose Language Domain- Specific Language Language Design Applying compiler construction to the domain of compiler construction
  • 69. !69 A Language Designer’s Workbench Language Design SDF3 Stratego Consistency Proof NaBL2 DynSem Responsive Editor (IDE) Tests Incremental Compiler Syntax Definition Static Semantics Dynamic Semantics Transforms
  • 70. Objective - A workbench supporting design and implementation of programming languages Approach - Declarative multi-purpose domain-specific meta-languages Meta-Languages - Languages for defining languages Domain-Specific - Linguistic abstractions for domain of language definition (syntax, names, types, …) Multi-Purpose - Derivation of interpreters, compilers, rich editors, documentation, and verification from single source Declarative - Focus on what not how; avoid bias to particular purpose in language definition Declarative Language Definition !70
  • 71. Representation - Standardized representation for <aspect> of programs - Independent of specific object language Specification Formalism - Language-specific declarative rules - Abstract from implementation concerns Language-Independent Interpretation - Formalism interpreted by language-independent algorithm - Multiple interpretations for different purposes - Reuse between implementations of different languages Separation of Concerns !71
  • 72. SDF3: Syntax definition - context-free grammars + disambiguation + constructors + templates - derivation of parser, formatter, syntax highlighting, … NaBL2: Names & Types - name resolution with scope graphs - type checking/inference with constraints - derivation of name & type resolution algorithm Stratego: Program Transformation - term rewrite rules with programmable rewriting strategies - derivation of program transformation system FlowSpec: Data-Flow Analysis - extraction of control-flow graph and specification of data-flow rules - derivation of data-flow analysis engine DynSem: Dynamic Semantics - specification of operational (natural) semantics - derivation of interpreter Meta-Languages in Spoofax Language Workbench !72
  • 73. The Spoofax Language Workbench - Lennart C. L. Kats, Eelco Visser - OOPSLA 2010 A Language Designer's Workbench - A one-stop-shop for implementation and verification of language designs - Eelco Visser, Guido Wachsmuth, Andrew P. Tolmach, Pierre Neron, Vlad A. Vergu, Augusto Passalaqua, Gabriël D. P. Konat - Onward 2014 Literature !73
  • 74. A Taste of Compiler Construction 74
  • 75. Language Definition in Spoofax Language Workbench !75 SDF3: Syntax Definition NaBL2: Static Semantics DynSem: Dynamic Semantics Programming Environment+ + Stratego: Program Transformation+
  • 76. Calc: A Little Calculator Language !76 rY = 0.017; // yearly interest rate Y = 30; // number of years P = 379,000; // principal N = Y * 12; // number of months c = if(rY == 0) // no interest P / N else let r = rY / 12 in let f = (1 + r) ^ N in (r * P * f) / (f - 1); c; // payment per month https://github.com/MetaBorgCube/metaborg-calc http://www.metaborg.org/en/latest/source/langdev/meta/lang/tour/index.html
  • 77. Calc: Syntax Definition !77 context-free syntax // numbers Exp = <(<Exp>)> {bracket} Exp.Num = NUM Exp.Min = <-<Exp>> Exp.Pow = <<Exp> ^ <Exp>> {right} Exp.Mul = <<Exp> * <Exp>> {left} Exp.Div = <<Exp> / <Exp>> {left} Exp.Sub = <<Exp> - <Exp>> {left, prefer} Exp.Add = <<Exp> + <Exp>> {left} Exp.Eq = <<Exp> == <Exp>> {non-assoc} Exp.Neq = <<Exp> != <Exp>> {non-assoc} Exp.Gt = [[Exp] > [Exp]] {non-assoc} Exp.Lt = [[Exp] < [Exp]] {non-assoc} context-free syntax // variables and functions Exp.Var = ID Exp.Let = < let <ID> = <Exp> in <Exp> > Exp.Fun = < <ID+> . <Exp>> Exp.App = <<Exp> <Exp>> {left}
  • 78. Calc: Type System !78 rules // numbers [[ Num(x) ^ (s) : NumT() ]]. [[ Pow(e1, e2) ^ (s) : NumT() ]] := [[ e1 ^ (s) : NumT() ]], [[ e2 ^ (s) : NumT() ]]. [[ Mul(e1, e2) ^ (s) : NumT() ]] := [[ e1 ^ (s) : NumT() ]], [[ e2 ^ (s) : NumT() ]]. [[ Add(e1, e2) ^ (s) : NumT() ]] := [[ e1 ^ (s) : NumT() ]], [[ e2 ^ (s) : NumT() ]]. rules // variables and functions [[ Var(x) ^ (s) : ty ]] := {x} -> s, {x} |-> d, d : ty. [[ Let(x, e1, e2) ^ (s) : ty2 ]] := new s_let, {x} <- s_let, {x} : ty, s_let -P-> s, [[ e1 ^ (s) : ty ]], [[ e2 ^ (s_let) : ty2 ]]. [[ Fun([x], e) ^ (s) : FunT(ty1, ty2) ]] := new s_fun, {x} <- s_fun, {x} : ty1, s_fun -P-> s, [[ e ^ (s_fun) : ty2 ]]. [[ App(e1, e2) ^ (s) : ty_res ]] := [[ e1 ^ (s) : ty_fun ]], [[ e2 ^ (s) : ty_arg ]], FunT(ty_arg, ty_res) instOf ty_fun.
  • 79. Calc: Dynamic Semantics !79 rules // numbers Num(n) --> NumV(parseB(n)) Pow(NumV(i), NumV(j)) --> NumV(powB(i, j)) Mul(NumV(i), NumV(j)) --> NumV(mulB(i, j)) Div(NumV(i), NumV(j)) --> NumV(divB(i, j)) Sub(NumV(i), NumV(j)) --> NumV(subB(i, j)) Add(NumV(i), NumV(j)) --> NumV(addB(i, j)) Lt(NumV(i), NumV(j)) --> BoolV(ltB(i, j)) Eq(NumV(i), NumV(j)) --> BoolV(eqB(i, j)) rules // variables and functions E |- Var(x) --> E[x] E |- Fun([x], e) --> ClosV(x, e, E) E |- Let(x, v1, e2) --> v where E {x |--> v1, E} |- e2 --> v App(ClosV(x, e, E), v_arg) --> v where E {x |--> v_arg, E} |- e --> v
  • 80. Calc: Code Generation !80 rules // numbers exp-to-java : Num(v) -> $[BigDecimal.valueOf([v])] exp-to-java : Add(e1, e2) -> $[[je1].add([je2])] with <exp-to-java> e1 => je1 ; <exp-to-java> e2 => je2 exp-to-java : Sub(e1, e2) -> $[[je1].subtract([je2])] with <exp-to-java> e1 => je1 ; <exp-to-java> e2 => je2 rules // variables and functions exp-to-java : Var(x) -> $[[x]] exp-to-java : Let(x, e1, e2) -> $[(([jty]) [x] -> [je2]).apply([je1])] with <nabl2-get-ast-type> e1 => ty1 ; <nabl2-get-ast-type> e2 => ty2 ; <type-to-java> FunT(ty1, ty2) => jty ; <exp-to-java> e1 => je1 ; <exp-to-java> e2 => je2 exp-to-java : f@Fun([x], e) -> $[(([jty]) [x] -> [je])] with <nabl2-get-ast-type> f => ty ; <type-to-java> ty => jty ; <exp-to-java> e => je exp-to-java: App(e1, e2) -> $[[e1].apply([e2])] with <exp-to-java> e1 => je1 ; <exp-to-java> e2 => je2
  • 83. The Basis !83 Java Type Check JVM bytecode Parse CodeGenOptimize
  • 84. !84 Compiler construction techniques are applicable in a wide range of software (development) applications
  • 85. Specific • Understanding a specific compiler • Understanding a programming language (MiniJava) • Understanding a target machine (Java Virtual Machine) • Understanding a compilation scheme (MiniJava to Byte Code) Architecture • Understanding architecture of compilers • Understanding (concepts of) programming languages • Understanding compilation techniques Domains • Understanding (principles of) syntax definition and parsing • Understanding (principles of) static semantics and type checking • Understanding (principles of) dynamic semantics and interpretation/code generation Meta • Understanding meta-languages and their compilation Levels of Understanding Compilers !85
  • 86. Syntax • concrete syntax, abstract syntax • context-free grammars • derivations, ambiguity, disambiguation, associativity, priority • parsing, parse trees, abstract syntax trees, terms • pretty-printing • parser generation • syntactic editor services Transformation • rewrite rules, rewrite strategies • simplification, desugaring Course Topics !86 Statics • static semantics and type checking ‣ name binding, name resolution, scope graphs ‣ types, type checking, type inference, subtyping ‣ unification, constraints • semantic editor services • Data-flow analysis ‣ control-flow, data-flow ‣ monotone frameworks, worklist algorithm Dynamics • dynamic semantics and interpreters • operational semantics, program execution • virtual machines, assembly code, byte code • code generation • memory management, garbage collection
  • 87. Q1 • What is a compiler? (Introduction) • Syntax Definition • Basic Parsing • Syntactic Editor Services • Transformation • Static Semantics & Name Resolution • Type Constraints • Constraint Resolution • More Constraint Resolution Lectures (Tentative) !87 Lectures: Tuesday, 17:45 in Lecture Hall Boole at EWI Lectures: Tuesday, 10:45 in Lecture Hall CT-CZ D Q2 • Data-Flow Analysis • Virtual Machines & Code Generation • Optimization • Garbage Collection • Dynamic Semantics & Interpreters • Applications • Reserve • Overview
  • 89. This award winning paper describes the design of the Spoofax Language Workbench. It provides an alternative architecture for programming languages tooling from the compiler pipeline discussed in this lecture. Read the paper and make the homework assignments on WebLab. Note that the details of some of the technologies in Spoofax have changed since the publication. The https://doi.org/10.1145/1932682.1869497
  • 90. Assignment Read this paper in preparation for Lecture 2 http://swerl.tudelft.nl/twiki/pub/Main/TechnicalReports/TUD-SERG-2010-019.pdf https://doi.org/10.1145/1932682.1869535
  • 92. Next: Syntax Definition !92 Lecture: Friday, 13:45 in Lecture Hall Chip at EWI Java Type Check JVM bytecode Parse CodeGenOptimize Specification of syntax definition from which we can derive parsers