01 - languages and compilers
DESCRIPTION
CompiladoresTRANSCRIPT
![Page 1: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/1.jpg)
Languages & Compilers From source code to executable code
#define L 10
main() { int i,k,r[L]; for(i=0;i<L;i++) { k = 3*i+2; r[i] = k*k; } }
0010011000110001 1000111011001010 1101010010101001 1010101010101111 1010100111111111 0101010101010101
Compiler
Error Messages
![Page 2: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/2.jpg)
The compiler
Language Processing Technologies
Marco Maggini
2
![Page 3: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/3.jpg)
Source and object languages
• There are... hundreds of programming languages ▫ General purpose programming languages
C, C++, Pascal, Fortran, Java, Basic, Lisp, Prolog, perl.... ▫ Special purpose languages
Text formatting (Tex, Latex...) Database management and querying (SQL)
• The compiler translates the source language into ▫ Another high-level programming language ▫ e.g. pascal -> C ▫ The machine code for a given processor/architecture
Language Processing Technologies
Marco Maggini
3
![Page 4: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/4.jpg)
Parsing and generation
Language Processing Technologies
Marco Maggini
4
X = A+B*C X *
+ =
C B A
![Page 5: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/5.jpg)
The compiler “context”
Language Processing Technologies
Marco Maggini
5
preprocessor
assembler
linker/loader
Source code skeleton
source program
assembly code
object code
executable code
libreries
include, define (macro)
![Page 6: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/6.jpg)
Compiler structure
Language Processing Technologies
Marco Maggini
6
lexical analysis
syntactic analysis
semantical analysis
intermediate code generation
optimization
object code generation
error handling symbol table
![Page 7: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/7.jpg)
Lexical analysi (scanning)
Language Processing Technologies
Marco Maggini
7
int somma, diff = 0.3;
![Page 8: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/8.jpg)
Syntatic Analyis (parsing)
Language Processing Technologies
Marco Maggini
8
assignment statement
identifier expression
expression
expression identifier
identifier number
expression
expression A
=
+
*
B C 60
![Page 9: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/9.jpg)
Syntatic rules
Language Processing Technologies
Marco Maggini
9
base rules
recursive rules
![Page 10: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/10.jpg)
Sematical analysis • Yields the sematics associated to the syntatic structure ▫ It verifies that the usage rules of the language are satisfied
identifier declarations (e.g. duplicate definitions,...) type check (compatibility of types in expressions, automatic
type conversion, type check for vector indexes, ecc..)
Language Processing Technologies
Marco Maggini
10
*
C
D
int D; float C;
type conversion function int -> float
![Page 11: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/11.jpg)
Symbol table • It memorizes the identifiers and their associated attributes ▫ memory allocation ▫ type ▫ visibility scope ▫ number and type of function/procedure arguments
Language Processing Technologies
Marco Maggini
11
memory allocation
![Page 12: 01 - Languages and Compilers](https://reader034.vdocuments.net/reader034/viewer/2022042821/55cf9237550346f57b94ba06/html5/thumbnails/12.jpg)
Object code generation
Language Processing Technologies
Marco Maggini
12
= id1
id2 id3
+ * int-to-float
60
t1 = int-to-float(60) t2 = id3 * t1 t3 = id2 + t2 id1 = t3
t1 = id3 * 60.0 id1 = id2 + t1
MOVF id3, R2 MULF #60.0, R2 .............
internal intermediate representation
intermediate code generation
code optimization
object code generation