A simple functional language written using c++ templates.
coauthor: @Pawel494
-
Literals
Lit
- only allowed Fibbonaci numbers (non negative):Fib<0> = 0, Fib<1> = 1 ...
or logic values:True, False
,
example:Lit<Fib<0>>, Lit<True>
-
Variables
Var
:Var(const char*)
labels are string (1 to 6 signs) with letters (case insensitive) and digits,
example:Var("A"), Var("01234"), Var("Cdefg")
-
Arithmetic operations
Sum, Inc1, Inc10
Sum<...>
- multiple arguments sum (at least two),Inc1<Arg>
- addsFib<1>
toArg
,Inc10<Arg>
- addsFib<10
toArg
,
example:
Sum<Lit<Fib<0>>, Lit<Fib<1>>, Lit<Fib<3>>>, Inc1<Lit<Fib<0>>>
-
Comparison
Eq
-Eq<Left, Right>
compares value of Left with Right,
example:Eq<Lit<Fib<0>>, Lit<Fib<1>>>
-
Refernce
Ref
-Ref<Var>
return the value ofVar
,
example:Ref<Var("A")>
-
Expression
Let
-Let<Var, Value, Expression>
assignsValue
to theVar
and calculates givenExpression
,
example:Let<Var("A"), Lit<Fib<1>>, Ref<Var("A")>>
-
Expression
If
-If<Condition, Then, Else>
ifCondition
result is True then calculates value ofThen
otherwise value ofElse
is calculated, \ example:If<Lit<True>, Lit<Fib<1>>, Lit<Fib<0>>>
-
Expression
Lambda
-Lambda<Var, Body>
reprezents anonymous function with singe input argumentVar
and bodyBody
,
example:Lambda<Var("x"), Ref<Var("x")>>
-
Function invocation
Invoke
-Invoke<Fun, Param>
calculatesFun
result for the given input parameterParam
,
example:Invoke<Lambda<Var("x"), Ref<Var("x")>>, Lit<Fib<0>>>