This small project is an 3rd year double degree project in compilation made to typecheck and detect errors in small C programs with a few implemented functionalities.
Here are the details
- int taille = 64;
- int pgcd(int a,int b) { ... }
- ASCII display
putchar(n); - Value assignements to variables
x = n; - If statement
if(c) { s1 } else { s2 } - While loop
while (c) { s } - Return in functions
return (c); - expressions
- Constants
42,true... - Operators (boolean, integers)
+,*,<... - Variables
x - Function calls
f(x1,x2...)
- Integers
int - Boolean
bool - Void
void
- Declaration & init at once
int n = 0; - Lexical analysis
- Syntaxical analysis
- Typecheck (Return, parameters, Variable assignment)
- Hashmap are used to emulate environment changes.
- Integer constants : hexa
0xeFF1c4cE, binary0b0_1_0_1_0_1et octals0432213(=0ox432213in Caml) - Comments :
//line &/*bloc*/ - Loops
do while&for - Switch statement
switch, with the associated instructions :break,default,case. - Instruction
continue(no real effect in typechecker) - Instructions
--&++ - Alternative
returnforms :return n;&return;&return(n); - Alternative
ifforms :if(c) { s1 }if(c) i1 else i2if(c) i1 - Alternative
whileforms :while(c);looping forever if c is true - Typechecking multiple files at once
- Asserts
mainexists - Assets a
returnstatement is placed in every branch of any nonvoidfunction - Order of definitions for global variables & functions : error when calling undefined variables
- Double declaration (functions and variables).
- Error details giving line and column of the error
- The program is now just instructions followed by one another, instead of variables and functions declaration lists.