- Boolean: #t for true and #f for false
- Number: Signed integer from −( 2^31 ) to 2^31
- Function
Name | Symbol | Example |
---|---|---|
Plus | + | (+ 1 2) => 3 |
Minus | - | (- 1 2) => -1 |
Multiply | * | (* 2 3) => 6 |
Divide | / | (/ 6 3) => 2 |
Modulus | mod | (mod 8 3) => 2 |
Greater | > | (> 1 2) => #f |
Smaller | < | (< 1 2) => #t |
Equal | = | (= 1 2) => #f |
And | and | (and #t #f) => #f |
Or | or | (or #t #f) => #t |
Not | not | (not #t) => #f |
define | ||
fun | ||
if |
separator [ \t\n\r]
letter [a-z]
digit [0-9]
number 0|[1-9]{digit}*|-[1-9]{digit}*
ID {letter}({letter}|{digit}|"-")*
bool-val #[t|f]
- Program
PROGRAM : STMT STMTS
STMTS : STMT STMTS | {}
STMT : EXP | DEF-STMT | PRINT-STMT
PRINT_STMT : '(' print_num EXP ')'
| '(' print_bool EXP ')'
- Expression
EXPS : EXP EXPS | {}
EXP : bool_val | number | VARIABLE | NUM_OP | LOGICAL_OP | FUN_EXP | FUN_CALL | IF_EXP
- Numerical Operations
NUM_OP : PLUS | MINUS | MULTIPLY | DIVIDE | MODULES | GREATER | SMALLER | EQUAL
- Logical Operations
LOGICAL_OP : AND_OP | OR_OP | NOT_OP
- Define statement
DEF_STMT : '(' define VARIABLE EXP ')'
VARIABLE : id
- Function
FUN_EXP : '(' _fun FUN_ID FUN_BODY ')'
FUN_ID : '(' VARIABLE VARIABLES ')'
FUN_BODY : EXP
FUN_CALL : '(' FUN_EXP PARAM PARAMS ')'
| '(' FUN_NAME PARAM PARAMS ')'
PARAM : EXP
PARAMS : PARAM PARAMS
VARIABLES: VARIABLE VARIABLES
LAST_EXP : EXP
FUN_NAME : id
- If Expression
IF_EXP : '(' _if TEST_EXP THAN_EXP ELSE_EXP ')'
TEST_EXP: EXP
THAN_EXP: EXP
ELSE_EXP: EXP