Implementation of the arith language in python
Michael David Covarrubias Course CSE210A Programming Languages Assignment Homework 1
git clone https://github.com/mdcovarr/arith-python.git
Software was developed on CentOS 7
Required software in order to run arith-python software
- python3
- pip3
- pyinstaller
python3 already comes installed with Debian 10 however you will need to install pip3. pip3 will be used to install pyinstaller. You can do this manually via commands
sudo apt-get install python3-pip
sudo pip3 install pyinstaller
arith-python/bin, arith-python/libexec, arith-python/test.sh
- Teaching Assistants Testing Software
arith-python/src
- Soruce code of implementation
Class used by the main to run software.
Class used to read from stdin. Once string is read, we validate that there are only valid characters in the input. Else we throw an Exception. If all characters are valid, then we create tokens of input
Example
stdin: '9 * 9 + !'
stdout: Error Invalid Character!
Example
stdin: 4 * 8 + 11
tokens = ['4', '*', '8', '+', '11']
Class used to validate the format of the expression, like not having the expression end with an operator e.g., '+', '-', '*'. And making sure that there are no expressions with invalid format of operators e.g., '9 * - - - 9'. If expression is invalid, an Exception is thrown and the Abstract Syntax Tree is not formed. However, if the expression is validate the Parser class creates the Abstract Syntax Tree.
Example's
'9 * 8 - 2 -' // Invalid Expression
'9 * - * 10 + 2' // Invalid Expression
'-1 * -2 + 7' // Valid Expression
Class used to interpret the Abstract Syntax Tree and return the result of the expression.
Abstract class representing a node in the Abstract Syntac Tree (AST).
Class representing an integer node in the AST.
Class representing an operator node in the AST. An operator such as '+', '-' or '*'.
Enum class representing all valid tokens
class ASTToken(enum.Enum):
NONE = 1
INTEGER = 2
PLUS = 3
MINUS = 4
MULT = 5
Class to encapsulate the expression to be added to the currently built AST. Expression object encapsulates a ASTOperator and a ASTInteger.
If you have installed pip3 and python you can install pyinstaller with command:
sudo make init
executable will be created at arith-python/arith. To make arith executable run command:
make arith
Once you have built the arith executable to test arith executable with the cse210A-nsgtest repository tests run command:
./test.sh