adapted to allow for user intervention before error recovery

This commit is contained in:
ceriel 1987-02-16 21:38:52 +00:00
parent 255884b3fb
commit 3f6a8abe1b
5 changed files with 22 additions and 7 deletions

View file

@ -127,16 +127,23 @@ def { register string p; }
start = ff;
}
| C_LEXICAL C_IDENT
/*
* Declaration of a name for the lexical analyser.
* May appear only once
*/
{ if (!lexical) {
lexical = store(lextoken.t_string);
}
else error(linecount,"Duplicate %%lexical");
}
';'
/*
* Declaration of a name for the lexical analyser.
* May appear only once
*/
| C_ONERROR C_IDENT
{ if (! onerror) {
onerror = store(lextoken.t_string);
}
else error(linecount,"Duplicate %%onerror");
}
';'
| action(0) { acount++; }
/*
* A global C-declaration

View file

@ -63,6 +63,7 @@ extern struct order *sorder, *porder;
extern string e_noopen; /* Error message string used often */
extern int verbose; /* Level of verbosity */
extern string lexical; /* name of lexical analyser */
extern string onerror; /* name of user error handler */
extern int ntneeded; /* ntneeded = 1 if nonterminals are included
* in the sets.
*/

View file

@ -168,12 +168,13 @@ genrecovery() {
}
}
i = maxptr - setptr;
fprintf(fpars,
fprintf(f,
"#define LL_LEXI %s\n#define LL_SSIZE %d\n#define LL_NSETS %d\n#define LL_NTERMINALS %d\n",
lexical,
nbytes,
i > 0 ? i : 1,
ntokens);
if (onerror) fprintf(f,"#define LL_USERHOOK %s\n", onerror);
/* Now generate the routines that call the startsymbols */
for (st = start; st; st = st->ff_next) {
fputs(st->ff_name, f);
@ -471,8 +472,11 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; {
genpop(findindex(n->n_contains));
}
if (g_gettype(n->n_rule) == EORULE &&
safety == getntout(n) &&
! g_getnpar(p)) break;
safety <= getntout(n) &&
! g_getnpar(p)) {
safety = getntout(n);
break;
}
fprintf(f,"L%d_%s(\n",g_getnont(p), n->n_name);
if (g_getnpar(p)) {
controlline();

View file

@ -58,6 +58,7 @@ string f_input;
string e_noopen = "Cannot open %s";
int verbose;
string lexical;
string onerror;
int ntneeded;
int ntprint;
# ifndef NDEBUG

View file

@ -67,6 +67,7 @@ STATIC string vallookup();
%token C_PERSISTENT ;
%token C_FIRST ;
%token C_LEXICAL ;
%token C_ONERROR ;
%token C_AVOID ;
%token C_PREFER ;
%token C_DEFAULT ;
@ -100,6 +101,7 @@ static t_keyw resword[] = {
{ "first", C_FIRST },
{ "start", C_START },
{ "lexical", C_LEXICAL },
{ "onerror", C_ONERROR },
{ 0, 0 }
};