https://github.com/hediske/compiler
A Compiler made using Maven that offers to the user the possibility to provide the language of the compiler .works only on SLR grammars and generates the SLR table according to the grammar given , An SLR parser generator and type checking.
https://github.com/hediske/compiler
compilation compiler lexical-analysis semantic-analysis slr slr-parser syntax-analysis
Last synced: 3 months ago
JSON representation
A Compiler made using Maven that offers to the user the possibility to provide the language of the compiler .works only on SLR grammars and generates the SLR table according to the grammar given , An SLR parser generator and type checking.
- Host: GitHub
- URL: https://github.com/hediske/compiler
- Owner: hediske
- License: mit
- Created: 2024-01-11T19:22:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-08T08:31:58.000Z (over 1 year ago)
- Last Synced: 2025-05-19T23:44:08.075Z (5 months ago)
- Topics: compilation, compiler, lexical-analysis, semantic-analysis, slr, slr-parser, syntax-analysis
- Language: Java
- Homepage:
- Size: 47.9 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Compiler
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 .
How to RunTo 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"Lexical Analyser
Symbols table
| Symbol| Types |
| ----------- | ----------- |
| if| NONE|
| else| NONE|
| true| BOOL|
| false| BOOL|
| function| NONE|
| while| NONE|
| for| NONE|
| string| NONE|
| bool| NONE|
| int| NONE|
| char| NONE|Language
Delimiter → space|tab|lineBreak
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
= →=
: →:
; →;
) →)
(→ (
} →}
{ → {
Syntax Analyser
This package can generate for the user
-
First
-
Follows
-
SLR table
- 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
and can verfiy if the grammar is SLR or not
To add a grammar to your Compiler you can modify file `grammar.json` located in **src/ressources**
Example
{
"Grammar": [
"Pro → D I",
"D → DL ; D | ɛ",
"DL → T : id | F : id",
"T → char | int | bool | string",
"F → function ( P ) : T | function ( ) : T",
"I → IL ; I | ɛ",
"IL → if ( E ) { I } IFS | while ( E ) { I } | id = E | id = function ( Par ) { I } | id = function ( ) { I }",
"IFS → else { I } | ɛ",
"E → id ( P' ) | id ( ) | EL opari E | EL opbol E | EL oprel E | opneg E | opnot E | ( E ) | EL",
"EL → nb | id | str | litteral | true | false",
"P → T | T , P",
"P' → E | E , P'",
"Par → id : T | id : T , Par"
]
}
The grammar must respect these rules :
Example
> 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**
Semantic analyser
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 .