Skip to content

Commit

Permalink
Merge pull request #9 from malinduGamage/feature/cse_machine
Browse files Browse the repository at this point in the history
Feature/cse machine
  • Loading branch information
UchihaIthachi authored Apr 9, 2024
2 parents 7835608 + fe1966d commit e1b1451
Show file tree
Hide file tree
Showing 41 changed files with 1,519 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
test_suite: [test_ast, test_st]
test_suite: [test_ast, test_st, test_all]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ PYTEST = pytest
.PHONY: install run tests test test_ast test_st test_all clean all check_python check_pip

# Default target
all: install clean test_ast clean
all: install clean test_all clean

# Install dependencies
install: check_python check_pip requirements.txt
Expand Down Expand Up @@ -77,7 +77,7 @@ run: install main.py test.txt
# Run normal tests
test:
@echo "Running tests...$(OS)"
@if [ "$(OS)" = "Windows" ] && [ "$(R)" = "" ]; then \
@if [ "$(OS)" = "Windows_NT" ] && [ "$(R)" = "" ]; then \
if [ "$(F)" = "" ]; then \
$(PYTHON) -m pytest -v --no-summary rpal_tests/test_generate_tests_with_rpal_exe.py ; \
else \
Expand Down Expand Up @@ -134,13 +134,19 @@ test_all:
echo "=========================================================================================================="; \
echo "Running tests for Standardized Syntax Tree (ST):"; \
$(PYTHON) -m pytest -q rpal_tests/test_generate_st_tests_with_rpal_exe.py ; \
echo "=========================================================================================================="; \
echo "Running tests:"; \
$(PYTHON) -m pytest -q rpal_tests/test_generate_tests_with_rpal_exe.py ; \
else \
echo "=========================================================================================================="; \
echo "Running tests for Abstract Syntax Tree (AST):"; \
$(PYTHON) -m pytest -q rpal_tests/test_generate_ast_tests_with_rpal_exe.py ; \
echo "=========================================================================================================="; \
echo "Running tests for Standardized Syntax Tree (ST):"; \
$(PYTHON) -m pytest -q rpal_tests/test_generate_st_tests_with_rpal_exe.py ; \
echo "=========================================================================================================="; \
echo "Running tests :"; \
$(PYTHON) -m pytest -q rpal_tests/test_generate_tests.py ; \
fi

# Clean up generated files
Expand Down
51 changes: 34 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
![Tests](https://github.com/malinduGamage/RPAL-Interpreter/actions/workflows/testing.yml/badge.svg)

## RPAL-Interpreter

- This project was the culmination of the CS3513-Programming Languages module, which was part of the curriculum offered by the Department of Computer Science & Engineering at the University of Moratuwa. It was completed during the 4th semester of Batch 21.

## Table of Contents
Expand All @@ -10,31 +11,37 @@
- [Usage](#usage)
- [Features](#features)
- [Project Structure](#project-structure)

- [Lexical Analyzer](#lexical-analyzer)
- [Screener](#screener)
- [Parser](#parser)
- [CSE Machine](#cse-machine)

- [Project Structure](#project-structure)
- [Contributors](#contributors)
- [License](#license)

## Problem Requirements
- Implement a lexical analyzer and a parser for the RPAL (Right-reference Pedagogic Algorithmic Language). Refer the [RPAL_Lex](https://github.com/malinduGamage/RPAL-Interpreter/blob/main/doc/RPAL_Lex.pdf) for the lexical rules and [RPAL_Grammar](https://github.com/malinduGamage/RPAL-Interpreter/blob/main/doc/RPAL_Grammar.pdf) for the grammar details.Additionally, refer to [About RPAL](https://github.com/malinduGamage/RPAL-Interpreter/blob/main/doc/About%20RPAL.pdf) for information about the RPAL language.

- Implement a lexical analyzer and a parser for the RPAL (Right-reference Pedagogic Algorithmic Language). Refer the [RPAL_Lex](https://github.com/malinduGamage/RPAL-Interpreter/blob/main/doc/RPAL_Lex.pdf) for the lexical rules and [RPAL_Grammar](https://github.com/malinduGamage/RPAL-Interpreter/blob/main/doc/RPAL_Grammar.pdf) for the grammar details.Additionally, refer to [About RPAL](https://github.com/malinduGamage/RPAL-Interpreter/blob/main/doc/About%20RPAL.pdf) for information about the RPAL language.
- The output of the parser should be the Abstract Syntax Tree (AST) for the given input program.
Implement an algorithm to convert the Abstract Syntax Tree (AST) in to Standardize Tree (ST) and implement CSE machine.Refer to the [semantics](https://github.com/malinduGamage/RPAL-Interpreter/blob/main/doc/semantics.pdf) document, which contains the rules for transforming the AST into the ST
Implement an algorithm to convert the Abstract Syntax Tree (AST) in to Standardize Tree (ST) and implement CSE machine.Refer to the [semantics](https://github.com/malinduGamage/RPAL-Interpreter/blob/main/doc/semantics.pdf) document, which contains the rules for transforming the AST into the ST
- Program should be able to read an input file which contains a RPAL program and return Output which should match the output of rpal.exe for the relevant program.
- For more details, refer the [Project_Requirements](https://github.com/malinduGamage/RPAL-Interpreter/blob/main/doc/ProgrammingProject.pdf) document.

## About our solution

- **Programming Language**:python
- **Development & Testing**: Visual Studio Code, Command Line, Cygwin, Pytest, GitHub Actions
- **Development & Testing**: Visual Studio Code, Command Line, Cygwin, Pytest, GitHub Actions

## Usage

To use the RPAL-Interpreter, follow these steps:

> ### Prerequisites
>
> Your local machine must have Python and pip installed.
1. Clone the repository to your local machine or download the project source code as a ZIP file.
2. Navigate to the root directory of the project in the command line interface.
3. Install the dependencies by running the following command in the project directory:
Expand All @@ -44,7 +51,7 @@ pip install -r requirements.txt
```

4. Put your RPAL test programs in the root directory. We had added the [test.txt](https://github.com/malinduGamage/RPAL-Interpreter/blob/main/test.txt) to the root directory, which contains the sample input program of the [Project_Requirements](https://github.com/malinduGamage/RPAL-Interpreter/blob/main/doc/ProgrammingProject.pdf) document.
Run the main script `main.py` with the file name as an argument:
Run the main script `main.py` with the file name as an argument:

```bash
python main.py file_name
Expand Down Expand Up @@ -78,6 +85,12 @@ To generate the Standardized Tree:
python main.py -st file_name
```

To generate the CSE table:

```bash
python main.py -ct file_name
```

#### Using Make Commands (Alternative Method)

**Your local machine must be able to run make command**
Expand All @@ -86,7 +99,7 @@ python main.py -st file_name
> For Windows users, for make commad [Cygwin](https://www.cygwin.com/install.html) or similar unix like env tools for execution.
Alternatively, you can use the following make commands:
Alternatively, you can use the following make commands:

**Install Dependencies:**

Expand All @@ -106,6 +119,7 @@ Run all tests (in rpal_tests/rpal_sources/) :
```bash
make test_all (in rpal_tests/rpal_sources/) :
```

Run tests for final result (in rpal_tests/rpal_sources/) :

```bash
Expand All @@ -129,7 +143,9 @@ make test_st
```bash
make all
```

> #### Note for Python 3 Users
>
> If you have both Python 2 and Python 3 installed, you may need to use python3 instead of python in the commands above. Similarly, use pip3 instead of pip for installing packages.
## Features
Expand All @@ -141,6 +157,7 @@ make all
- Executes the RPAL program and produces the output

The interpreter consists of the following main components:

## Project Structure

The RPAL interpreter project is structured into several components, each responsible for specific functionalities related to lexical analysis, parsing, interpretation, and error handling. Below is an overview of the project structure and its key components:
Expand Down Expand Up @@ -214,18 +231,18 @@ RPAL-Interpreter/
│ └── __init__.py # Marks the directory as a Python package
|
├── cse_machine/ # Package for parsing functionality
│ ├── apply_operations/
│ │ ├── apply_bi.py
│ │ ├── apply_un.py
│ ├── apply_operations/
│ │ ├── apply_bi.py
│ │ ├── apply_un.py
│ │ └── __init__.py # Marks the directory as a Python package
│ ├── data_structures/
│ │ ├── enviroment.py
│ │ ├── stack.py
│ │ ├── control_structure.py
│ │ └── __init__.py
│ ├── utils/
│ │ ├── STlinearlizer.py
│ │ ├── util.py
│ ├── data_structures/
│ │ ├── enviroment.py
│ │ ├── stack.py
│ │ ├── control_structure.py
│ │ └── __init__.py
│ ├── utils/
│ │ ├── STlinearlizer.py
│ │ ├── util.py
│ │ └── __init__.py # Marks the directory as a Python package
│ ├── machine.py
│ └── __init__.py # Marks the directory as a Python package
Expand Down
Empty file.
Loading

0 comments on commit e1b1451

Please sign in to comment.