fixed problem with hex numbers, and use new PushBack feature

This commit is contained in:
ceriel 1989-04-11 11:40:49 +00:00
parent 4d5f61ce45
commit 6f8702a65e
4 changed files with 24 additions and 54 deletions

View file

@ -25,6 +25,5 @@ misc.c
options.c options.c
program.g program.g
statement.g statement.g
tab.c
tokenname.c tokenname.c
tokenname.h tokenname.h

View file

@ -23,8 +23,6 @@ struct token dot,
int idfsize = IDFSIZE; int idfsize = IDFSIZE;
int ForeignFlag; int ForeignFlag;
static int eofseen;
STATIC STATIC
SkipComment() SkipComment()
{ {
@ -111,10 +109,6 @@ getch()
} }
break; break;
} }
if (ch == EOI) {
eofseen = 1;
return '\n';
}
return ch; return ch;
} }
@ -135,7 +129,7 @@ CheckForLineDirective()
* Do not skip newlines * Do not skip newlines
*/ */
ch = getch(); ch = getch();
if (class(ch) == STNL) { if (class(ch) == STNL || class(ch) == STEOI) {
LineNumber++; LineNumber++;
error(s_error); error(s_error);
return; return;
@ -145,12 +139,13 @@ CheckForLineDirective()
i = i*10 + (ch - '0'); i = i*10 + (ch - '0');
ch = getch(); ch = getch();
} }
while (ch != '"' && class(ch) != STNL) ch = getch(); while (ch != '"' && class(ch) != STNL && class(ch) != STEOI)
ch = getch();
if (ch == '"') { if (ch == '"') {
c = buf; c = buf;
do { do {
*c++ = ch = getch(); *c++ = ch = getch();
if (class(ch) == STNL) { if (class(ch) == STNL || class(ch) == STEOI) {
LineNumber++; LineNumber++;
error(s_error); error(s_error);
return; return;
@ -159,15 +154,15 @@ CheckForLineDirective()
*--c = '\0'; *--c = '\0';
do { do {
ch = getch(); ch = getch();
} while (class(ch) != STNL); } while (class(ch) != STNL && class(ch) != STEOI);
/* /*
* Remember the file name * Remember the file name
*/ */
if (!eofseen && strcmp(FileName,buf)) { if (class(ch) == STNL && strcmp(FileName,buf)) {
FileName = Salloc(buf,(unsigned) strlen(buf) + 1); FileName = Salloc(buf,(unsigned) strlen(buf) + 1);
} }
} }
if (eofseen) { if (class(ch) == STEOI) {
error(s_error); error(s_error);
return; return;
} }
@ -191,20 +186,8 @@ LLlex()
return tk->tk_symb; return tk->tk_symb;
} }
again1:
if (eofseen) {
eofseen = 0;
ch = EOI;
}
else {
again: again:
LoadChar(ch); ch = getch();
if ((ch & 0200) && ch != EOI) {
error("non-ascii '\\%03o' read", ch & 0377);
goto again;
}
}
tk->tk_lineno = LineNumber; tk->tk_lineno = LineNumber;
switch (class(ch)) { switch (class(ch)) {
@ -212,7 +195,7 @@ again:
case STNL: case STNL:
LineNumber++; LineNumber++;
CheckForLineDirective(); CheckForLineDirective();
goto again1; goto again;
case STSKIP: case STSKIP:
goto again; goto again;
@ -231,8 +214,7 @@ again:
SkipComment(); SkipComment();
goto again; goto again;
} }
else if (nch == EOI) eofseen = 1; PushBack();
else PushBack();
} }
if (ch == '&') return tk->tk_symb = AND; if (ch == '&') return tk->tk_symb = AND;
if (ch == '~') return tk->tk_symb = NOT; if (ch == '~') return tk->tk_symb = NOT;
@ -272,8 +254,7 @@ again:
default : default :
crash("(LLlex, STCOMP)"); crash("(LLlex, STCOMP)");
} }
if (nch == EOI) eofseen = 1; PushBack();
else PushBack();
return tk->tk_symb = ch; return tk->tk_symb = ch;
case STIDF: case STIDF:
@ -286,8 +267,7 @@ again:
LoadChar(ch); LoadChar(ch);
} while(in_idf(ch)); } while(in_idf(ch));
if (ch == EOI) eofseen = 1; PushBack();
else PushBack();
*tag++ = '\0'; *tag++ = '\0';
tk->TOK_IDF = id = findidf(idfbuf); tk->TOK_IDF = id = findidf(idfbuf);
@ -329,9 +309,7 @@ again:
else if (ch == '.') state = OptReal; else if (ch == '.') state = OptReal;
else { else {
state = End; state = End;
if (ch == 'H') ; if (ch != 'H') PushBack();
else if (ch == EOI) eofseen = 1;
else PushBack();
} }
break; break;
@ -354,8 +332,7 @@ again:
state = End; state = End;
if (ch != 'H') { if (ch != 'H') {
lexerror("H expected after hex number"); lexerror("H expected after hex number");
if (ch == EOI) eofseen = 1; PushBack();
else PushBack();
} }
break; break;
@ -369,8 +346,7 @@ again:
state = Hex; state = Hex;
break; break;
} }
if (ch == EOI) eofseen = 1; PushBack();
else PushBack();
/* Fall through */ /* Fall through */
case End: case End:
@ -427,8 +403,7 @@ again:
} }
noscale: noscale:
if (ch == EOI) eofseen = 1; PushBack();
else PushBack();
return tk->tk_symb = REAL; return tk->tk_symb = REAL;

View file

@ -50,7 +50,7 @@ pr:
@pr Makefile $(GF) $(HFILES) $(CSRC) @pr Makefile $(GF) $(HFILES) $(CSRC)
clean: clean:
rm -f $(OBJ) $(GENFILES) LLfiles Cfiles tab LL.output m2mm rm -f $(OBJ) $(GENFILES) LLfiles Cfiles LL.output m2mm
lint: Cfiles lint: Cfiles
lint $(INCLUDES) $(LINTFLAGS) $(SRC) \ lint $(INCLUDES) $(LINTFLAGS) $(SRC) \
@ -73,11 +73,8 @@ tokenfile.g: tokenname.c make.tokfile
symbol2str.c: tokenname.c make.tokcase symbol2str.c: tokenname.c make.tokcase
make.tokcase <tokenname.c >symbol2str.c make.tokcase <tokenname.c >symbol2str.c
char.c: char.tab tab char.c: char.tab
tab -fchar.tab >char.c $(EMHOME)/bin/tabgen -fchar.tab >char.c
tab:
$(CC) tab.c -o tab
depend: Cfiles depend: Cfiles
sed '/^#AUTOAUTO/,$$d' Makefile > Makefile.new sed '/^#AUTOAUTO/,$$d' Makefile > Makefile.new

View file

@ -5,11 +5,10 @@
% %
% CHARACTER CLASSES % CHARACTER CLASSES
% %
%C %iSTGARB
STGARB:\000-\200 STSKIP: \t\013\014\015
STSKIP: \r\t STNL:\012
STNL:\012\013\014 STSIMP:-#&()*+,/;=[]^{|}~
STSIMP:#&()*+,-/;=[]^{|}~
STCOMP:.:<> STCOMP:.:<>
STIDF:a-zA-Z STIDF:a-zA-Z
STSTR:"' STSTR:"'
@ -40,7 +39,7 @@ STEOI:\200
% ISHEX % ISHEX
% %
%C %C
1:a-fA-F 1:A-F0-9
%Tchar ishex[] = { %Tchar ishex[] = {
%p %p
%T}; %T};