Skip to content

thppn/ppp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ppp

For the purpose of Compilers II lesson in the CSE Dept @ University of Ioannina was developed an OOP language compiling to C code. In this repository the project is refactored from scratch according to the initial requirements.

A simple ppp program looks like this

class Fibonacci:
    int x;;
    def __init__(self): Fibonacci;;

    def fib(self, int n): int
        if(n <= 1):
            return n;
        endif;
        return fib(n-1) + fib(n-2)
    ;;
class Main:
    int x, y ;
    Fibonacci f
    ;;

    def main(self): -
        $Fibonacci(self.f);
        input self.x;
        self.y = self.f.fib(self.x);
        print self.y
    ;;

How to run

Download ANTLR4 jar and install python runtime

bash pip install antlr4-python3-runtime

or use the Dockerfile

docker run -it --rm thppn/antlr4-python:latest

Compile grammar

bash java -jar antlr/antlr-4.13.2-complete.jar -Dlanguage=Python3 -o grammar ./ppp.g4

Compile ppp example program

bash python main.py examples/<program>/<program>.ppp

Compile final file and execute

bash gcc output.c && ./a.out

ToDo

  • error messages
  • create more examples
  • all types support
  • arrays

About

An objected oriented programming language designed for educational purposes with ANTLR

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published