Skip to content

Latest commit

 

History

History
145 lines (121 loc) · 3.5 KB

README.md

File metadata and controls

145 lines (121 loc) · 3.5 KB

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 Run

    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"
    

    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
  • 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

    <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 :

    1. You need To put a Space betwwen each element of the production
    2. You use this arrow for the rule definition
    3. this symbol for the epsilon ɛ
    4. Uppercase for the Non-Terminal

    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 .