npm i minicaml_ts -g
to install minicaml_ts globally
npx minicaml_ts
to run minicaml_ts
- Basic usage
-
minicaml_ts file.mcl [options]
: execute file
-
- Options
-
-h --help
: Show this help message -
-v --version
: Show version -
--tokens
: Print tokens from lexer -
--ast
: \tPrint AST from parser
-
- Int
- String
- Boolean
-
string + string
: concatenation -
int + int
: addition -
int - int
: subtraction -
int * int
: multiplication -
int / int
: division
-
bool && bool
: and -
bool || bool
: or -
!bool
: not
-
int == int
: equal -
int != int
: not equal -
int < int
: less than -
int <= int
: less than or equal -
int > int
: greater than -
int >= int
: greater than or equal
-
let var_name = value in ...
: variable declaration
-
if (bool) { ... } else { ... }
: if statement
-
let fun_name = fun arg_name -> { ... } in ...
: function declaration -
letrec fun_name = fun arg_name -> { ... } in ...
: recursive function declaration
-
apply(fun_name arg)
: function call
-
iszero value
: check if value is zero
-
print expression
: print expression to console Raccomanded not to use, minicaml is a functional language
let a = 5 in
let b = 6 in
let f = fun x -> {
fun y -> {
x+y
}
} in
apply(apply(f a)b)
letrec factorial = fun n -> {
if (n == 0) {
1
} else {
n * apply(factorial (n-1))
}
} in
apply(factorial 5)
let sommatory = fun x -> {
letrec sommatory_aux = fun x -> {
if (x == 0) { 0 }
else { x + apply(sommatory_aux (x-1)) }
}
in apply(sommatoria_aux x)
} in apply(sommatoria 10)