A (simplified) MATLAB language interpreter.
This interpreter directly executes instructions written in the MATLAB language. The interpreter was written in Python and it uses the following strategies for parsing and analyzing the statements in a MATLAB script:
- Reads and 'tokenizes' the input source code
- Parses the tokenized source code and produces an Abstract Syntax Tree (AST)
- Traverses and interprets the AST, executing expressions as it moves along the tree
Currently, the main feature of the interpreter is the ability to evaluate a series of simple mathematical expressions (+, -, *, /) and assign the result to an identifier (or variable). The interpreter 'remembers' that variable by maintaining it in scope and is then able to evaluate future expressions referencing such variable. Finally, the interpreter is also able to ignore MATLAB-style comments (%). Below is an example:
radius = 1.5 % the radius
PI = 3.14 % pi constant
% area of the circle
circle_area = PI * (radius * radius)
radius=1.5
PI=3.14
circle_area=7.065
-
Building a simple UI using wxPython- DONE -
Adding basic function support:
- Trigonometry: cos, sin, tan
- Arithmetic: power, floor, mod, round, abs
- Exponents: exp, log, sqrt
-
Matrix support
- Ex.
A = [1, 2, 3; 4, 5, 6; 7, 8, 9]
- Ex.
Follow these instructions to get the project running on your local machine for development and testing
This option assumes python 3.5, pip, and make are installed in your machine.
- Install the virtual environment library (virtualenv) via pip:
$ pip install virtualenv
- Create a virtual environment for a project:
$ cd my_project_folder
$ virtualenv env
- To begin using the virtual environment, it needs to be activated and the requirements need to be installed:
$ source env/bin/activate
$ pip install -r requirements.txt
-
Download and install Docker on your machine
-
Pull the following image for the virtual machine:
$ docker pull gpdowning/python
- Verify successful pull:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gpdowning/python latest 9e0a05a1bd40 7 days ago 783.1 MB
python 3.5.2 58528474c16a 2 weeks ago 683.2 MB
- Run docker within project directory:
$ cd my_project_folder
$ pwd
$ my_project_folder_full_path
$ docker run -it -v my_project_folder_full_path:/usr/user_name -w /usr/user_name gpdowning/python
There are two ways to execute the interpreter:
The interpreter can be launched in a command-line interface either on a stand alone GUI, or the terminal
$ python3 app.py
A '.m' script can also be evaluated by the interpreter. For instance, the example script RunInterpreter.in would be executed as follows:
$ python3 RunInterpreter.py < RunInterpreter.in
This project uses the following Python software development tools:
- Python 3 - The programming language
- Make - Automated builds
- Git - Source control
- Pylint - Code static analysis
- unittest - Unit testing
- coverage - Code coverage
- Pydoc - Automated documentation
- autopep8 - Automated formatting
- TravisCI - Continious integration
- wxPython - User Interface
For the versions available, see the repository tags.
This project is licensed under the MIT License - see the LICENSE.md file for details
- Inspired by rspivak and his 'Let's Build a Simple Pascal Interpreter' project
- The GUI and console 'shell' were based on the following libraries: wx.py.interpreter.py, wx.py.shell.py, and code.py