Hello , This project is a compiler based on three analysers :
- lexical analyser This analyser provides for the user the possiblilty of using many types and symbols
- Syntax analyser This analyser provides for the user the possiblilty of generating First,Follows and Slr table based on the grammar given
- Semantic analyser
This analyser provides for the user the possiblilty of testing if the grammar is correct semantically by verifying the Types .
To run this app you need to install Java Jdk 17 or above : You can check the version by typing this command
java --version
First , change directory to compiler folder :cd compiler
Then run this command
mvn exec:java -Dexec.mainClass="com.mycompany.compiler.main.Compiler"
Symbol Types if NONE else NONE true BOOL false BOOL function NONE while NONE for NONE string NONE bool NONE int NONE char NONE Delimiter → space|tab|lineBreak
This package can generate for the user
Num → (chiffre)+
id → lettre(chiffre + lettre)+
opari → +| − | ∗ | /
oprel →== | < | <= | <> | > | >=
opnot →!
opneg→ –
str → ”lettre*”
opbol→ || | &&
while→ while
if→ if
else→ else
char→ char
string→ string
bool→ bool
function→ f unction
true→ true
false→ false
= →=
: →:
; →;
) →)
(→ (
} →}
{ → {
- First
- Follows
- SLR table and can verfiy if the grammar is SLR or not
- You need To put a Space betwwen each element of the production
- You use this arrow for the rule definition
→
- this symbol for the epsilon
ɛ
- Uppercase for the Non-Terminal
To add a grammar to your Compiler you can modify file grammar.json
located in src/ressources
<small>
{
"Grammar": [<br>
"Pro → D I",<br>
"D → DL ; D | ɛ",<br>
"DL → T : id | F : id",
<br>
"T → char | int | bool | string",
<br>
"F → function ( P ) : T | function ( ) : T",
<br>
"I → IL ; I | ɛ",
<br>
"IL → if ( E ) { I } IFS | while ( E ) { I } | id = E | id = function ( Par ) { I } | id = function ( ) { I }",
<br>
"IFS → else { I } | ɛ",
<br>
"E → id ( P' ) | id ( ) | EL opari E | EL opbol E | EL oprel E | opneg E | opnot E | ( E ) | EL",
<br>
"EL → nb | id | str | litteral | true | false",
<br>
"P → T | T , P",
<br>
"P' → E | E , P'",
<br>
"Par → id : T | id : T , Par"
<br>
]
<br>
}</small>
The grammar must respect these rules :
E' → E
E → E + T
E → T
T → T * F
T → F
F → ( E )
F → id
To add a code for testing the Syntax analyser ! your file must be also located under src/ressources
The goal of this analyser is to check the type in the code to compile ! It checks if the variables were declared , if statements are correct and if expressions have correct types .