53 lines
973 B
Markdown
53 lines
973 B
Markdown
###IMProved
|
|
|
|
IMProved aims to build an interpreter for IMP (based on
|
|
[this](http://jayconrod.com/posts/37/a-simple-interpreter-from-scratch-in-python-part-1))
|
|
that is fully documented, occassionally improved and
|
|
embeddable into Python 3.
|
|
|
|
As you may notice, I am bad at documentation.
|
|
|
|
###Installation
|
|
|
|
The package has a setuptools toolchain, but is not (yet?) on pip,
|
|
which means that installation has to be performed manually. The
|
|
process looks like this:
|
|
|
|
```sh
|
|
git clone https://github.com/hellerve/IMProved
|
|
cd IMProved
|
|
python setup.py install
|
|
```
|
|
|
|
And you're good to go!
|
|
|
|
###Usage
|
|
|
|
Easy!
|
|
|
|
```python
|
|
import improved
|
|
|
|
improved.callIMP("n := 5")
|
|
# this will return a dictionary containing the key/value pair n/5
|
|
```
|
|
|
|
For a less contrived example, let's calculate the nth fibonacci number
|
|
where n is user input:
|
|
|
|
```python
|
|
import improved
|
|
|
|
x = """
|
|
n := read;
|
|
fib := 1;
|
|
while n > 1 do
|
|
fib := n * fib;
|
|
n := n -1
|
|
end;
|
|
write fib
|
|
"""
|
|
|
|
improved.callIMP(x)
|
|
```
|