Skip to content

Latest commit

 

History

History
168 lines (117 loc) · 5.54 KB

README.md

File metadata and controls

168 lines (117 loc) · 5.54 KB

Language Build Status Codecov

MATLAB Interpreter

A (simplified) MATLAB language interpreter.

Table of Contents

About

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:

  1. Reads and 'tokenizes' the input source code
  2. Parses the tokenized source code and produces an Abstract Syntax Tree (AST)
  3. Traverses and interprets the AST, executing expressions as it moves along the tree

Features

Current Version (v1.0)

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:

Example Input

radius = 1.5      % the radius
PI     = 3.14     % pi constant

% area of the circle
circle_area  = PI * (radius * radius)

Example Output

radius=1.5
PI=3.14
circle_area=7.065

TODO Work

  • 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]

Set Up

Follow these instructions to get the project running on your local machine for development and testing

Option 1: Virtual Environment

This option assumes python 3.5, pip, and make are installed in your machine.

  1. Install the virtual environment library (virtualenv) via pip:
$ pip install virtualenv
  1. Create a virtual environment for a project:
$ cd my_project_folder
$ virtualenv env
  1. 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

Option 2: Docker - Virtual Machine

  1. Download and install Docker on your machine

  2. Pull the following image for the virtual machine:

$ docker pull gpdowning/python
  1. 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
  1. 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

Running the Interpreter

There are two ways to execute the interpreter:

Command-line Interface

The interpreter can be launched in a command-line interface either on a stand alone GUI, or the terminal

$ python3 app.py

Running a script

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

Tools

This project uses the following Python software development tools:

Versioning

For the versions available, see the repository tags.

Author

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgements