0% found this document useful (0 votes)
36 views19 pages

1 TheorieLangage Compilation

This document outlines the course organization for a compiler construction course. It will cover specification and instrumentation of textual languages, introduction to language theory, and introduction to FRAMA-C. Students will complete a project to build a programming language by specifying its grammar and implementing a compiler for it. The document provides an overview of programming languages and translators such as compilers and interpreters. It describes the roles of compiler components like lexical analyzers, syntactic analyzers, semantic analyzers, code generators, and symbol tables. Finally, it outlines the student's mission to build a compiler for a simplified algorithmic language using JavaCC.

Uploaded by

dgxtal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views19 pages

1 TheorieLangage Compilation

This document outlines the course organization for a compiler construction course. It will cover specification and instrumentation of textual languages, introduction to language theory, and introduction to FRAMA-C. Students will complete a project to build a programming language by specifying its grammar and implementing a compiler for it. The document provides an overview of programming languages and translators such as compilers and interpreters. It describes the roles of compiler components like lexical analyzers, syntactic analyzers, semantic analyzers, code generators, and symbol tables. Finally, it outlines the student's mission to build a compiler for a simplified algorithmic language using JavaCC.

Uploaded by

dgxtal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Compiler Construction

Salah Sadou

Head of Software Cybersecurity Dpt. at ENSIBS


Université Bretagne Sud

Salah Sadou (CYBERUS, UBS) Compiler Construction 1 / 20


Course Organization

Specification and instrumentation of a textual language


1 Compilation process
2 Syntax description with formal grammars
3 Syntax analysis techniques

Introduction to language theory


1 Typology
2 Concepts & Paradigms
3 Power and associated automata

Introduction to FRAMA-C
1 Introduction of formalism in the C language
2 Course given by Julien Signoles (CEA-List, Paris)

Salah Sadou (CYBERUS, UBS) Compiler Construction 2 / 20


Evaluation

Project: Building a programming language


Language specification
Definition of the language grammar
Language compiler implementation

Salah Sadou (CYBERUS, UBS) Compiler Construction 3 / 20


Overview

1 Programming Languages
Few Historical References
Translators
Translation stages
Tools for Building Translators
Leading Thread

Salah Sadou (CYBERUS, UBS) Compiler Construction 4 / 20


Few Historical References

Until 1940: immutable instructions.


from 1940 to 1950:
appearance of machine languages,
assembly languages: a language instruction is equivalent to a machine
instruction and intimately related to hardware.
Appearance of simple translators: assemblers programs.
from 1950 to 1960: creation of the first high-level languages
Fortran for scientific computing, Cobol for DB applications, Lisp
(functional) for reasoning and other languages (Algol, Pascal, C...)
later appear, among others, logical languages (Prolog) and
object-oriented languages (Smalltalk, Eiffel, C++, Java, ...).

Salah Sadou (CYBERUS, UBS) Compiler Construction 5 / 20


Today’s Languages

Today there are thousands of languages and are sometimes very specialized.

They are increasingly accessible to human understanding while


remaining computable.
More and more independence is required between program and target
machine.
Languages properties condition the complexity of the translators
construction: it is important to know the characteristics of the
languages and their expression means.

Salah Sadou (CYBERUS, UBS) Compiler Construction 6 / 20


Translators

Two categories of translators:


Compilers
Interpreters

Salah Sadou (CYBERUS, UBS) Compiler Construction 7 / 20


Compilers

Specificities
A maximum of errors detected by the compilation phase.
A translation, followed by several executions.

Salah Sadou (CYBERUS, UBS) Compiler Construction 8 / 20


Interpreters

Specificities
As many translations as executions.
Slow execution.
All errors appear at runtime.

Salah Sadou (CYBERUS, UBS) Compiler Construction 9 / 20


Hybrid Solutions

Exemple
Java compilers.

Salah Sadou (CYBERUS, UBS) Compiler Construction 10 / 20


Translation stages

Source program -> character sequence.


Target program -> suite of codes computable by the target machine.
A translation of a source program must produce a program that
matches the intent of the source program.
Salah Sadou (CYBERUS, UBS) Compiler Construction 11 / 20
Roles of Compiler Components

Lexical Analyzer
it produces lexical units (or tokens) by character concatenation.

The lexical unit constitutes the first level of entity having an identifiable
role in the language:
a sequence of digits like ’1’ ’2’ ’4’ is the lexeme ’124’
a sequence of letters like ’e’ ’l’ ’s’ ’e’ is the lexeme ’else’

Salah Sadou (CYBERUS, UBS) Compiler Construction 12 / 20


Roles of Compiler Components
Syntactic Analyzer
Checks the conformity of constructions (assembly of lexemes) with the
syntax of the language.
Builds the syntactic tree representing the source program.
Feeds the symbol table.
Diagnoses errors.

for example for x = 3 ∗ a0 + 14.0,


it builds:

Salah Sadou (CYBERUS, UBS) Compiler Construction 13 / 20


Roles of Compiler Components
Semantic Analyzer
checks the respect of the semantics: (typing, index of arrays, etc.)
feeds and uses the symbol table.
produces a semantic tree.
completes the diagnosis of errors.

For the same example:

Salah Sadou (CYBERUS, UBS) Compiler Construction 14 / 20


Roles of Compiler Components

Code Generator
It produces a sequence of statements executable by a target machine (or
intermediate code statements for a virtual machine).

Optimizer
It improves and simplifies the code produced by the generator following
various transformations (eg: deletion of unreachable parts of the program).

Salah Sadou (CYBERUS, UBS) Compiler Construction 15 / 20


Roles of Compiler Components

Symbol Table
It has a central role for:
variables, arrays, structures: description of the type, memory space to
be reserved, range, visibility,
procedures, functions, methods: number and type of parameters (call
by value, by address)

It is the grouping of essential knowledge to check the conformity to the


language and to translate the source program into executable code in
conformity with the expectations.

Salah Sadou (CYBERUS, UBS) Compiler Construction 16 / 20


Tools for Building Translators

Lexical parser generators: they automatically make a lexical analyzer.


Requirement: describe lexical units using a regular grammar.
Example: lex, Javacc
Syntactic parser generators: they automatically make a syntactic
analyzer.
Requirement: provide them with the rules of syntactic constructions
authorized by the language (non-contextual grammar rules).
Example: yacc, Javacc
Syntax-driven translation engines: they provide a set of functions to
traverse the parse tree while producing code.
Example: JJTree

Salah Sadou (CYBERUS, UBS) Compiler Construction 17 / 20


Leading Thread
Purpose
Write a compiler for a simplified algorithmic language.

Example (Concrete Syntax)


Algo Factorial
Integer x, result;
Begin
x := readInteger();
If x < 0 Then write("Negative value!");
Else result := 1;
While x >0 Do
result := result * x;
x := x - 1;
Done
write(resultat);
EndIf
EndSadou (CYBERUS, UBS)
Salah Compiler Construction 18 / 20
Your Mission (which you must accept!)

Based on an informal description of a simplified algorithmic language:


Produce a precise description of its syntax
Write a compiler of this language with JavaCC (and JJTree for the
brave)

Assessment
Presentation of your language’s Grammar
Demonstration of your compiler on a sample of algorithms.

Salah Sadou (CYBERUS, UBS) Compiler Construction 19 / 20

You might also like