mathinterpreter


Namemathinterpreter JSON
Version 0.2.1a0 PyPI version JSON
download
home_pageNone
SummaryAn interpreter for evaluating simple math expressions.
upload_time2024-06-06 14:41:17
maintainerMarco Barbosa, Henrique Guidi
docs_urlNone
authorMarco Barbosa, Henrique Guidi, David Callanan
requires_python>=3.10
licenseMIT License Copyright (c) 2020 David P. Callanan Copyright (c) 2024 Marco A. A. Barbosa, Henrique S. Guidi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords calculator interpreter math
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
![Static Badge](https://img.shields.io/badge/python-%3E%3D3.10-blue?style=flat&logo=python&logoColor=green&label=Python&color=green) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) ![Static Badge](https://img.shields.io/badge/unit_test-pytest-blue?style=flat&logo=pytest)

# Python - Math Interpreter

An interpreter, written from scratch in Python, that can evaluate simple math calculations, with a simple Read-Eval-Print-Loop (REPL) command line interface. This project is based on  [py-simple-math-interpreter](https://github.com/davidcallanan/py-simple-math-interpreter), by David Callanan and illustrates the use of software engineering techniques to evolve a prototype code into a professional software. 

Since our objective is to create an education/professional example we didn't change the original business logic, *i.e.*, we do not change the interpretor code. Besides the four basic operations ( addition, subtraction, multiplication, and division) we implemented the power operator `^` to calculate `a^b` and the modulo operator `%`.

## How to install and run the REPL


### Using pipx (recommended)

To use this project as a standalone command line tool install [pipx](https://pipx.pypa.io/stable/installation/) and run:

```bash
pipx install git+https://github.com/ScientificThought/py-math-interpreter
```

### Install using pip

If you want to install this package and use it as a library on another project you ccan use `pip` and a virtual environment manager.  There are many ways to do that but if you already know how to setup a virtual environment, probably you could proceed your way. 

In our development setup we use `venv`, which comes with python, on Ubuntu Linux. If you are new to software development, follow the steps we recommend below which is expect to work on any Linux Distribution.

Create a new directory and a new virtual environment for working with `mathinterpreter`:

```bash
mkdir mynewproject
cd mynewproject
python -m venv env
source env/bin/activate
```
Note that `mynewproject` could be any name of your choice and that instead of using `source` you could simply use the `.` command. After activating your new environment, install the package from source using pip:

```bash
python -m pip install git+https://github.com/ScientificThought/py-math-interpreter.git
```
At this point you can run the REPL, from the directory in which you installed the package by typing `mathinterpreter` in your terminal. This will open the REPL terminal of the interpreter and you can now use it for evaluating math expressions:
```
$ mathinterpreter
calc > 1+1        
2.0
calc > (3.0+2*2)/3
2.3333333333333335
calc > q
$ 
```
Just type `q` or `quit` followed by enter  in the REPL to return to your shell. That's it.

### How to use this package as Python module

You can import the module `mathinterpreter` from your python code and use the function `calc` to evaluate expressions, as in the following:
```python
from mathinterpreter import calc

value = calc('1 + 3*(5*2+1)/2')
print(value)
```
To using `mathinterpreter` as a library you will need to import the Lexer, the Parser, and the Interpreter classes. For understanding how the interpreter works we recommend you to look the files `mathinterpreter/__main__.py` and `mathinterpreter/calculate.py`, which implement the REPL.

## What we have done and what we are doing

### Current implementation includes:**

*Version*: 2024.05.07
- library `mathinterpreter` (Lexer, Parser, Interpreter, and a `calc()`, to simplify calculations);
- a simple command line interface, `mathinterpreter`, using a simple REPL;


### Project Software Stack

- pip: for package installation frontend;
- setuptools: for package installation backend;
- pytest: for unit tests;
- black: for automatic code formatting;
- GitHub Action Scripts: for CI Automation;

### Planned improvements
We track feature requests with issues. But we aim to implement:

- implement code coverage;
- expand the tests suit;
- improve the cli:
    - use `argparse` to improve the cli usage, allowing the user to call `mathinterpreter "1+1"`, for example.    
    - make the REPL more user friendly;

## Contributing

Please take a look on our [contributing guide](doc/guides/contributing.md).

## Who we are?

We are [Marco Barbosa](@aureliobarbosa) and [Henrique Guidi](@hsguidi), colleagues which got 
involved with computation while doing PhD in Physics at University of São Paulo. 

ScientificThoughts was created as an online place to develop interesting small projects to improving 
our software engineering techniques. Want to join us? Just contact us.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "mathinterpreter",
    "maintainer": "Marco Barbosa, Henrique Guidi",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "calculator, interpreter, math",
    "author": "Marco Barbosa, Henrique Guidi, David Callanan",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/02/1a/6e31d1fe38934a01b02d6c8f016da3e6289e4daf041fcad48b4aa6cb11e2/mathinterpreter-0.2.1a0.tar.gz",
    "platform": null,
    "description": "\n![Static Badge](https://img.shields.io/badge/python-%3E%3D3.10-blue?style=flat&logo=python&logoColor=green&label=Python&color=green) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) ![Static Badge](https://img.shields.io/badge/unit_test-pytest-blue?style=flat&logo=pytest)\n\n# Python - Math Interpreter\n\nAn interpreter, written from scratch in Python, that can evaluate simple math calculations, with a simple Read-Eval-Print-Loop (REPL) command line interface. This project is based on  [py-simple-math-interpreter](https://github.com/davidcallanan/py-simple-math-interpreter), by David Callanan and illustrates the use of software engineering techniques to evolve a prototype code into a professional software. \n\nSince our objective is to create an education/professional example we didn't change the original business logic, *i.e.*, we do not change the interpretor code. Besides the four basic operations ( addition, subtraction, multiplication, and division) we implemented the power operator `^` to calculate `a^b` and the modulo operator `%`.\n\n## How to install and run the REPL\n\n\n### Using pipx (recommended)\n\nTo use this project as a standalone command line tool install [pipx](https://pipx.pypa.io/stable/installation/) and run:\n\n```bash\npipx install git+https://github.com/ScientificThought/py-math-interpreter\n```\n\n### Install using pip\n\nIf you want to install this package and use it as a library on another project you ccan use `pip` and a virtual environment manager.  There are many ways to do that but if you already know how to setup a virtual environment, probably you could proceed your way. \n\nIn our development setup we use `venv`, which comes with python, on Ubuntu Linux. If you are new to software development, follow the steps we recommend below which is expect to work on any Linux Distribution.\n\nCreate a new directory and a new virtual environment for working with `mathinterpreter`:\n\n```bash\nmkdir mynewproject\ncd mynewproject\npython -m venv env\nsource env/bin/activate\n```\nNote that `mynewproject` could be any name of your choice and that instead of using `source` you could simply use the `.` command. After activating your new environment, install the package from source using pip:\n\n```bash\npython -m pip install git+https://github.com/ScientificThought/py-math-interpreter.git\n```\nAt this point you can run the REPL, from the directory in which you installed the package by typing `mathinterpreter` in your terminal. This will open the REPL terminal of the interpreter and you can now use it for evaluating math expressions:\n```\n$ mathinterpreter\ncalc > 1+1        \n2.0\ncalc > (3.0+2*2)/3\n2.3333333333333335\ncalc > q\n$ \n```\nJust type `q` or `quit` followed by enter  in the REPL to return to your shell. That's it.\n\n### How to use this package as Python module\n\nYou can import the module `mathinterpreter` from your python code and use the function `calc` to evaluate expressions, as in the following:\n```python\nfrom mathinterpreter import calc\n\nvalue = calc('1 + 3*(5*2+1)/2')\nprint(value)\n```\nTo using `mathinterpreter` as a library you will need to import the Lexer, the Parser, and the Interpreter classes. For understanding how the interpreter works we recommend you to look the files `mathinterpreter/__main__.py` and `mathinterpreter/calculate.py`, which implement the REPL.\n\n## What we have done and what we are doing\n\n### Current implementation includes:**\n\n*Version*: 2024.05.07\n- library `mathinterpreter` (Lexer, Parser, Interpreter, and a `calc()`, to simplify calculations);\n- a simple command line interface, `mathinterpreter`, using a simple REPL;\n\n\n### Project Software Stack\n\n- pip: for package installation frontend;\n- setuptools: for package installation backend;\n- pytest: for unit tests;\n- black: for automatic code formatting;\n- GitHub Action Scripts: for CI Automation;\n\n### Planned improvements\nWe track feature requests with issues. But we aim to implement:\n\n- implement code coverage;\n- expand the tests suit;\n- improve the cli:\n    - use `argparse` to improve the cli usage, allowing the user to call `mathinterpreter \"1+1\"`, for example.    \n    - make the REPL more user friendly;\n\n## Contributing\n\nPlease take a look on our [contributing guide](doc/guides/contributing.md).\n\n## Who we are?\n\nWe are [Marco Barbosa](@aureliobarbosa) and [Henrique Guidi](@hsguidi), colleagues which got \ninvolved with computation while doing PhD in Physics at University of S\u00e3o Paulo. \n\nScientificThoughts was created as an online place to develop interesting small projects to improving \nour software engineering techniques. Want to join us? Just contact us.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2020 David P. Callanan Copyright (c) 2024 Marco A. A. Barbosa, Henrique S. Guidi  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "An interpreter for evaluating simple math expressions.",
    "version": "0.2.1a0",
    "project_urls": {
        "repository": "https://github.com/ScientificThought/mathinterpreter"
    },
    "split_keywords": [
        "calculator",
        " interpreter",
        " math"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f9f262e9c91279662028d2a9867a850c67f17d81b8101e9525f5cddc18ef723d",
                "md5": "a92cf2312186786d01a02ece7c4451ee",
                "sha256": "d3d5975359ce876ea895408c3f5803029a1c73d5e1dcd648ad12d131b1218c7e"
            },
            "downloads": -1,
            "filename": "mathinterpreter-0.2.1a0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a92cf2312186786d01a02ece7c4451ee",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 10689,
            "upload_time": "2024-06-06T14:41:15",
            "upload_time_iso_8601": "2024-06-06T14:41:15.079916Z",
            "url": "https://files.pythonhosted.org/packages/f9/f2/62e9c91279662028d2a9867a850c67f17d81b8101e9525f5cddc18ef723d/mathinterpreter-0.2.1a0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "021a6e31d1fe38934a01b02d6c8f016da3e6289e4daf041fcad48b4aa6cb11e2",
                "md5": "e614a966d87a7a3eeb52f9a607e3602b",
                "sha256": "df4c5b5ca5588a76ffab13a501ee360a7472b7491011b82823fcaad8b4562828"
            },
            "downloads": -1,
            "filename": "mathinterpreter-0.2.1a0.tar.gz",
            "has_sig": false,
            "md5_digest": "e614a966d87a7a3eeb52f9a607e3602b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 16254,
            "upload_time": "2024-06-06T14:41:17",
            "upload_time_iso_8601": "2024-06-06T14:41:17.643288Z",
            "url": "https://files.pythonhosted.org/packages/02/1a/6e31d1fe38934a01b02d6c8f016da3e6289e4daf041fcad48b4aa6cb11e2/mathinterpreter-0.2.1a0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-06 14:41:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ScientificThought",
    "github_project": "mathinterpreter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mathinterpreter"
}
        
Elapsed time: 0.27070s