Skip to content

ThisaraWeerakoon/RPAL-Interpreter

Repository files navigation

RPAL Interpreter

Developing an interpreter for RPAL language

0_RV_mQ55Aj-vww8l3

Description

The project entailed the development of a software system capable of analyzing and parsing the RPAL programming language. RPAL(Right-reference Pedagogic Algorithmic Language) is a simple functional programming language. This involved constructing a lexical analyzer to break down RPAL code into its fundamental components, followed by the creation of an Abstract Syntax Tree (AST) to represent the program's structure and logic. Subsequently, a parsing algorithm was implemented to transform this AST into a Standardize Tree (ST). Additionally, the system was required to execute RPAL programs using a CSE (Compiled Stack Environment) machine. The ultimate objective was to ensure that the output of our system matched that of an established RPAL interpreter, specifically "rpal.exe", when provided with identical input programs.

  • Motivation: To get hands on experience in developing of a programming language.
  • Why: RPAL is a simple functional programming language,so it is easy to start with RPAL
  • Problem Solved: Implemented a fully funcational interpreter including a lexical analyzer and a parser.Any program written in RPAL language can be executed in our programme.
  • What We Learned: How to design a lexical analyzer,then how to parse the grammar and create abstract syntax tree and how to simplify it into syntax tree.Finally executing it on a CSE machine. Learned the underlying principles of programming languages.

Table of Contents

Installation

Follow these steps to setup the code:

  1. Clone the repository:

    git clone https://github.com/ThisaraWeerakoon/RPAL-Interpreter
  2. Navigate to the project directory:

    cd RPAL-Interpreter
  3. Compile the code for interpreter: I have built a Makefile to compile the code in one command:

    make

    Or you can directly compile using following command

    g++ -o myrpal main.cpp

    Now myrpal.exe created which is the RPAL interpreter

Usage

Now to use the RPAL interpreter,you can test myrpal.exe with any programme written in RPAL language. In this repo there is a provided sample RPAL program RPAL_test.To test it use following command:

To execute program directly:

./myrpal rpal_test

To print the AST, use the −𝑎𝑠𝑡 switch.

./myrpal -ast rpal_test

After above commands you may see something similar below as output.

Screenshot 2024-07-09 at 22 26 05

Doucmentation

You can access the comprehensive report including the folder structure and other essential theory biehind implementtion Report.pdf

Credits

We used several third-party assets and tutorials, including:

License

This project is licensed under the MIT License - see the LICENSE file for details.

Features

  • Implemented a lexical analyzer which creates tokens.You can find the lexical rules RPAL_Lex.pdf
  • After lexical analyzer,program is parsed and create Abstract Syntax Tree
  • Further the AST is also converted into Standarize Tree
  • Finally program is exeuted in CSE Machine (Control Stack Environement Machine) and given the final output
  • You can find the grammar rules of the RPAL RPAL_Grammar.pdf
  • If you try to implement the code repo and want to see whether the interpretation is correct,you can check with the standard RPAL interpreter <RPAL.Zip file

How to Contribute

We welcome contributions from the community! If you are interested in contributing, please follow these guidelines:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix:
    git checkout -b feature-or-bugfix-name
  3. Commit your changes:
    git commit -m "Description of the feature or bug fix"
  4. Push to the branch:
    git push origin feature-or-bugfix-name
  5. Open a pull request and provide a detailed description of your changes.

About

Developing an interpreter for a programming language

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages