|
@ -3,22 +3,27 @@ static char* lispy_version = "Lispy version 0.0.0.0.6"; |
|
|
|
|
|
|
|
|
/* Parser language defintion */ |
|
|
/* Parser language defintion */ |
|
|
static char* parser = |
|
|
static char* parser = |
|
|
" \ |
|
|
|
|
|
number : /-?[0-9]+([.][0-9]*|[0-9]*)/ ; \ |
|
|
|
|
|
symbol : '+' | '-' | '*' | '/' | '%' | '^' | \ |
|
|
|
|
|
\"min\" | \"max\" ; \ |
|
|
|
|
|
sexpr : '(' <expr>* ')' ; \ |
|
|
|
|
|
qexpr : '{' <expr>* '}' ; \ |
|
|
|
|
|
expr : <number> | <symbol> | <sexpr> | <qexpr>; \ |
|
|
|
|
|
lispy : /^/ <expr>* /$/ ; \ |
|
|
|
|
|
|
|
|
" \ |
|
|
|
|
|
number : /-?[0-9]+([.][0-9]*|[0-9]*)/ ; \ |
|
|
|
|
|
symbol : \"list\" | \"head\" | \"tail\" | \"join\" | \ |
|
|
|
|
|
\"eval\" | '+' | '-' | '*' | '/' | '%' | \ |
|
|
|
|
|
'^' | \"min\" | \"max\" ; \ |
|
|
|
|
|
sexpr : '(' <expr>* ')' ; \ |
|
|
|
|
|
qexpr : '{' <expr>* '}' ; \ |
|
|
|
|
|
expr : <number> | <symbol> | <sexpr> | <qexpr>; \ |
|
|
|
|
|
lispy : /^/ <expr>* /$/ ; \ |
|
|
"; |
|
|
"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Declare new lval struct */ |
|
|
/* Declare new lval struct */ |
|
|
typedef struct lval { |
|
|
typedef struct lval { |
|
|
int type; |
|
|
int type; |
|
|
long num; |
|
|
|
|
|
double dec; |
|
|
|
|
|
|
|
|
/* only one of the two number/decimal is valid in a |
|
|
|
|
|
lval instance, so we can use an anonymous union */ |
|
|
|
|
|
union { |
|
|
|
|
|
long num; |
|
|
|
|
|
double dec; |
|
|
|
|
|
}; |
|
|
/* Error & symbol types have some string data */ |
|
|
/* Error & symbol types have some string data */ |
|
|
char* err; |
|
|
char* err; |
|
|
char* sym; |
|
|
char* sym; |
|
@ -29,7 +34,8 @@ typedef struct lval { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Create enumeration of possible lval types */ |
|
|
/* Create enumeration of possible lval types */ |
|
|
enum {LVAL_NUM, LVAL_DEC, LVAL_SYM, LVAL_SEXPR, LVAL_QEXPR, LVAL_ERR}; |
|
|
|
|
|
|
|
|
enum lval_types {LVAL_NUM, LVAL_DEC, LVAL_SYM, LVAL_SEXPR, |
|
|
|
|
|
LVAL_QEXPR, LVAL_ERR}; |
|
|
|
|
|
|
|
|
/* lval constructor functions */ |
|
|
/* lval constructor functions */ |
|
|
lval* lval_num(long x); |
|
|
lval* lval_num(long x); |
|
@ -52,11 +58,14 @@ lval* lval_read(mpc_ast_t* t); |
|
|
lval* lval_eval_sexpr(lval* v); |
|
|
lval* lval_eval_sexpr(lval* v); |
|
|
lval* lval_eval(lval* v); |
|
|
lval* lval_eval(lval* v); |
|
|
|
|
|
|
|
|
|
|
|
/* lval print functions */ |
|
|
void lval_expr_print(lval* v, char open, char close); |
|
|
void lval_expr_print(lval* v, char open, char close); |
|
|
void lval_print(lval* v); |
|
|
void lval_print(lval* v); |
|
|
void lval_println(lval* v); |
|
|
void lval_println(lval* v); |
|
|
|
|
|
|
|
|
|
|
|
/* language built-in operators and functions */ |
|
|
long min(long x, long y); |
|
|
long min(long x, long y); |
|
|
long max(long x, long y); |
|
|
long max(long x, long y); |
|
|
|
|
|
|
|
|
lval* builtin_op(lval* a, char* op); |
|
|
lval* builtin_op(lval* a, char* op); |
|
|
|
|
|
lval* builtin_head(lval* a); |
|
|
|
|
|
lval* builtin_tail(lval* a); |