| 
									
										
										
										
											2014-01-26 11:25:50 +00:00
										 |  |  | #include "../mpc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main(int argc, char **argv) { | 
					
						
							| 
									
										
										
										
											2015-11-07 16:57:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   mpc_result_t r; | 
					
						
							| 
									
										
										
										
											2014-01-26 11:25:50 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   mpc_parser_t* Adjective = mpc_new("adjective"); | 
					
						
							|  |  |  |   mpc_parser_t* Noun      = mpc_new("noun"); | 
					
						
							|  |  |  |   mpc_parser_t* Phrase    = mpc_new("phrase"); | 
					
						
							|  |  |  |   mpc_parser_t* Doge      = mpc_new("doge"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-15 16:06:59 +01:00
										 |  |  |   mpca_lang(MPCA_LANG_DEFAULT, | 
					
						
							| 
									
										
										
										
											2014-04-16 17:06:16 +01:00
										 |  |  |     " adjective : \"wow\" | \"many\" | \"so\" | \"such\";                 " | 
					
						
							|  |  |  |     " noun      : \"lisp\" | \"language\" | \"c\" | \"book\" | \"build\"; " | 
					
						
							|  |  |  |     " phrase    : <adjective> <noun>;                                     " | 
					
						
							|  |  |  |     " doge      : /^/ <phrase>* /$/;                                      ", | 
					
						
							| 
									
										
										
										
											2014-04-23 12:20:20 +01:00
										 |  |  |     Adjective, Noun, Phrase, Doge, NULL); | 
					
						
							| 
									
										
										
										
											2015-11-07 16:57:09 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2014-01-26 11:25:50 +00:00
										 |  |  |   if (argc > 1) { | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     if (mpc_parse_contents(argv[1], Doge, &r)) { | 
					
						
							|  |  |  |       mpc_ast_print(r.output); | 
					
						
							|  |  |  |       mpc_ast_delete(r.output); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       mpc_err_print(r.error); | 
					
						
							|  |  |  |       mpc_err_delete(r.error); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-11-07 16:57:09 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2014-01-26 11:25:50 +00:00
										 |  |  |   } else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (mpc_parse_pipe("<stdin>", stdin, Doge, &r)) { | 
					
						
							|  |  |  |       mpc_ast_print(r.output); | 
					
						
							|  |  |  |       mpc_ast_delete(r.output); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       mpc_err_print(r.error); | 
					
						
							|  |  |  |       mpc_err_delete(r.error); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   mpc_cleanup(4, Adjective, Noun, Phrase, Doge); | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2014-04-06 12:26:28 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 |