https://github.com/olekscode/tinylang
An interpreter for Tiny Language implemented in Scala
https://github.com/olekscode/tinylang
application evaluation interpreter
Last synced: 4 months ago
JSON representation
An interpreter for Tiny Language implemented in Scala
- Host: GitHub
- URL: https://github.com/olekscode/tinylang
- Owner: olekscode
- Created: 2018-04-18T03:29:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-18T04:09:40.000Z (over 7 years ago)
- Last Synced: 2025-02-11T11:41:29.688Z (11 months ago)
- Topics: application, evaluation, interpreter
- Language: Scala
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TinyLang
**Example:** Computing the factorial with TinyLang
```Scala
val machine = new Machine
val env = Map("x" -> 5)
val code = Sequence(
Assign("factorial", Number(1)),
While(
Less(Number(1), Var("x")),
Sequence(
Assign("factorial", Prod(Var("factorial"), Var("x"))),
Assign("x", Sum(Var("x"), Number(-1)))
)
)
)
machine.run(code, env)
//res0: Map[String,Any] = Map(x -> 1, factorial -> 120)
```