Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Fugoes/Final
An Interpreter
https://github.com/Fugoes/Final
Last synced: 2 months ago
JSON representation
An Interpreter
- Host: GitHub
- URL: https://github.com/Fugoes/Final
- Owner: Fugoes
- Created: 2016-12-03T14:31:21.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-30T08:41:17.000Z (over 7 years ago)
- Last Synced: 2024-08-02T01:25:31.974Z (6 months ago)
- Language: C++
- Size: 6.25 MB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Introduction
`Final` is a recursive acronym for `Final is not another lisp`. `Final` is a language, and this project is its interpreter. It is developed to hand in as homework...
# Build
```
$ git clone https://github.com/Fugoes/Final.git
$ cd Final
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .
```You could set the complier by passing the `-G` option.
To get release version, use `cmake -DCMAKE_BUILD_TYPE=Release ..` instead of `cmake ..`, and `cmake --build . --config Release` instead of `cmake --build .`.
The binary file will be `Final` under linux and `Final.exe` under Windows.
# Grammar
## Basic
* `(+ )`
For example:
```
>>> (+ 1 2 3)
6
>>> (+ (+ 1 2) 1)
4
```Note that the number of parameters can be arbitrary.
* `(- )`
Only accept two parameters and return ` - `.
* `(* )`
Similar to `+`.
* `(/ )`
* `(% )`
* `(> )`, `(< )`, `(= )`
Compare two expressions value.
* `(if )`
if `` is true, execute `` and return its value, else execute `` and return its value.
* `(begin ... )`
Execute `` to `` one by one, and return the last expression's value.
* `(print ... )`
* `(display ... )`
* `(runtime)`
This command will display all variables in your run time.
## Use variable
* `(assign a 5)`
Assign a to 5. Similar to `=` in python.
* `(set a 5)`
In `Final`, each bracket has its own variable scope, for example:
```
>>> (assign a 2)
true
>>> (print a)
2
true
>>> (begin (print a))
2
true
>>> (begin (assign a 3) (print a))
3
true
>>> (print a)
2
true
```The difference between `assign` and `set` could be demonstrated with this example:
```
>>> (assign a 2)
true
>>> (assign b a)
true
>>> (runtime)name : a
cited: 2
type : Integer
value: 2name : b
cited: 2
type : Integer
value: 2true
>>> (set a 4)
true
>>> (runtime)name : a
cited: 2
type : Integer
value: 4name : b
cited: 2
type : Integer
value: 4true
>>> (assign a 2)
true
>>> (runtime)name : a
cited: 1
type : Integer
value: 2name : b
cited: 1
type : Integer
value: 4true
```What's more, you could only using `set` on an integer.
* `(echo )`
Return the value of the expression.
## Define function
Here is an example:
```
>>> (function (fbi n)
... (if (< n 2)
... 1
... (+ (fbi (- n 1)) (fbi (- n 2)))))
true
>>> (fbi 10)
89
```In a function, you cannot use variables defined outside that function.
# License
`Final` is licensed under the [WTFPL](http://www.wtfpl.net/). Note that you shall not hand it in as your homework...