An open API service indexing awesome lists of open source software.

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.

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


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


    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 .