Yet another language implementation using Elixir.
This repository provides the Rorty interpreter as an escript.
mix escript.build
generatesrorty
command in your current directory.
$ mix escript.build
Generated escript rorty with MIX_ENV=dev
mix escript.install
installsrorty
command into$HOME/.mix/escripts
.
$ mix escript.install
Generated escript rorty with MIX_ENV=dev
Are you sure you want to replace it with "rorty"? [Yn]
* creating /Users/kentaro/.mix/escripts/rorty
Evaluates the given code.
$ rorty -e "puts(1 + 1)"
2
Reads the content of the given file and evaluates it.
$ rorty -f examples/factorial.rorty
120
Parses the given code and shows the parse tree. This option must be used with either -e
or -f
option.
$ rorty -a -e '1+1'
[
%Rorty.Ast.Expr.Binary{
left: %Rorty.Ast.Expr.IntegerLiteral{value: 1},
operator: Rorty.Operator.Add,
right: %Rorty.Ast.Expr.IntegerLiteral{value: 1}
}
]
Shows the help message.
Rorty currently supports a basic grammar.
See lib/rorty/grammar.ex for details.
Factorial (factorial.rorty)
def factorial(n) {
if (n < 2) {
1
} else {
n * factorial(n - 1)
}
}
puts(factorial(5))
Fizz Buzz (fizzbuzz.rorty)
for (i in 1 to 100) {
if (i % 15 == 0) {
puts("FizzBuzz")
} else {
if (i % 5 == 0) {
puts("Buzz")
} else {
if (i % 3 == 0) {
puts("Fizz")
} else {
puts(i)
}
}
}
}
The author has been encouraged by the article published in WEB+DB PRESS Vol.125 to make my own language.