Skip to content

Commit

Permalink
Fixed gettoken for EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
sasagawa888 committed Nov 20, 2022
1 parent ae7cc9b commit 01d27d2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
8 changes: 7 additions & 1 deletion error.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,5 +303,11 @@ error (int errnum, char *fun, int arg)
fclose (GET_PORT (input_stream));
}
ESCFORG;
longjmp (buf, 1);
if (init_flag)
{
init_flag = 0;
longjmp (buf, 2);
}
else
longjmp (buf, 1);
}
6 changes: 2 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ int syntax_flag = YES; //syntaxerrors/2 YES=normal. NO=ignore syntax-errors
int string_term_flag = 0; //for string_term/2 0=normal, 1=readparse from string_term_buffer
int ctrl_c_flag = 0; //for ctrl_c to stop prove
int init_flag = 1; //for halt
int greeting_flag = 1; //for greeting message

//operator token
char operator[OPERATOR_NUMBER][5] = {
Expand Down Expand Up @@ -225,7 +224,6 @@ main (int argc, char *argv[])
if (!init_flag)
goto repl;

init_flag = 0;
home = getenv ("HOME");
strcpy (str, home);
strcat (str, "/nprolog/library/dcg.pl");
Expand Down Expand Up @@ -325,10 +323,10 @@ main (int argc, char *argv[])
}
}

if (greeting_flag)
if (init_flag)
{
printf ("N-Prolog Ver %1.2f\n", VERSION);
greeting_flag = 0;
init_flag = 0;
}

repl:
Expand Down
3 changes: 1 addition & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ NPL_OBJS = main.o \
error.o \
bignum.o \
compute.o \
edit.o \
sam.o
edit.o



Expand Down
1 change: 1 addition & 0 deletions npl.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ extern int listing_flag;
extern int prefix_flag;
extern int syntax_flag;
extern int string_term_flag;
extern int init_flag;

//------pointer----
extern int hp; //heap pointer
Expand Down
5 changes: 5 additions & 0 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,9 @@ gettoken (void)
{
if (c == EOL)
error (SYNTAX_ERR, "unexpected EOL in quoted atom ", NIL);

if (c == EOF)
error (SYNTAX_ERR, "unexpected EOF in quoted atom ", NIL);

if (c == '\\')
{
Expand Down Expand Up @@ -1078,6 +1081,8 @@ gettoken (void)
else
error (SYNTAX_ERR, "double $ in string token ", NIL);
}
else if(c == EOF)
error (SYNTAX_ERR, "not exist right $ in file ", NIL);
else
{
stok.buf[pos++] = c;
Expand Down
2 changes: 2 additions & 0 deletions tests/test4.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

ffAon(Nf)'

0 comments on commit 01d27d2

Please sign in to comment.