Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/NicholasLYang/for-the-graal
A simple but absurd language implemented in Ruby-Java-JavaScript
https://github.com/NicholasLYang/for-the-graal
Last synced: about 1 month ago
JSON representation
A simple but absurd language implemented in Ruby-Java-JavaScript
- Host: GitHub
- URL: https://github.com/NicholasLYang/for-the-graal
- Owner: NicholasLYang
- Created: 2021-04-16T23:03:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-04-17T05:54:18.000Z (over 3 years ago)
- Last Synced: 2024-08-04T08:02:40.402Z (5 months ago)
- Language: Java
- Size: 21.5 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- Open-Source-Ruby-and-Rails-Apps - for-the-graal - Java-JavaScript 🔥 🚀 (Happy Exploring 🤘)
README
# For The Graal
This is a fun absurd interpreter for a mini language.
The parser is implemented in Ruby using a s-expression parser SXP,
the type checker/compiler is written in Java and the interpreter in
JavaScript## Language
A program consists of a list of statements. Currently, there are functions,
if statements, let statements and print statements.The language supports numbers (double precision floating point), strings and bools.
Functions are defined using `fun`. They take in a name, a list of params,
and a body. Params are a name/type pair. The function body is a list of
statements.
```
(
(fun foo ((n number) (b number))
(
(print (* n b))
)
)
)
```Let statements are defined using `let`. They take in a name and an expression.
```
(
(let a (* 25 (/ 30 10)))
)
```Print statements are defined using `print`. They take in a single expression.
```
(
(print "foobar")
)
```If statements are defined using `if`. They take in a condition, and
a then block with an optional else block.
```
(
(if (< 10 20) (print "10 < 20"))
(if (< 21 20) (print "21 < 20") (print "21 > 20"))
)
```
## Running
Before running, you should have Graal with Ruby, JavaScript and Java
all installed. Also, please make sure to run `bundle install`
to install `sxp`.Compiling is simply:
```
javac -Xlint:unchecked -classpath src/ src/Main.java
```
and running:
```
java -classpath src/ Main
```Where `` is a file containing the source code.
Check out `examples/` for, well, examples.`javac` and `java` must be the Graal versions, of course.
NOTE: You must run the code from the root directory as it loads files
via relative paths.