Developing an interpreter for RPAL language
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.
Follow these steps to setup the code:
-
Clone the repository:
git clone https://github.com/ThisaraWeerakoon/RPAL-Interpreter
-
Navigate to the project directory:
cd RPAL-Interpreter
-
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
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.
You can access the comprehensive report including the folder structure and other essential theory biehind implementtion Report.pdf
We used several third-party assets and tutorials, including:
This project is licensed under the MIT License - see the LICENSE file for details.
- 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
We welcome contributions from the community! If you are interested in contributing, please follow these guidelines:
- Fork the repository.
- Create a new branch for your feature or bug fix:
git checkout -b feature-or-bugfix-name
- Commit your changes:
git commit -m "Description of the feature or bug fix"
- Push to the branch:
git push origin feature-or-bugfix-name
- Open a pull request and provide a detailed description of your changes.