better handling for scanning errors;
make Yap_error_output a global variable. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@693 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
35f1d9cf63
commit
bf37b29b4b
@ -12,7 +12,7 @@
|
|||||||
* Last rev: *
|
* Last rev: *
|
||||||
* mods: *
|
* mods: *
|
||||||
* comments: allocating space *
|
* comments: allocating space *
|
||||||
* version:$Id: alloc.c,v 1.28 2002-11-18 17:56:30 vsc Exp $ *
|
* version:$Id: alloc.c,v 1.29 2002-11-19 17:10:42 vsc Exp $ *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
#ifdef SCCS
|
#ifdef SCCS
|
||||||
static char SccsId[] = "%W% %G%";
|
static char SccsId[] = "%W% %G%";
|
||||||
@ -1071,11 +1071,11 @@ Yap_InitMemory(int Trail, int Heap, int Stack)
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#if SIZEOF_INT_P!=SIZEOF_INT
|
#if SIZEOF_INT_P!=SIZEOF_INT
|
||||||
if (output_msg) {
|
if (Yap_output_msg) {
|
||||||
fprintf(stderr, "HeapBase = %p GlobalBase = %p\n LocalBase = %p TrailTop = %p\n",
|
fprintf(stderr, "HeapBase = %p GlobalBase = %p\n LocalBase = %p TrailTop = %p\n",
|
||||||
Yap_HeapBase, Yap_GlobalBase, Yap_LocalBase, Yap_TrailTop);
|
Yap_HeapBase, Yap_GlobalBase, Yap_LocalBase, Yap_TrailTop);
|
||||||
#else
|
#else
|
||||||
if (output_msg) {
|
if (Yap_output_msg) {
|
||||||
fprintf(stderr, "HeapBase = %x GlobalBase = %x\n LocalBase = %x TrailTop = %x\n",
|
fprintf(stderr, "HeapBase = %x GlobalBase = %x\n LocalBase = %x TrailTop = %x\n",
|
||||||
(UInt) Yap_HeapBase, (UInt) Yap_GlobalBase,
|
(UInt) Yap_HeapBase, (UInt) Yap_GlobalBase,
|
||||||
(UInt) Yap_LocalBase, (UInt) Yap_TrailTop);
|
(UInt) Yap_LocalBase, (UInt) Yap_TrailTop);
|
||||||
|
@ -1024,7 +1024,7 @@ X_API void
|
|||||||
YAP_SetOutputMessage(void)
|
YAP_SetOutputMessage(void)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
output_msg = TRUE;
|
Yap_output_msg = TRUE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
C/init.c
7
C/init.c
@ -52,6 +52,8 @@ static char SccsId[] = "%W% %G%";
|
|||||||
|
|
||||||
#define LOGFILE "logfile"
|
#define LOGFILE "logfile"
|
||||||
|
|
||||||
|
int Yap_output_msg = FALSE;
|
||||||
|
|
||||||
#ifdef MACC
|
#ifdef MACC
|
||||||
STATIC_PROTO(void InTTYLine, (char *));
|
STATIC_PROTO(void InTTYLine, (char *));
|
||||||
#endif
|
#endif
|
||||||
@ -402,7 +404,7 @@ InitDebug(void)
|
|||||||
|
|
||||||
for (i = 1; i < 20; ++i)
|
for (i = 1; i < 20; ++i)
|
||||||
Yap_Option[i] = 0;
|
Yap_Option[i] = 0;
|
||||||
if (output_msg) {
|
if (Yap_output_msg) {
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
#if HAVE_ISATTY
|
#if HAVE_ISATTY
|
||||||
@ -967,9 +969,6 @@ InitCodes(void)
|
|||||||
heap_regs->term_prolog = MkAtomTerm(Yap_LookupAtom("prolog"));
|
heap_regs->term_prolog = MkAtomTerm(Yap_LookupAtom("prolog"));
|
||||||
heap_regs->term_refound_var = MkAtomTerm(Yap_LookupAtom("$I_FOUND_THE_VARIABLE_AGAIN"));
|
heap_regs->term_refound_var = MkAtomTerm(Yap_LookupAtom("$I_FOUND_THE_VARIABLE_AGAIN"));
|
||||||
heap_regs->dyn_array_list = NULL;
|
heap_regs->dyn_array_list = NULL;
|
||||||
#if DEBUG
|
|
||||||
heap_regs->debugger_output_msg = FALSE;
|
|
||||||
#endif
|
|
||||||
heap_regs->n_of_file_aliases = 0;
|
heap_regs->n_of_file_aliases = 0;
|
||||||
heap_regs->file_aliases = NULL;
|
heap_regs->file_aliases = NULL;
|
||||||
heap_regs->foreign_code_loaded = NULL;
|
heap_regs->foreign_code_loaded = NULL;
|
||||||
|
55
C/iopreds.c
55
C/iopreds.c
@ -819,7 +819,9 @@ extern void add_history (const char *);
|
|||||||
|
|
||||||
static char *ttyptr = NULL;
|
static char *ttyptr = NULL;
|
||||||
|
|
||||||
static char *_line = (char *) NULL;
|
|
||||||
|
|
||||||
|
static char *myrl_line = (char *) NULL;
|
||||||
|
|
||||||
static int cur_out_sno = 2;
|
static int cur_out_sno = 2;
|
||||||
|
|
||||||
@ -879,8 +881,8 @@ ReadlineGetc(int sno)
|
|||||||
|
|
||||||
while (ttyptr == NULL) {
|
while (ttyptr == NULL) {
|
||||||
/* Only sends a newline if we are at the start of a line */
|
/* Only sends a newline if we are at the start of a line */
|
||||||
if (_line != NULL && _line != (char *) EOF)
|
if (myrl_line != NULL && myrl_line != (char *) EOF)
|
||||||
free (_line);
|
free (myrl_line);
|
||||||
rl_instream = Stream[sno].u.file.file;
|
rl_instream = Stream[sno].u.file.file;
|
||||||
rl_outstream = Stream[cur_out_sno].u.file.file;
|
rl_outstream = Stream[cur_out_sno].u.file.file;
|
||||||
/* window of vulnerability opened */
|
/* window of vulnerability opened */
|
||||||
@ -894,20 +896,20 @@ ReadlineGetc(int sno)
|
|||||||
console_count_output_char(ch,Stream+StdErrStream,StdErrStream);
|
console_count_output_char(ch,Stream+StdErrStream,StdErrStream);
|
||||||
}
|
}
|
||||||
Yap_PrologMode |= ConsoleGetcMode;
|
Yap_PrologMode |= ConsoleGetcMode;
|
||||||
_line = readline (Prompt);
|
myrl_line = readline (Prompt);
|
||||||
} else {
|
} else {
|
||||||
Yap_PrologMode |= ConsoleGetcMode;
|
Yap_PrologMode |= ConsoleGetcMode;
|
||||||
_line = readline (NULL);
|
myrl_line = readline (NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ReadlinePos != ReadlineBuf) {
|
if (ReadlinePos != ReadlineBuf) {
|
||||||
ReadlinePos[0] = '\0';
|
ReadlinePos[0] = '\0';
|
||||||
ReadlinePos = ReadlineBuf;
|
ReadlinePos = ReadlineBuf;
|
||||||
Yap_PrologMode |= ConsoleGetcMode;
|
Yap_PrologMode |= ConsoleGetcMode;
|
||||||
_line = readline (ReadlineBuf);
|
myrl_line = readline (ReadlineBuf);
|
||||||
} else {
|
} else {
|
||||||
Yap_PrologMode |= ConsoleGetcMode;
|
Yap_PrologMode |= ConsoleGetcMode;
|
||||||
_line = readline (NULL);
|
myrl_line = readline (NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Do it the gnu way */
|
/* Do it the gnu way */
|
||||||
@ -927,11 +929,11 @@ ReadlineGetc(int sno)
|
|||||||
newline=FALSE;
|
newline=FALSE;
|
||||||
strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT);
|
strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT);
|
||||||
/* window of vulnerability closed */
|
/* window of vulnerability closed */
|
||||||
if (_line == NULL || _line == (char *) EOF)
|
if (myrl_line == NULL || myrl_line == (char *) EOF)
|
||||||
return(console_post_process_read_char(EOF, s, sno));
|
return(console_post_process_read_char(EOF, s, sno));
|
||||||
if (_line[0] != '\0' && _line[1] != '\0')
|
if (myrl_line[0] != '\0' && myrl_line[1] != '\0')
|
||||||
add_history (_line);
|
add_history (myrl_line);
|
||||||
ttyptr = _line;
|
ttyptr = myrl_line;
|
||||||
}
|
}
|
||||||
if (*ttyptr == '\0') {
|
if (*ttyptr == '\0') {
|
||||||
ttyptr = NIL;
|
ttyptr = NIL;
|
||||||
@ -950,18 +952,18 @@ Yap_GetCharForSIGINT(void)
|
|||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
#if HAVE_LIBREADLINE
|
#if HAVE_LIBREADLINE
|
||||||
if ((Yap_PrologMode & ConsoleGetcMode) && _line != (char *) NULL) {
|
if ((Yap_PrologMode & ConsoleGetcMode) && myrl_line != (char *) NULL) {
|
||||||
ch = _line[0];
|
ch = myrl_line[0];
|
||||||
free(_line);
|
free(myrl_line);
|
||||||
_line = NULL;
|
myrl_line = NULL;
|
||||||
} else {
|
} else {
|
||||||
_line = readline ("Action (h for help): ");
|
myrl_line = readline ("Action (h for help): ");
|
||||||
if (_line == (char *)NULL || _line == (char *)EOF) {
|
if (myrl_line == (char *)NULL || myrl_line == (char *)EOF) {
|
||||||
ch = EOF;
|
ch = EOF;
|
||||||
} else {
|
} else {
|
||||||
ch = _line[0];
|
ch = myrl_line[0];
|
||||||
free(_line);
|
free(myrl_line);
|
||||||
_line = NULL;
|
myrl_line = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -2788,6 +2790,8 @@ syntax_error (TokEntry * tokptr)
|
|||||||
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("string"),1),1,&t0);
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("string"),1),1,&t0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Error_tok:
|
||||||
|
break;
|
||||||
case Ponctuation_tok:
|
case Ponctuation_tok:
|
||||||
{
|
{
|
||||||
char s[2];
|
char s[2];
|
||||||
@ -2804,12 +2808,13 @@ syntax_error (TokEntry * tokptr)
|
|||||||
*error = TermNil;
|
*error = TermNil;
|
||||||
end = tokptr->TokPos;
|
end = tokptr->TokPos;
|
||||||
break;
|
break;
|
||||||
|
} else if (tokptr->Tok != Ord (Error_tok)) {
|
||||||
|
ts[1] = MkIntegerTerm(tokptr->TokPos);
|
||||||
|
*error =
|
||||||
|
MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("-"),2),2,ts),TermNil);
|
||||||
|
error = RepPair(*error)+1;
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
ts[1] = MkIntegerTerm(tokptr->TokPos);
|
|
||||||
*error =
|
|
||||||
MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("-"),2),2,ts),TermNil);
|
|
||||||
error = RepPair(*error)+1;
|
|
||||||
count++;
|
|
||||||
tokptr = tokptr->TokNext;
|
tokptr = tokptr->TokNext;
|
||||||
}
|
}
|
||||||
tf[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("read"),1),1,&ARG2);
|
tf[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("read"),1),1,&ARG2);
|
||||||
|
@ -504,6 +504,9 @@ ParseTerm(int prio)
|
|||||||
NextToken;
|
NextToken;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Error_tok:
|
||||||
|
FAIL;
|
||||||
|
|
||||||
case Ponctuation_tok:
|
case Ponctuation_tok:
|
||||||
switch ((int) Yap_tokptr->TokInfo) {
|
switch ((int) Yap_tokptr->TokInfo) {
|
||||||
case '(':
|
case '(':
|
||||||
|
45
C/scanner.c
45
C/scanner.c
@ -573,6 +573,11 @@ token(void)
|
|||||||
Yap_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
|
Yap_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (ch == 10 && yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) {
|
||||||
|
/* in ISO a new line terminates a string */
|
||||||
|
Yap_ErrorMessage = "layout character \n inside quotes";
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (ch == quote) {
|
if (ch == quote) {
|
||||||
my_get_quoted_ch();
|
my_get_quoted_ch();
|
||||||
if (ch != quote)
|
if (ch != quote)
|
||||||
@ -585,7 +590,6 @@ token(void)
|
|||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 10:
|
case 10:
|
||||||
/* don't add characters */
|
/* don't add characters */
|
||||||
printf("I am here\n");
|
|
||||||
my_get_quoted_ch();
|
my_get_quoted_ch();
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
@ -865,6 +869,23 @@ Yap_tokenizer(int (*Nxtch) (int), int (*QuotedNxtch) (int))
|
|||||||
t->TokInfo = (Term) TokenInfo;
|
t->TokInfo = (Term) TokenInfo;
|
||||||
t->TokPos = TokenPos;
|
t->TokPos = TokenPos;
|
||||||
t->TokNext = NIL;
|
t->TokNext = NIL;
|
||||||
|
if (Yap_ErrorMessage) {
|
||||||
|
/* insert an error token to inform the system on what happened */
|
||||||
|
TokEntry *e = (TokEntry *) AllocScannerMemory(sizeof(TokEntry));
|
||||||
|
if (e == NULL) {
|
||||||
|
Yap_ErrorMessage = "not enough stack space to read in term";
|
||||||
|
p->TokInfo = eot_tok;
|
||||||
|
/* serious error now */
|
||||||
|
return(l);
|
||||||
|
}
|
||||||
|
p->TokNext = e;
|
||||||
|
e->Tok = Error_tok;
|
||||||
|
e->TokInfo = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
|
||||||
|
e->TokPos = TokenPos;
|
||||||
|
e->TokNext = NIL;
|
||||||
|
Yap_ErrorMessage = NULL;
|
||||||
|
p = e;
|
||||||
|
}
|
||||||
} while (kind != eot_tok);
|
} while (kind != eot_tok);
|
||||||
return (l);
|
return (l);
|
||||||
}
|
}
|
||||||
@ -1308,6 +1329,11 @@ Yap_fast_tokenizer(void)
|
|||||||
Yap_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
|
Yap_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (ch == 10 && yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) {
|
||||||
|
/* in ISO a new line terminates a string */
|
||||||
|
Yap_ErrorMessage = "layout character \n inside quotes";
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (ch == quote) {
|
if (ch == quote) {
|
||||||
my_fgetch();
|
my_fgetch();
|
||||||
if (ch != quote)
|
if (ch != quote)
|
||||||
@ -1569,6 +1595,23 @@ Yap_fast_tokenizer(void)
|
|||||||
t->TokPos = TokenPos;
|
t->TokPos = TokenPos;
|
||||||
t->TokNext = NIL;
|
t->TokNext = NIL;
|
||||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||||
|
if (Yap_ErrorMessage) {
|
||||||
|
/* insert an error token to inform the system on what happened */
|
||||||
|
TokEntry *e = (TokEntry *) AllocScannerMemory(sizeof(TokEntry));
|
||||||
|
if (e == NULL) {
|
||||||
|
Yap_ErrorMessage = "not enough stack space to read in term";
|
||||||
|
p->TokInfo = eot_tok;
|
||||||
|
/* serious error now */
|
||||||
|
return(l);
|
||||||
|
}
|
||||||
|
p->TokNext = e;
|
||||||
|
e->Tok = Error_tok;
|
||||||
|
e->TokInfo = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
|
||||||
|
e->TokPos = TokenPos;
|
||||||
|
e->TokNext = NIL;
|
||||||
|
Yap_ErrorMessage = NULL;
|
||||||
|
p = e;
|
||||||
|
}
|
||||||
} while (kind != eot_tok);
|
} while (kind != eot_tok);
|
||||||
return (l);
|
return (l);
|
||||||
}
|
}
|
||||||
|
12
H/yapio.h
12
H/yapio.h
@ -172,9 +172,15 @@ extern char Yap_FileNameBuf[YAP_FILENAME_MAX], Yap_FileNameBuf2[YAP_FILENAME_MAX
|
|||||||
|
|
||||||
typedef YP_FILE *YP_File;
|
typedef YP_FILE *YP_File;
|
||||||
|
|
||||||
enum TokenKinds
|
enum TokenKinds {
|
||||||
{ Name_tok, Number_tok, Var_tok, String_tok, Ponctuation_tok,
|
Name_tok,
|
||||||
eot_tok };
|
Number_tok,
|
||||||
|
Var_tok,
|
||||||
|
String_tok,
|
||||||
|
Ponctuation_tok,
|
||||||
|
Error_tok,
|
||||||
|
eot_tok
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct TOKEN {
|
typedef struct TOKEN {
|
||||||
unsigned char Tok;
|
unsigned char Tok;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* File: Yap.h.m4 *
|
* File: Yap.h.m4 *
|
||||||
* mods: *
|
* mods: *
|
||||||
* comments: main header file for YAP *
|
* comments: main header file for YAP *
|
||||||
* version: $Id: Yap.h.m4,v 1.37 2002-11-18 18:17:13 vsc Exp $ *
|
* version: $Id: Yap.h.m4,v 1.38 2002-11-19 17:10:45 vsc Exp $ *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -778,8 +778,6 @@ typedef struct opcode_tab_entry {
|
|||||||
#define MAX_ERROR_MSG_SIZE 256
|
#define MAX_ERROR_MSG_SIZE 256
|
||||||
extern char Yap_ErrorSay[MAX_ERROR_MSG_SIZE];
|
extern char Yap_ErrorSay[MAX_ERROR_MSG_SIZE];
|
||||||
|
|
||||||
/********************* how to write a Prolog term ***********************/
|
|
||||||
|
|
||||||
/********* Prolog may be in several modes *******************************/
|
/********* Prolog may be in several modes *******************************/
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -801,6 +799,11 @@ extern int Yap_CritLocks;
|
|||||||
extern char **Yap_argv;
|
extern char **Yap_argv;
|
||||||
extern int Yap_argc;
|
extern int Yap_argc;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
/************** Debugging Support ***************************/
|
||||||
|
extern int Yap_output_msg;
|
||||||
|
#endif
|
||||||
|
|
||||||
/******************* number of modules ****************************/
|
/******************* number of modules ****************************/
|
||||||
|
|
||||||
#define MaxModules 256
|
#define MaxModules 256
|
||||||
|
Reference in New Issue
Block a user