EnlitHamster / pcompiler-lft

P Compiler developped for FLT exam

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Projects

The compiler is divided in 6 different projects:

  • Automata
  • Lexer
  • ArithmeticParser
  • Parser
  • ArithmeticEvaluator
  • Translator

Automata

This project contains a collection of automata, some useful to the Compiler, some not. These are mere exercises.

Lexer

The lexer is an important part of the compiler, used by the Parsers, Evaluator and Translator to check if the input code respects the CFG of P.

ArithmeticParser

The arithmetic parser controls that the syntax of the input code is an acceptable arithmetic expression.

Parser

The parser controls that the syntax of the input code is an acceptable program written in P.

ArithmeticEvaluator

The arithmetic evaluator calculates the actual value of the input code, given it being an acceptable arithmetic expression.

Translator

The translator transforms the input code in actual Java ByteCode generating a .j file that JASMIN could easily compile in a .class file.

Exercises

1 🞍 Automata

  • 1: Binary automaton
  • 2: Id automaton
  • 3, 4, 5: Student automaton
  • 6: ModThree automaton
  • 7, 8: AThree automaton
  • 9: Name automaton
  • 10, 11: Comments automaton

2 🞍 Lexing

See Projects β‡’ Lexer

3 🞍 Parsing

  • 1: Arithmetic parser
  • 2: Parser

4 🞍 Evaluation

See Projects β‡’ ArithmeticEvaluator

5 🞍 Translation

See Projects β‡’ Translator

Usage

To compile a single exercise, use ./es.sh <paragraph> [exercise] [force build]
To compile a project use ./exec.sh build <project> [force build] To compile a single file (with due dependencies) use ./exec.sh build <file name> [force build]
To test a project use ./exec.sh test <project>
To compile the entire project use make
To clear the executables use make clear

Context-Free Grammar of P

P    β†’    SL $

SL   β†’    S SL'

SL'  β†’    ; S SL'
     |    Ξ΅

S    β†’    id := E
     |    print ( E )
     |    read ( id )
     |    case WL else S
     |    while ( BO ) S
     |    { SL }
     
WL   β†’    W WL'

WL'  β†’    W WL'
     |    Ξ΅

W    β†’    when ( BO ) S

BO   β†’    BA BO'

BO'  β†’    or BA BO'
     |    Ξ΅

BA   β†’    B BA'

BA'  β†’    and B BA'
     |    Ξ΅

B    β†’    E RELOP E
     |    ! ( E RELOP E )
     
E    β†’    T E'

E'   β†’    + T E'
     |    - T E'
     |    Ξ΅
     
T    β†’    F T'

T'   β†’    * F T'
     |    / F T'
     |    Ξ΅

F    β†’    ( E )
     |    num
     |    id

About

P Compiler developped for FLT exam


Languages

Language:Java 78.9%Language:Shell 9.7%Language:HTML 4.5%Language:Makefile 4.1%Language:Jasmin 2.2%Language:OpenEdge ABL 0.6%