do not abort when finding syntax error

This commit is contained in:
Yuichi Nishiwaki 2013-10-17 17:57:12 +09:00
parent d9e47bdd05
commit 5671c43a77
3 changed files with 15 additions and 2 deletions

View File

@ -69,5 +69,6 @@ pic_value pic_float_value(double);
#define pic_nil_p(v) ((v).type == PIC_VTYPE_NIL)
#define pic_true_p(v) ((v).type == PIC_VTYPE_TRUE)
#define pic_false_p(v) ((v).type == PIC_VTYPE_FALSE)
#define pic_undef_p(v) ((v).type == PIC_VTYPE_UNDEF)
#endif

View File

@ -3,6 +3,8 @@
#include "picrin.h"
#if PIC_ENABLE_READLINE
# include <string.h>
# include <stdlib.h>
# include <readline/readline.h>
# include <readline/history.h>
#endif
@ -84,6 +86,11 @@ main()
printf("]\n");
#endif
if (pic_undef_p(v)) {
pic_gc_arena_restore(pic, ai);
continue;
}
/* eval */
proc = pic_codegen(pic, v, pic->global_env);
v = pic_run(pic, proc, pic_nil_value());

View File

@ -4,6 +4,8 @@
#include "picrin.h"
#define YYERROR_VERBOSE 1
struct parser_control {
pic_state *pic;
pic_value value;
@ -29,7 +31,7 @@ struct parser_control {
program
:
{
p->value = pic_nil_value(p->pic);
p->value = pic_undef_value(p->pic);
}
| datum
{
@ -95,7 +97,6 @@ int
yyerror(struct parser_control *p, const char *msg)
{
puts(msg);
abort();
}
pic_value
@ -109,5 +110,9 @@ pic_parse(pic_state *pic, const char *str)
yyparse(&p);
yylex_destroy();
if (yynerrs > 0) {
p.value = pic_undef_value();
}
return p.value;
}