mumble

A Lisp written in C, following the *Build Your Own Lisp* book
Log | Files | Refs | README

doge.c (1151B)


      1 #include "../mpc.h"
      2 
      3 int main(int argc, char **argv) {
      4 
      5   mpc_result_t r;
      6   
      7   mpc_parser_t* Adjective = mpc_new("adjective");
      8   mpc_parser_t* Noun      = mpc_new("noun");
      9   mpc_parser_t* Phrase    = mpc_new("phrase");
     10   mpc_parser_t* Doge      = mpc_new("doge");
     11 
     12   mpca_lang(MPCA_LANG_DEFAULT,
     13     " adjective : \"wow\" | \"many\" | \"so\" | \"such\";                 "
     14     " noun      : \"lisp\" | \"language\" | \"c\" | \"book\" | \"build\"; "
     15     " phrase    : <adjective> <noun>;                                     "
     16     " doge      : /^/ <phrase>* /$/;                                      ",
     17     Adjective, Noun, Phrase, Doge, NULL);
     18   
     19   if (argc > 1) {
     20     
     21     if (mpc_parse_contents(argv[1], Doge, &r)) {
     22       mpc_ast_print(r.output);
     23       mpc_ast_delete(r.output);
     24     } else {
     25       mpc_err_print(r.error);
     26       mpc_err_delete(r.error);
     27     }
     28   
     29   } else {
     30 
     31     if (mpc_parse_pipe("<stdin>", stdin, Doge, &r)) {
     32       mpc_ast_print(r.output);
     33       mpc_ast_delete(r.output);
     34     } else {
     35       mpc_err_print(r.error);
     36       mpc_err_delete(r.error);
     37     }
     38   
     39   }
     40 
     41   mpc_cleanup(4, Adjective, Noun, Phrase, Doge);
     42   
     43   return 0;
     44   
     45 }
     46