Scanner, Parser and Interpreter of a simple Functional Programming Language
No external libraries were used, you only need to have OCaml installed.
- This language only works with Integer Numbers
- IF, LET, IN, TEST, SUCCESS, FAIL, FUNC must be capitalized
- Variables can't contain Capital Letters
- Variables can't start with a Number
(exp) //brackets
exp + exp //sum
exp - exp //difference
exp * exp //multiplication
exp / exp //division
examples
5 - 2 //3
0/0 //NaN
2/0 //PLUS_INFINITY
5 - 1/0 //MINUS_INFINITY
2/0 - 3/0 //NaN
...
exp == exp
exp < exp
exp > exp
examples
3 + 2 == 5 //TRUE
1 == 0 //FALSE
1 > 0 //TRUE
1 < 0 //FALSE
...
TEST exp [ == | < | > ] exp
SUCCESS
exp
FAIL
exp
examples
TEST (5 + 5) / 2 == 5
SUCCES
10
FAIL
1/0
...
LET ide = exp
IN
exp
examples
LET x = 1
IN
LET y = 2
IN
x*x + y*y
...
FUNC fname (ide1, ide2, ...) =
exp
IN
exp
examples
FUNC sum (x, y) = x + y
IN
5 + 5
...
fname (exp1, exp2, ...)
examples
FUNC sum (x, y) = x + y
IN
TEST sum(2, 3) == 5
SUCCESS sum(2, 3)
FAIL 0
...