From c4642a8462e709823b32d0d38661d37221b6d22d Mon Sep 17 00:00:00 2001 From: Harshana-2000 Date: Thu, 18 Apr 2024 20:06:53 +0530 Subject: [PATCH] refactor: Update project directory structure This commit reorganizes the project directory structure to improve clarity and maintainability. Changes include: - Moving files to more appropriate directories - Renaming directories for consistency - Updating import statements and references accordingly These changes aim to make it easier for developers to navigate the project and locate relevant files. No functionality has been altered in this commit. --- .vscode/settings.json | 16 +- Makefile | 41 +++-- README.md | 155 +++++++++--------- myrpal.py | 2 +- rpal_tests/assert_program.py | 2 +- rpal_tests/rpal_sources/tiny | 4 +- rpal_tests/test_generate_ast_tests.py | 2 +- rpal_tests/test_generate_st_tests.py | 2 +- rpal_tests/test_generate_tests.py | 2 +- {cse_machine => src/cse_machine}/__init__.py | 0 .../cse_machine}/apply_operations/__init__.py | 0 .../apply_operations/apply_bin.py | 10 +- .../cse_machine}/apply_operations/apply_un.py | 8 +- .../cse_machine}/data_structures/__init__.py | 0 .../data_structures/control_structure.py | 4 +- .../data_structures/enviroment.py | 2 +- .../cse_machine}/data_structures/stack.py | 6 +- {cse_machine => src/cse_machine}/machine.py | 22 +-- .../cse_machine}/utils/STlinearizer.py | 4 +- .../cse_machine}/utils/__init__.py | 0 .../cse_machine}/utils/util.py | 0 .../errors_handling}/__init__.py | 0 .../errors_handling}/cse_error_handler.py | 2 +- .../errors_handling}/error_handler.py | 2 +- {interpreter => src/interpreter}/__init__.py | 0 .../interpreter}/execution_engine.py | 24 +-- .../lexical_analyzer}/__init__.py | 0 .../lexical_analyzer}/scanner.py | 14 +- {parser => src/parser}/__init__.py | 0 {parser => src/parser}/build_standard_tree.py | 6 +- {parser => src/parser}/parser_module.py | 8 +- {screener => src/screener}/__init__.py | 0 {screener => src/screener}/token_screener.py | 6 +- .../table_routines}/__init__.py | 0 .../table_routines}/accept_states.py | 2 +- .../table_routines}/char_map.py | 2 +- .../table_routines}/fsa_table.py | 2 +- .../table_routines}/keywords.py | 2 +- {utils => src/utils}/__init__.py | 0 .../utils}/control_structure_element.py | 0 {utils => src/utils}/file_handler.py | 2 +- {utils => src/utils}/node.py | 2 +- {utils => src/utils}/stack.py | 2 +- {utils => src/utils}/token_printer.py | 2 +- {utils => src/utils}/tokens.py | 2 +- {utils => src/utils}/tree_list.py | 2 +- {utils => src/utils}/tree_printer.py | 4 +- test_ | 10 +- 48 files changed, 191 insertions(+), 187 deletions(-) rename {cse_machine => src/cse_machine}/__init__.py (100%) rename {cse_machine => src/cse_machine}/apply_operations/__init__.py (100%) rename {cse_machine => src/cse_machine}/apply_operations/apply_bin.py (96%) rename {cse_machine => src/cse_machine}/apply_operations/apply_un.py (94%) rename {cse_machine => src/cse_machine}/data_structures/__init__.py (100%) rename {cse_machine => src/cse_machine}/data_structures/control_structure.py (91%) rename {cse_machine => src/cse_machine}/data_structures/enviroment.py (98%) rename {cse_machine => src/cse_machine}/data_structures/stack.py (83%) rename {cse_machine => src/cse_machine}/machine.py (96%) rename {cse_machine => src/cse_machine}/utils/STlinearizer.py (97%) rename {cse_machine => src/cse_machine}/utils/__init__.py (100%) rename {cse_machine => src/cse_machine}/utils/util.py (100%) rename {errors_handling => src/errors_handling}/__init__.py (100%) rename {errors_handling => src/errors_handling}/cse_error_handler.py (94%) rename {errors_handling => src/errors_handling}/error_handler.py (92%) rename {interpreter => src/interpreter}/__init__.py (100%) rename {interpreter => src/interpreter}/execution_engine.py (94%) rename {lexical_analyzer => src/lexical_analyzer}/__init__.py (100%) rename {lexical_analyzer => src/lexical_analyzer}/scanner.py (94%) rename {parser => src/parser}/__init__.py (100%) rename {parser => src/parser}/build_standard_tree.py (98%) rename {parser => src/parser}/parser_module.py (99%) rename {screener => src/screener}/__init__.py (100%) rename {screener => src/screener}/token_screener.py (94%) rename {table_routines => src/table_routines}/__init__.py (100%) rename {table_routines => src/table_routines}/accept_states.py (96%) rename {table_routines => src/table_routines}/char_map.py (98%) rename {table_routines => src/table_routines}/fsa_table.py (98%) rename {table_routines => src/table_routines}/keywords.py (97%) rename {utils => src/utils}/__init__.py (100%) rename {utils => src/utils}/control_structure_element.py (100%) rename {utils => src/utils}/file_handler.py (97%) rename {utils => src/utils}/node.py (99%) rename {utils => src/utils}/stack.py (98%) rename {utils => src/utils}/token_printer.py (85%) rename {utils => src/utils}/tokens.py (99%) rename {utils => src/utils}/tree_list.py (97%) rename {utils => src/utils}/tree_printer.py (88%) diff --git a/.vscode/settings.json b/.vscode/settings.json index d53c412..dc45ebe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,13 +1,13 @@ { "python.analysis.extraPaths": [ - "${workspaceFolder}/utils/", - "${workspaceFolder}/errors_handling/", - "${workspaceFolder}/lexical_analysis/", - "${workspaceFolder}/table_routines/", - "${workspaceFolder}/screener/", - "${workspaceFolder}/parser/", - "${workspaceFolder}/cse_machine/", - "${workspaceFolder}/interpreter/", + "${workspaceFolder}/src/utils/", + "${workspaceFolder}/src/errors_handling/", + "${workspaceFolder}/src/lexical_analysis/", + "${workspaceFolder}src//table_routines/", + "${workspaceFolder}/src/screener/", + "${workspaceFolder}/src/parser/", + "${workspaceFolder}/src/cse_machine/", + "${workspaceFolder}/src/interpreter/", "${workspaceFolder}/rpal_tests/" ] diff --git a/Makefile b/Makefile index b45dfc8..7fbc604 100644 --- a/Makefile +++ b/Makefile @@ -105,11 +105,10 @@ run: install myrpal.py test.txt # define test targets for the RPAL interpreter ############################################################################################################ -R = 1 # Run normal tests test: @echo "Running tests...$(OS)" - @if [ "$(OS)" = "Windows_NT" ] && [ "$(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 \ @@ -126,59 +125,59 @@ test: # Run a specific test with parameters test_st: @echo "Running tests...$(OS)" - @if [ "$$(uname -s)" = "Linux" ] && [ -z "$(R)" ]; then \ + @if [ "$(OS)" = "Windows_NT" ] && [ "$(R)" = " " ]; then \ if [ "$(F)" = "" ]; then \ - $(PYTHON) -m pytest -v --no-summary rpal_tests/test_generate_st_tests.py ; \ + $(PYTHON) -m pytest -v --no-summary rpal_tests/test_generate_st_tests_with_rpal_exe.py ; \ else \ - $(PYTHON) -m pytest -v -k "$(F)" rpal_tests/test_generate_st_tests.py -vvv --tb=short; \ + $(PYTHON) -m pytest -v -k "$(F)" rpal_tests/test_generate__st_tests_with_rpal_exe.py -vvv --tb=short; \ fi \ else \ if [ "$(F)" = "" ]; then \ - $(PYTHON) -m pytest -v --no-summary rpal_tests/test_generate_st_tests_with_rpal_exe.py ; \ + $(PYTHON) -m pytest -v --no-summary rpal_tests/test_generate_st_tests.py ; \ else \ - $(PYTHON) -m pytest -v -k "$(F)" rpal_tests/test_generate_st_tests_with_rpal_exe.py -vvv --tb=short; \ + $(PYTHON) -m pytest -v -k "$(F)" rpal_tests/test_generate_st_tests.py -vvv --tb=short; \ fi \ fi # Run a specific test with parameters test_ast: @echo "Running tests...$(OS)" - @if [ "$$(uname -s)" = "Linux" ] && [ -z "$(R)" ]; then \ + @if [ "$(OS)" = "Windows_NT" ] && [ "$(R)" = " " ]; then \ if [ "$(F)" = "" ]; then \ - $(PYTHON) -m pytest -vv --no-summary rpal_tests/test_generate_ast_tests.py ; \ + $(PYTHON) -m pytest -v --no-summary rpal_tests/test_generate_ast_tests_with_rpal_exe.py ; \ else \ - $(PYTHON) -m pytest -vv -k "$(F)" rpal_tests/test_generate_ast_tests.py -vvv --tb=short; \ + $(PYTHON) -m pytest -v -k "$(F)" rpal_tests/test_generate__ast_tests_with_rpal_exe.py -vvv --tb=short; \ fi \ else \ if [ "$(F)" = "" ]; then \ - $(PYTHON) -m pytest -vv --no-summary rpal_tests/test_generate_ast_tests_with_rpal_exe.py ; \ + $(PYTHON) -m pytest -v --no-summary rpal_tests/test_generate_ast_tests.py ; \ else \ - $(PYTHON) -m pytest -vv -k "$(F)" rpal_tests/test_generate_ast_tests_with_rpal_exe.py -vvv --tb=short; \ + $(PYTHON) -m pytest -v -k "$(F)" rpal_tests/test_generate_ast_tests.py -vvv --tb=short; \ fi \ fi test_all: @echo "Running tests...$(OS)" - @if [ "$$(uname -s)" = "Linux" ] && [ -z "$(R)" ]; then \ + @if [ "$(OS)" = "Windows_NT" ] && [ "$(R)" = " " ]; then \ echo "=========================================================================================================="; \ echo "Running tests for Abstract Syntax Tree (AST):"; \ - $(PYTHON) -m pytest rpal_tests/test_generate_ast_tests_with_rpal_exe.py ; \ + $(PYTHON) -m pytest -q --no-summary rpal_tests/test_generate_ast_tests_with_rpal_exe.py ; \ echo "=========================================================================================================="; \ echo "Running tests for Standardized Syntax Tree (ST):"; \ - $(PYTHON) -m pytest rpal_tests/test_generate_st_tests_with_rpal_exe.py ; \ + $(PYTHON) -m pytest -q --no-summary rpal_tests/test_generate_st_tests_with_rpal_exe.py ; \ echo "=========================================================================================================="; \ - echo "Running tests:"; \ - $(PYTHON) -m pytest rpal_tests/test_generate_tests_with_rpal_exe.py ; \ + echo "Running tests :"; \ + $(PYTHON) -m pytest -q --no-summary rpal_tests/test_generate_tests_with_rpal_exe.py ; \ else \ echo "=========================================================================================================="; \ echo "Running tests for Abstract Syntax Tree (AST):"; \ - $(PYTHON) -m pytest -q --no-summary rpal_tests/test_generate_ast_tests_with_rpal_exe.py ; \ + $(PYTHON) -m pytest -q --no-summary rpal_tests/test_generate_ast_tests.py ; \ echo "=========================================================================================================="; \ echo "Running tests for Standardized Syntax Tree (ST):"; \ - $(PYTHON) -m pytest -q --no-summary rpal_tests/test_generate_st_tests_with_rpal_exe.py ; \ + $(PYTHON) -m pytest -q --no-summary rpal_tests/test_generate_st_tests.py ; \ echo "=========================================================================================================="; \ - echo "Running tests :"; \ - $(PYTHON) -m pytest -q --no-summary rpal_tests/test_generate_tests_with_rpal_exe.py ; \ + echo "Running tests:"; \ + $(PYTHON) -m pytest -q --no-summary rpal_tests/test_generate_tests.py ; \ fi ############################################################################################################ diff --git a/README.md b/README.md index 95b6ad7..2f01d02 100644 --- a/README.md +++ b/README.md @@ -227,90 +227,91 @@ The RPAL interpreter project is structured into several components, each respons ```bash RPAL-Interpreter/ -├── myrpal.py # Main entry point of the application +├── myrpal.py # Main entry point of the RPAL interpreter application | -├── lexical_analyzer/ # Package for lexical analysis functionality -│ ├── scanner.py # Module containing lexical scanner logic -│ └── __init__.py # Marks the directory as a Python package +├── src/ # Source code directory +| ├── lexical_analyzer/ # Package for lexical analysis functionality +| │ ├── scanner.py # Module containing logic for the lexical scanner +| │ └── __init__.py # Marks the directory as a Python package +| | +| ├── screener/ # Package for screening functionality +| │ ├── screener.py # Module containing logic for screening +| │ └── __init__.py # Marks the directory as a Python package +| | +| ├── parser/ # Package for parsing functionality +| │ ├── build_standard_tree.py # Module for converting Abstract Syntax Tree (AST) to standard tree +| │ ├── parser_module.py # Module containing parser logic (converts tokens to AST) +| │ └── __init__.py # Marks the directory as a Python package +| | +| ├── cse_machine/ # Package for CSE (Compiled Stack Environment) machine functionality +| │ ├── apply_operations/ # Package for applying operations in the CSE machine +| │ │ ├── apply_bi.py # Module for applying binary operations +| │ │ ├── apply_un.py # Module for applying unary operations +| │ │ └── __init__.py # Marks the directory as a Python package +| │ ├── data_structures/ # Package for data structures used in the CSE machine +| │ │ ├── enviroment.py # Module for environment data structures +| │ │ ├── stack.py # Module for stack data structure +| │ │ ├── control_structure.py # Module for control structure data structure +| │ │ └── __init__.py # Marks the directory as a Python package +| │ ├── utils/ # Package for utilities used in the CSE machine +| │ │ ├── STlinearlizer.py # Module for linearizing the standard tree +| │ │ ├── util.py # Module for utility functions for the CSE machine +| │ │ └── __init__.py # Marks the directory as a Python package +| │ ├── machine.py # Module for the CSE machine +| │ └── __init__.py # Marks the directory as a Python package +| | +| ├── interpreter/ # Package for interpreter functionality +| │ ├── execution_engine.py # Module containing the logic for the RPAL interpreter +| │ └── __init__.py # Marks the directory as a Python package +| | +| ├── error_handling/ # Package for error handling functionality +| │ ├── error_handler.py # Module containing logic for error handling +| │ └── __init__.py # Marks the directory as a Python package +| | +| ├── table_routines/ # Package for table routines functionality +| │ ├── char_map.py # Module containing logic for character mapping +| │ ├── fsa_table.py # Module containing logic for Finite State Automaton (FSA) table +| │ ├── accept_states.py # Module containing logic for accept states +| │ ├── keywords.py # Module containing set of keywords +| │ └── __init__.py # Marks the directory as a Python package +| | +| ├── utils/ # Package for utility functionalities +| │ ├── tokens.py # Module containing token class definition +| │ ├── node.py # Module containing node data structure class definition +| │ ├── stack.py # Module containing stack class definition +| │ ├── token_printer.py # Module containing token printing function (for debugging purposes) +| │ ├── tree_printer.py # Module containing tree printing function (for debugging purposes) +| │ ├── tree_list.py # Module for listing tree elements +| │ ├── file_handler.py # Module containing file handling functions +| │ └── __init__.py # Marks the directory as a Python package | -├── screener/ # Package for screening functionality -│ ├── screener.py # Module containing screening logic -│ └── __init__.py # Marks the directory as a Python package +├── rpal_tests/ # Directory for tests +| ├── rpal_sources/ # Directory for RPAL source code files to test +| ├── test_generate_tests.py # Module for generating tests +| ├── test_generate_ast_tests.py # Module for generating tests in rpal_sources by pytest for AST +| ├── test_generate_st_tests.py # Module for generating tests in rpal_sources by pytest for standard tree +| ├── test_generate_tests_with_rpal_exe.py # Module for generating tests in rpal_sources by pytest output generated by real rpal.exe +| ├── test_generate_ast_tests_with_rpal_exe.py # Module for generating tests in rpal_sources by pytest for AST output generated by real rpal.exe +| ├── test_generate_st_tests_with_rpal_exe.py # Module for generating tests in rpal_sources by pytest for standard tree output generated by real rpal.exe +| ├── assert_program .py # Module for checking tests +| ├── program_name_list.py # List of program names in rpal_sources directory +| ├── output.py # List of outputs generated by rpal.exe +| ├── output_ast.py # List of AST outputs generated by rpal.exe +| ├── output_st.py # List of standard tree outputs generated by rpal.exe +| ├── rpal.exe # RPAL interpreter +| ├── cygwin1.dll # Cygwin DLL required for execution (if applicable) +| └── __init__.py # Marks the directory as a Python package | -├── parser/ # Package for parsing functionality -│ ├── build_standard_tree.py # Module for converting AST to standard tree -│ ├── parser_module.py # Module containing parser logic (filter token to AST) -│ └── __init__.py # Marks the directory as a Python package +├── doc/ # Directory for documentation files | -├── cse_machine/ # Package for parsing functionality -│ ├── apply_operations/ # Package for applying operations -│ │ ├── apply_bi.py # Module for applying binary operations -│ │ ├── apply_un.py # Module for applying unary operations -│ │ └── __init__.py # Marks the directory as a Python package -│ ├── data_structures/ # Package for data structures to cse machine -│ │ ├── enviroment.py # Module for enviroment data structures -│ │ ├── stack.py # Module for stack -│ │ ├── control_structure.py # Module for control structure -│ │ └── __init__.py # Marks the directory as a Python package -│ ├── utils/ # Package for utilities to cse machine -│ │ ├── STlinearlizer.py # Module for linearlizer the standard tree -│ │ ├── util.py # Module for utilities functions for cse machine -│ │ └── __init__.py # Marks the directory as a Python package -│ ├── machine.py # Module for cse machine -│ └── __init__.py # Marks the directory as a Python package +├── .vscode/ # Directory for VS Code settings +│ └── settings.json # VS Code settings file | -├── interpreter/ # Package for interpreter functionality -│ ├── execution_engine.py # Module containing interpreter logic -│ └── __init__.py # Marks the directory as a Python package +├── requirements.txt # File containing project dependencies | -├── error_handling/ # Package for error handling functionality -│ ├── error_handler.py # Module containing error handling logic -│ └── __init__.py # Marks the directory as a Python package +├── Makefile # Makefile for automating tasks such as installation, running tests, and cleaning up | -├── table_routines/ # Package for table routines functionality -│ ├── char_map.py # Module containing character mapping logic -│ ├── fsa_table.py # Module containing Finite State Automaton table logic -│ ├── accept_states.py # Module containing accept states logic -│ ├── keywords.py # Module containing keywords set -│ └── __init__.py # Marks the directory as a Python package -| -├── utils/ # Package for utility functionalities -│ ├── tokens.py # Module containing token class definition -│ ├── node.py # Module containing node data structure class definition -│ ├── stack.py # Module containing stack class definition -│ ├── token_printer.py # Module containing token printing function (for debugging purposes) -│ ├── tree_printer.py # Module containing tree printing function (for debugging purposes) -│ ├── tree_list.py # Module for listing tree elements -│ ├── file_handler.py # Module containing file handling functions -│ └── __init__.py # Marks the directory as a Python package -| -├── rpal_tests/ # Directory for tests -│ ├── rpal_sources/ # Directory for RPAL source code files to test -│ ├── test_generate_tests.py # Module for generating tests -│ ├── test_generate_ast_tests.py # Module for generating tests in rpal_sources by pytest for AST -│ ├── test_generate_st_tests.py # Module for generating tests in rpal_sources by pytest for standard tree -│ ├── test_generate_tests_with_rpal_exe.py # Module for generating tests in rpal_sources by pytest output generated by real rpal.exe -│ ├── test_generate_ast_tests_with_rpal_exe.py # Module for generating tests in rpal_sources by pytest for AST output generated by real rpal.exe -│ ├── test_generate_st_tests_with_rpal_exe.py # Module for generating tests in rpal_sources by pytest for standard tree output generated by real rpal.exe -│ ├── assert_program .py # Module for checking tests -│ ├── program_name_list.py # List of program names in rpal_sources directory -│ ├── output.py # List of outputs generated by rpal.exe -│ ├── output_ast.py # List of AST outputs generated by rpal.exe -│ ├── output_st.py # List of standard tree outputs generated by rpal.exe -│ ├── rpal.exe # RPAL interpreter -│ ├── cygwin1.dll # Cygwin DLL required for execution (if applicable) -│ └── __init__.py # Marks the directory as a Python package -| -├── doc/ # Directory for documentation files -| -├── .vscode/ # Directory for VS Code settings -│ └── settings.json # VS Code settings file -| -├── requirements.txt # File containing project dependencies -| -├── Makefile # Makefile for automating tasks such as installation, running tests, and cleaning up -| -└── __init__.py # Marks the directory as a Python package +└── __init__.py # Marks the directory as a Python package ``` diff --git a/myrpal.py b/myrpal.py index b6c6e08..ba09c9c 100644 --- a/myrpal.py +++ b/myrpal.py @@ -36,7 +36,7 @@ import sys import platform -from interpreter.execution_engine import Evaluator +from src.interpreter.execution_engine import Evaluator from rpal_tests.rpal_exe import rpal_exe def main(): diff --git a/rpal_tests/assert_program.py b/rpal_tests/assert_program.py index e7df6d2..7d4e3fa 100644 --- a/rpal_tests/assert_program.py +++ b/rpal_tests/assert_program.py @@ -8,7 +8,7 @@ import os from rpal_tests.rpal_exe import rpal_exe -from interpreter.execution_engine import Evaluator +from src.interpreter.execution_engine import Evaluator def program(source_file_name,flag=None): # Setup: Obtain original output by running the RPAL program using rpal_exe diff --git a/rpal_tests/rpal_sources/tiny b/rpal_tests/rpal_sources/tiny index 058f885..baca898 100644 --- a/rpal_tests/rpal_sources/tiny +++ b/rpal_tests/rpal_sources/tiny @@ -30,7 +30,7 @@ let Head i = i 1 in let Tail T = Rtail T (Order T) where rec Rtail T N = - N eq 1 -> true | + N eq 1 -> nil | (Rtail T (N-1) aug (T N)) in let rec EE E (m,i,o) = @@ -98,7 +98,7 @@ in Print ( PP ('program', (';', - (':=', 'x',11), + (':=', 'x',3), ('print', 'x') ) ) (nil aug 3) diff --git a/rpal_tests/test_generate_ast_tests.py b/rpal_tests/test_generate_ast_tests.py index a823431..054b8db 100644 --- a/rpal_tests/test_generate_ast_tests.py +++ b/rpal_tests/test_generate_ast_tests.py @@ -12,7 +12,7 @@ from rpal_tests.program_name_list import test_programs from rpal_tests.output_ast import out_ast from rpal_tests.output import out -from interpreter.execution_engine import Evaluator +from src.interpreter.execution_engine import Evaluator """ This function is a test function that is used to test the functionality of the interpreter. diff --git a/rpal_tests/test_generate_st_tests.py b/rpal_tests/test_generate_st_tests.py index 87b2614..185bf9d 100644 --- a/rpal_tests/test_generate_st_tests.py +++ b/rpal_tests/test_generate_st_tests.py @@ -12,7 +12,7 @@ from rpal_tests.program_name_list import test_programs from rpal_tests.output_st import out_st from rpal_tests.output import out -from interpreter.execution_engine import Evaluator +from src.interpreter.execution_engine import Evaluator """ This function is a test function that is used to test the functionality of the interpreter. diff --git a/rpal_tests/test_generate_tests.py b/rpal_tests/test_generate_tests.py index 92e17eb..49b99ae 100644 --- a/rpal_tests/test_generate_tests.py +++ b/rpal_tests/test_generate_tests.py @@ -11,7 +11,7 @@ from rpal_tests.assert_program import program from rpal_tests.program_name_list import test_programs from rpal_tests.output import out -from interpreter.execution_engine import Evaluator +from src.interpreter.execution_engine import Evaluator """ This function is a test function that is used to test the functionality of the interpreter. diff --git a/cse_machine/__init__.py b/src/cse_machine/__init__.py similarity index 100% rename from cse_machine/__init__.py rename to src/cse_machine/__init__.py diff --git a/cse_machine/apply_operations/__init__.py b/src/cse_machine/apply_operations/__init__.py similarity index 100% rename from cse_machine/apply_operations/__init__.py rename to src/cse_machine/apply_operations/__init__.py diff --git a/cse_machine/apply_operations/apply_bin.py b/src/cse_machine/apply_operations/apply_bin.py similarity index 96% rename from cse_machine/apply_operations/apply_bin.py rename to src/cse_machine/apply_operations/apply_bin.py index c10bcfb..41d8822 100644 --- a/cse_machine/apply_operations/apply_bin.py +++ b/src/cse_machine/apply_operations/apply_bin.py @@ -1,5 +1,13 @@ +#src/cse_machine/binary_operations/apply_bin.py + +# Description +# This module defines functions to apply binary operations to operands in the CSE (Compiler, Symbolic, Expression) machine. + +# Usage +# This module can be imported and used to apply binary operations to operands in the CSE machine. + # This file contains functions to apply unary and binary operations to operands in the CSE machine. -from utils.control_structure_element import ControlStructureElement +from src.utils.control_structure_element import ControlStructureElement def apply_binary(cse_machine, rator, rand, binop): """ diff --git a/cse_machine/apply_operations/apply_un.py b/src/cse_machine/apply_operations/apply_un.py similarity index 94% rename from cse_machine/apply_operations/apply_un.py rename to src/cse_machine/apply_operations/apply_un.py index 369b333..afc7f0e 100644 --- a/cse_machine/apply_operations/apply_un.py +++ b/src/cse_machine/apply_operations/apply_un.py @@ -1,12 +1,12 @@ -#cse_machine/binary_operations/apply_bin.py +#src/cse_machine/binary_operations/apply_un.py # Description -# This module defines functions to apply binary operations to operands in the CSE (Compiler, Symbolic, Expression) machine. +# This module defines functions to apply uninary operations to operands in the CSE (Compiler, Symbolic, Expression) machine. # Usage -# This module can be imported and used to apply binary operations to operands in the CSE machine. +# This module can be imported and used to apply uninary operations to operands in the CSE machine. -from utils.control_structure_element import ControlStructureElement +from src.utils.control_structure_element import ControlStructureElement def apply_unary(cse_machine, rator_e, unop): """ Apply a unary operation to an operand. diff --git a/cse_machine/data_structures/__init__.py b/src/cse_machine/data_structures/__init__.py similarity index 100% rename from cse_machine/data_structures/__init__.py rename to src/cse_machine/data_structures/__init__.py diff --git a/cse_machine/data_structures/control_structure.py b/src/cse_machine/data_structures/control_structure.py similarity index 91% rename from cse_machine/data_structures/control_structure.py rename to src/cse_machine/data_structures/control_structure.py index a171d22..69786ad 100644 --- a/cse_machine/data_structures/control_structure.py +++ b/src/cse_machine/data_structures/control_structure.py @@ -1,4 +1,4 @@ -#cse_machine/data_structures/control_structure.py +#src/cse_machine/data_structures/control_structure.py # Description # This module defines a control structure class for the CSE (Compiler, Symbolic, Expression) machine. @@ -7,7 +7,7 @@ # This module contains the ControlStructure class, which represents a control structure in the CSE machine. -from utils.stack import Stack +from src.utils.stack import Stack class ControlStructure(Stack): """ diff --git a/cse_machine/data_structures/enviroment.py b/src/cse_machine/data_structures/enviroment.py similarity index 98% rename from cse_machine/data_structures/enviroment.py rename to src/cse_machine/data_structures/enviroment.py index ae0da63..4c59f43 100644 --- a/cse_machine/data_structures/enviroment.py +++ b/src/cse_machine/data_structures/enviroment.py @@ -1,4 +1,4 @@ -# cse_machine/data_structures/enumeration.py +# src/cse_machine/data_structures/enumeration.py # Description # This module defines an enumeration class for the CSE (Compiler, Symbolic, Expression) machine. diff --git a/cse_machine/data_structures/stack.py b/src/cse_machine/data_structures/stack.py similarity index 83% rename from cse_machine/data_structures/stack.py rename to src/cse_machine/data_structures/stack.py index fcce52b..1ce721c 100644 --- a/cse_machine/data_structures/stack.py +++ b/src/cse_machine/data_structures/stack.py @@ -1,4 +1,4 @@ -# cse_machine/data_structures/stack.py +# src/cse_machine/data_structures/stack.py # Description # This module defines a custom stack class for the CSE (Compiler, Symbolic, Expression) machine. @@ -6,8 +6,8 @@ # Usage # This module can be imported and used to create a custom stack class for the CSE machine. -from utils.stack import Stack -from cse_machine.data_structures.enviroment import Environment +from src.utils.stack import Stack +from src.cse_machine.data_structures.enviroment import Environment class STACK(Stack): """ diff --git a/cse_machine/machine.py b/src/cse_machine/machine.py similarity index 96% rename from cse_machine/machine.py rename to src/cse_machine/machine.py index 1ed4c25..eaf73d2 100644 --- a/cse_machine/machine.py +++ b/src/cse_machine/machine.py @@ -1,4 +1,4 @@ -# cse_machine/machine.py +# src/cse_machine/machine.py """ Control Structure Environment (CSE) Machine for Executing RPAL Programs. @@ -26,16 +26,16 @@ """ -from errors_handling.cse_error_handler import CseErrorHandler -from cse_machine.data_structures.control_structure import ControlStructure -from cse_machine.data_structures.enviroment import Environment -from cse_machine.data_structures.stack import Stack -from cse_machine.utils.STlinearizer import Linearizer -from cse_machine.utils.util import add_table_data, print_cse_table , var_lookup , raw , add_table_data_decorator -from cse_machine.apply_operations.apply_bin import apply_binary -from cse_machine.apply_operations.apply_un import apply_unary -from utils.node import Node -from utils.control_structure_element import ControlStructureElement +from src.errors_handling.cse_error_handler import CseErrorHandler +from src.cse_machine.data_structures.control_structure import ControlStructure +from src.cse_machine.data_structures.enviroment import Environment +from src.cse_machine.data_structures.stack import Stack +from src.cse_machine.utils.STlinearizer import Linearizer +from src.cse_machine.utils.util import add_table_data, print_cse_table , var_lookup , raw , add_table_data_decorator +from src.cse_machine.apply_operations.apply_bin import apply_binary +from src.cse_machine.apply_operations.apply_un import apply_unary +from src.utils.node import Node +from src.utils.control_structure_element import ControlStructureElement class CSEMachine: """ diff --git a/cse_machine/utils/STlinearizer.py b/src/cse_machine/utils/STlinearizer.py similarity index 97% rename from cse_machine/utils/STlinearizer.py rename to src/cse_machine/utils/STlinearizer.py index e6b03cc..d828a01 100644 --- a/cse_machine/utils/STlinearizer.py +++ b/src/cse_machine/utils/STlinearizer.py @@ -7,8 +7,8 @@ # This module can be imported and used to create a linearizer class for the CSE machine. -from cse_machine.data_structures.control_structure import ControlStructure -from utils.control_structure_element import ControlStructureElement +from src.cse_machine.data_structures.control_structure import ControlStructure +from src.utils.control_structure_element import ControlStructureElement class Linearizer: diff --git a/cse_machine/utils/__init__.py b/src/cse_machine/utils/__init__.py similarity index 100% rename from cse_machine/utils/__init__.py rename to src/cse_machine/utils/__init__.py diff --git a/cse_machine/utils/util.py b/src/cse_machine/utils/util.py similarity index 100% rename from cse_machine/utils/util.py rename to src/cse_machine/utils/util.py diff --git a/errors_handling/__init__.py b/src/errors_handling/__init__.py similarity index 100% rename from errors_handling/__init__.py rename to src/errors_handling/__init__.py diff --git a/errors_handling/cse_error_handler.py b/src/errors_handling/cse_error_handler.py similarity index 94% rename from errors_handling/cse_error_handler.py rename to src/errors_handling/cse_error_handler.py index f450eb9..98338c2 100644 --- a/errors_handling/cse_error_handler.py +++ b/src/errors_handling/cse_error_handler.py @@ -1,4 +1,4 @@ -# error_handling/error_handler.py +# src/error_handling/error_handler.py # This is the main module for error handling. It provides a class ErrorHandler with static methods for handling errors. class CseErrorHandler: diff --git a/errors_handling/error_handler.py b/src/errors_handling/error_handler.py similarity index 92% rename from errors_handling/error_handler.py rename to src/errors_handling/error_handler.py index 86cb801..2458642 100644 --- a/errors_handling/error_handler.py +++ b/src/errors_handling/error_handler.py @@ -1,4 +1,4 @@ -# error_handling/error_handler.py +# src/error_handling/error_handler.py # This is the main module for error handling. It provides a class ErrorHandler with static methods for handling errors. class ErrorHandler: diff --git a/interpreter/__init__.py b/src/interpreter/__init__.py similarity index 100% rename from interpreter/__init__.py rename to src/interpreter/__init__.py diff --git a/interpreter/execution_engine.py b/src/interpreter/execution_engine.py similarity index 94% rename from interpreter/execution_engine.py rename to src/interpreter/execution_engine.py index 41b5276..0a1fe74 100644 --- a/interpreter/execution_engine.py +++ b/src/interpreter/execution_engine.py @@ -1,4 +1,4 @@ -# interpreter/execution_engine.py +# src/interpreter/execution_engine.py # Description: # This module serves as the main execution engine of the RPAL interpreter. It coordinates the interpretation process, including tokenization, filtering, parsing, and printing of tokens, filtered tokens, and the Abstract Syntax Tree (AST) of the program. @@ -14,17 +14,17 @@ # importing the necessary modules -from lexical_analyzer.scanner import Scanner -from screener.token_screener import Screener -from parser.parser_module import Parser -from parser.build_standard_tree import StandardTree -from cse_machine.machine import CSEMachine - -from cse_machine.data_structures.enviroment import Environment -import utils.token_printer as Token_printer -import utils.tree_list as Tree_list -import utils.tree_printer as Tree_printer -import utils.file_handler as File_handler +from src.lexical_analyzer.scanner import Scanner +from src.screener.token_screener import Screener +from src.parser.parser_module import Parser +from src.parser.build_standard_tree import StandardTree +from src.cse_machine.machine import CSEMachine + +from src.cse_machine.data_structures.enviroment import Environment +import src.utils.token_printer as Token_printer +import src.utils.tree_list as Tree_list +import src.utils.tree_printer as Tree_printer +import src.utils.file_handler as File_handler class Evaluator: diff --git a/lexical_analyzer/__init__.py b/src/lexical_analyzer/__init__.py similarity index 100% rename from lexical_analyzer/__init__.py rename to src/lexical_analyzer/__init__.py diff --git a/lexical_analyzer/scanner.py b/src/lexical_analyzer/scanner.py similarity index 94% rename from lexical_analyzer/scanner.py rename to src/lexical_analyzer/scanner.py index c27d61b..51297f3 100644 --- a/lexical_analyzer/scanner.py +++ b/src/lexical_analyzer/scanner.py @@ -1,4 +1,4 @@ -# lexical_analyzer/scanner.py +# src/lexical_analyzer/scanner.py # Description: # This file contains the Scanner class, which is responsible for scanning the input string and returning a list of tokens. @@ -12,11 +12,11 @@ import os import sys -from errors_handling.error_handler import ErrorHandler -from table_routines.char_map import CharMap -from table_routines.fsa_table import FSATable -from table_routines.accept_states import AcceptStates -from utils.tokens import Token +from src.errors_handling.error_handler import ErrorHandler +from src.table_routines.char_map import CharMap +from src.table_routines.fsa_table import FSATable +from src.table_routines.accept_states import AcceptStates +from src.utils.tokens import Token class Scanner: @@ -87,7 +87,7 @@ def token_scan(self, input_string): # Check if the input string ends with a newline character # and if not, print a warning message - check_ending_newline(input_string) + check_ending_newline(self.input_string) while self.index < len(input_string): character = input_string[self.index] diff --git a/parser/__init__.py b/src/parser/__init__.py similarity index 100% rename from parser/__init__.py rename to src/parser/__init__.py diff --git a/parser/build_standard_tree.py b/src/parser/build_standard_tree.py similarity index 98% rename from parser/build_standard_tree.py rename to src/parser/build_standard_tree.py index a2e67de..ea5e307 100644 --- a/parser/build_standard_tree.py +++ b/src/parser/build_standard_tree.py @@ -1,4 +1,4 @@ -# parser/build_standard_tree.py +# src/parser/build_standard_tree.py # Description: # This module contains the StandardTree class, which is used to build a standard tree from a given AST tree. @@ -9,8 +9,8 @@ # The build_standard_tree method applies a series of transformations to the input tree, resulting in a standard tree. # Each transformation corresponds to specific cases or patterns found in the input tree's structure. -from utils.node import Node -from errors_handling.error_handler import ErrorHandler +from src.utils.node import Node +from src.errors_handling.error_handler import ErrorHandler from copy import deepcopy diff --git a/parser/parser_module.py b/src/parser/parser_module.py similarity index 99% rename from parser/parser_module.py rename to src/parser/parser_module.py index 70a098b..f9b7327 100644 --- a/parser/parser_module.py +++ b/src/parser/parser_module.py @@ -1,4 +1,4 @@ -# parser/parser_module.py +# src/parser/parser_module.py # Description: # This module contains the Parser class, which is responsible for parsing the input code and constructing an Abstract Syntax Tree (AST). @@ -11,9 +11,9 @@ # Once parsing is complete, the status attribute of the Parser instance will indicate whether parsing was successful. # The constructed AST can be accessed using the stack attribute of the Parser instance. -from utils.node import Node -from utils.stack import Stack -from errors_handling.error_handler import ErrorHandler +from src.utils.node import Node +from src.utils.stack import Stack +from src.errors_handling.error_handler import ErrorHandler class Parser: """ diff --git a/screener/__init__.py b/src/screener/__init__.py similarity index 100% rename from screener/__init__.py rename to src/screener/__init__.py diff --git a/screener/token_screener.py b/src/screener/token_screener.py similarity index 94% rename from screener/token_screener.py rename to src/screener/token_screener.py index fad01e2..61090f5 100644 --- a/screener/token_screener.py +++ b/src/screener/token_screener.py @@ -1,4 +1,4 @@ -#screener/token_screener.py +# src/screener/token_screener.py #Description #This module contains the Screener class, which is responsible for filtering unwanted tokens from the input list of tokens. @@ -6,8 +6,8 @@ #Usage #The Screener class provides the screener() method, which removes unwanted tokens from the input list of tokens and returns the filtered list. -from table_routines.keywords import Keywords -from utils.tokens import Token +from src.table_routines.keywords import Keywords +from src.utils.tokens import Token class Screener: """ diff --git a/table_routines/__init__.py b/src/table_routines/__init__.py similarity index 100% rename from table_routines/__init__.py rename to src/table_routines/__init__.py diff --git a/table_routines/accept_states.py b/src/table_routines/accept_states.py similarity index 96% rename from table_routines/accept_states.py rename to src/table_routines/accept_states.py index 521e643..56d4a58 100644 --- a/table_routines/accept_states.py +++ b/src/table_routines/accept_states.py @@ -1,4 +1,4 @@ -#table_routines/accept_states.py +# src/table_routines/accept_states.py #Description # This module contains the AcceptStates class that represents the accept states for the Finite State Automaton (FSA). diff --git a/table_routines/char_map.py b/src/table_routines/char_map.py similarity index 98% rename from table_routines/char_map.py rename to src/table_routines/char_map.py index 13a257e..3ff4870 100644 --- a/table_routines/char_map.py +++ b/src/table_routines/char_map.py @@ -1,4 +1,4 @@ -#table_routines/char_map.py +# src/table_routines/char_map.py #Description # This module contains the CharMap class that represents a character mapping dictionary. diff --git a/table_routines/fsa_table.py b/src/table_routines/fsa_table.py similarity index 98% rename from table_routines/fsa_table.py rename to src/table_routines/fsa_table.py index ace1aa3..9978a46 100644 --- a/table_routines/fsa_table.py +++ b/src/table_routines/fsa_table.py @@ -1,4 +1,4 @@ -# table_routines/fsa_table.py +# src/table_routines/fsa_table.py # Description # This module contains the FSATable class that represents the transition table for the Finite State Automaton (FSA). diff --git a/table_routines/keywords.py b/src/table_routines/keywords.py similarity index 97% rename from table_routines/keywords.py rename to src/table_routines/keywords.py index c41db41..8e5151f 100644 --- a/table_routines/keywords.py +++ b/src/table_routines/keywords.py @@ -1,4 +1,4 @@ -#table_routines/keywords.py +# src/table_routines/keywords.py #Description # This module contains the Keywords class that represents the keywords used in the RPAL language. diff --git a/utils/__init__.py b/src/utils/__init__.py similarity index 100% rename from utils/__init__.py rename to src/utils/__init__.py diff --git a/utils/control_structure_element.py b/src/utils/control_structure_element.py similarity index 100% rename from utils/control_structure_element.py rename to src/utils/control_structure_element.py diff --git a/utils/file_handler.py b/src/utils/file_handler.py similarity index 97% rename from utils/file_handler.py rename to src/utils/file_handler.py index 41310c1..33d5db4 100644 --- a/utils/file_handler.py +++ b/src/utils/file_handler.py @@ -1,4 +1,4 @@ -#utils/file_handler.py +# src/utils/file_handler.py #Description: #This module contains utility functions for reading file content. diff --git a/utils/node.py b/src/utils/node.py similarity index 99% rename from utils/node.py rename to src/utils/node.py index bcdf6a5..0f5c2a3 100644 --- a/utils/node.py +++ b/src/utils/node.py @@ -1,4 +1,4 @@ -#utils/node.py +# src/utils/node.py #Description # This module contains the Node class, which represents a node in a binary tree data structure. diff --git a/utils/stack.py b/src/utils/stack.py similarity index 98% rename from utils/stack.py rename to src/utils/stack.py index f14107a..6b89014 100644 --- a/utils/stack.py +++ b/src/utils/stack.py @@ -1,4 +1,4 @@ -#utils/stack.py +# src/utils/stack.py #Description # This module implements the Stack data structure using a list as the underlying data structure. diff --git a/utils/token_printer.py b/src/utils/token_printer.py similarity index 85% rename from utils/token_printer.py rename to src/utils/token_printer.py index 1d5ecde..5872536 100644 --- a/utils/token_printer.py +++ b/src/utils/token_printer.py @@ -1,5 +1,5 @@ from typing import List, Optional -from utils.tokens import Token # Assuming Token class is defined in 'utils.token' +from src.utils.tokens import Token # Assuming Token class is defined in 'utils.token' def print_tokens(tokens: Optional[List[Token]]) -> None: """ diff --git a/utils/tokens.py b/src/utils/tokens.py similarity index 99% rename from utils/tokens.py rename to src/utils/tokens.py index c74a188..f00b7bb 100644 --- a/utils/tokens.py +++ b/src/utils/tokens.py @@ -1,4 +1,4 @@ -#utils/tokens.py +# src/utils/tokens.py # Description: # This module contains the Token class, which represents a token in a program. diff --git a/utils/tree_list.py b/src/utils/tree_list.py similarity index 97% rename from utils/tree_list.py rename to src/utils/tree_list.py index 7456d6e..d6caa4b 100644 --- a/utils/tree_list.py +++ b/src/utils/tree_list.py @@ -1,4 +1,4 @@ -# utils/list_tree.py +# src/utils/list_tree.py # Description # This function returns an tree as a list. diff --git a/utils/tree_printer.py b/src/utils/tree_printer.py similarity index 88% rename from utils/tree_printer.py rename to src/utils/tree_printer.py index bea4fc9..5db3a83 100644 --- a/utils/tree_printer.py +++ b/src/utils/tree_printer.py @@ -1,4 +1,4 @@ -#utils/tree_printer.py +# src/utils/tree_printer.py #Description # This module contains a function to print the tree with appropriate indentation. @@ -6,7 +6,7 @@ #Usage # This module provides the print_tree() function to print the AST with appropriate indentation. -from utils.tree_list import list_tree +from src.utils.tree_list import list_tree def print_tree(tree): """ Prints the Tree with appropriate indentation. diff --git a/test_ b/test_ index 3d34d34..de579f1 100644 --- a/test_ +++ b/test_ @@ -1,7 +1,3 @@ -let c = ((fn x.Istruthvalue x) ,3) -in -let f = c 1 -in -let x = c 2 -in -Print(f x) +let f n = rf n 1 1 where + rec rf n c r = c eq n+1 -> r | rf n (c+1) (c*r) +in Print(f 3 , f 5 ,f 7)