https://github.com/yazaldefilimone/mini-interpreter
Crafting an interpreter with TypeScript.
https://github.com/yazaldefilimone/mini-interpreter
compiler interpreter programming-language
Last synced: about 1 year ago
JSON representation
Crafting an interpreter with TypeScript.
- Host: GitHub
- URL: https://github.com/yazaldefilimone/mini-interpreter
- Owner: yazaldefilimone
- License: mit
- Created: 2023-02-16T10:16:14.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-28T19:45:53.000Z (almost 3 years ago)
- Last Synced: 2025-03-08T05:51:42.816Z (about 1 year ago)
- Topics: compiler, interpreter, programming-language
- Language: TypeScript
- Homepage:
- Size: 92.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# start
```bash
git clone https://github.com/yazaldefilimonepinto/mini-interpreter.git
cd mini-interpreter
npm i
```
```bash
❯ npm run dev:file ./exemples/while.eva
````
# variable
```cljs
(var name "Yazalde Filimone")
(print name)
(set name "Yazalde")
(print name)
```
# scope
```cljs
(var name "Yazalde")
(begin
(print name)
(var last_name "Filimone")
(print last_name))
(print name)
(print last_name)
```
# lambda/arrow function(js)
use `def` to define function
```cljs
(def onClick (callback)
(begin
(var x 10)
(var y 20)
(callback (+ x y))))
(onClick (lambda (data) (* data 10)))
```
```cljs
((lambda (x) (* x x)) 2)
```
# for loop
```cljs
(for (var x 0) (< x 10)
(begin
(print x)
(set x (+ x 1))
x))
```
# while loop
```cljs
(var x 0)
(while (< x 10)
(begin
(print x)
(set x (+ x 1))
x))
```
# switch case
```cljs
(var n 10)
(switch
((< n 5) "< 5")
((> n 5) "> 5")
(else "no"))
```
# class
```cljs
(class Math null
(begin
(def constructor (this x y)
(begin
(set (prop this x) x)
(set (prop this y) y)
)
)
(def calc (this)
(+ (prop this x) (prop this y))
)
))
(var math (new Math 10 20))
((prop math calc) math)
```