int main(int argc, char **argv) { mpc_parser_t *plisp = plisp_set_grammar(); puts("PLisp v.0.0.0.1."); //Pablo Lisp lol puts("Press Ctrl-C to exit."); global = new_lenv(128); lenv_add_builtins(global); while ((input = linenoise("mylsp> ")) != NULL) { if (input[0] != '\0') { mpc_result_t r; linenoiseHistoryAdd(input); if ((mpc_parse("<stdin>", input, plisp, &r))) { lval *val = lval_eval(global, lval_read(r.output)); lval_println(val); lval_del(val); mpc_ast_delete(r.output); } else { mpc_err_print(r.error); mpc_err_delete(r.error); } } free(input); } lenv_del(global); plisp_cleanup_grammar(); return 0; }
int main(int argc, char* *argv){ init_parser(); lenv *e = lenv_new(); lenv_add_builtins(e); if (access(STD_LIB, F_OK) != -1){ lval *err = builtin_load(e, lval_add(lval_sexpr(), lval_str((char *)STD_LIB))); if (err->type == LVAL_ERR) lval_println(err); lval_del(err); } else { printf("Can't find stdlib at %s.\n", STD_LIB); } if (argc > 1){ for (int i = 1; i < argc; i++){ lval *args = lval_add(lval_sexpr(), lval_str(argv[i])); lval *x = builtin_load(e, args); if (x->type == LVAL_ERR) lval_println(x); lval_del(x); } } else { puts("Aroma Version v0.0.0.1"); puts("Press Ctrl+C to Exit."); char *input = NULL; mpc_result_t r; while (true){ input = readline(">>> "); if (strlen(input) < 1) { continue; } add_history(input); if (mpc_parse("<stdin>", input, Lispy, &r)){ /* mpc_ast_print(r.output); */ lval *x = lval_eval(e, lval_read(r.output)); lval_println(x); lval_del(x); mpc_ast_delete(r.output); } else { mpc_err_print(r.error); mpc_err_delete(r.error); } /* printf("%s\n", input); */ free(input); } } lenv_del(e); cleanup_parser(); return 0; }
int main(int argc, char *argv[]) { /* Create types */ mpc_parser_t *Number = mpc_new("number"); mpc_parser_t *Bool = mpc_new("bool"); mpc_parser_t *Symbol = mpc_new("symbol"); mpc_parser_t *Sexp = mpc_new("sexp"); mpc_parser_t *Qexp = mpc_new("qexp"); mpc_parser_t *Expr = mpc_new("expr"); mpc_parser_t *Smallisp = mpc_new("Smallisp"); /* Definintions */ mpca_lang(MPC_LANG_DEFAULT, "number : /-?[0-9]+/ ; " "bool : \"true\" | \"false\" ; " "symbol : /[a-zA-Z0-9_+\\-*\\/=<>!&]+/; " "sexp : '(' <expr>* ')'; " "qexp : '{' <expr>* '}'; " "expr : <number> | <bool> | <char> | <symbol> | <sexp> | <qexp>; " "Smallisp : /^/ <sexp>* /$/ ; ", Number, Bool, Symbol, Sexp, Qexp, Expr, Smallisp, NULL); puts("Lispy version 0.0.0.7\n"); puts("Press Ctrl-C to exit\n"); lenv *env = lenv_new(); lenv_add_builtins(env); while(1) { char *input = readline("slisp> "); add_history(input); mpc_result_t r; if (mpc_parse("<stdin>", input, Smallisp, &r)) { /* On success print AST */ lval *result = lval_eval(env, lval_read(r.output)); lval_println(result); lval_del(result); mpc_ast_print(r.output); mpc_ast_delete(r.output); } else { /* Print error */ mpc_err_print(r.error); mpc_err_print(r.error); } free(input); } lenv_del(env); mpc_cleanup(7, Number, Bool, Symbol, Sexp, Qexp, Expr, Smallisp); return 0; }
int main(int argc, char** argv){ puts("yafl Version 0.0.1"); puts("Press CTRL+C to Exit\n"); gen_parsers(); lenv* e = lenv_new(); lenv_add_builtins(e); lval* core = lval_add(lval_sexpr(), lval_str("src/yfl/core.yfl")); //printf("gets here"); lval* core_loaded = builtin_load(e, core); if(core_loaded->type == LVAL_ERR) {lval_println(core_loaded);} lval_del(core_loaded); if(argc >= 2){ //execute file for(int i = 1; i < argc; i++){ lval* args = lval_add(lval_sexpr(), lval_str(argv[i])); lval* x = builtin_load(e, args); if(x->type == LVAL_ERR) { lval_println(x); } lval_del(x); } } else{ //Start REPL while(1){ char* input = readline("yafl> "); add_history(input); mpc_result_t r; if(mpc_parse("<stdin>", input, Yafl, &r)){ lval* x = lval_eval(e, lval_read(r.output)); lval_println(x); lval_del(x); mpc_ast_delete(r.output); }else{ mpc_err_print(r.error); mpc_err_delete(r.error); } free(input); } } teardown_parsers(); return 0; }
int main(int argc, char** argv) { init_parser(); /* initialize environment */ lenv* e = lenv_new(); lenv_add_builtins(e); /* load standard library functions */ lval* x = builtin_load(e, lval_add(lval_sexpr(), lval_str("prelude.lsp"))); if (x->type == LVAL_ERR) { lval_println(x); } lval_del(x); if (argc >= 2) { /* read from command line */ parse_args(e, argc, argv); } else { /* interactive prompt */ say_hello(); while (1) { char* input = prompt(); lval* x = parse(input); if (x != NULL) { x = lval_eval(e, x); lval_println(x); lval_del(x); } free(input); } } /* cleanup */ lenv_del(e); free_parser(); return 0; }
int main(int argc, char** argv) { mpc_parser_t* Bool = mpc_new("bool"); mpc_parser_t* Number = mpc_new("number"); mpc_parser_t* Symbol = mpc_new("symbol"); mpc_parser_t* Sexp = mpc_new("sexp"); mpc_parser_t* Qexp = mpc_new("qexp"); mpc_parser_t* Expr = mpc_new("expr"); mpc_parser_t* Program = mpc_new("program"); mpca_lang(MPCA_LANG_DEFAULT, " \ bool : /#[tf]/ ; \ number : /-?[0-9]+/ ; \ symbol : /[a-zA-Z0-9_+\\-*\\/\\\\=<>!&\\^?]+/ ; \ sexp : '(' <expr>* ')' ; \ qexp : '{' <expr>* '}' ; \ expr : <bool> | <number> | <symbol> | \ <sexp> | <qexp> ; \ program : /^/ <expr> /$/ ; \ ", Bool, Number, Symbol, Sexp, Qexp, Expr, Program); puts("Welcome to gLenISP Version 0.0.0.1"); puts("You have 1000 parentheses remaining"); puts("Press Ctrl+c to Exit\n"); struct lenv* e = lenv_new(); lenv_add_builtins(e); while (1) { char* input = readline("glenisp> "); if (input == NULL) { break; } add_history(input); mpc_result_t r; if (mpc_parse("<stdin>", input, Program, &r)) { //mpc_ast_print(r.output); struct lval* x = lval_read(r.output); mpc_ast_delete(r.output); puts("Input:"); lval_print(x); putchar('\n'); struct lval* r = lval_eval(e, x); puts("Output:"); lval_print(r); putchar('\n'); lval_del(r); } else { mpc_err_print(r.error); mpc_err_delete(r.error); } free(input); } mpc_cleanup(6, Bool, Number, Symbol, Sexp, Qexp, Expr, Program); return 0; }