Made acceptable for flex

This commit is contained in:
ceriel 1991-01-11 14:28:59 +00:00
parent 0b26bdf5fb
commit efa476b5b3
3 changed files with 31 additions and 53 deletions

View file

@ -10,10 +10,6 @@ static char rcsid2[]="$Header$";
* Author: Hans van Staveren * Author: Hans van Staveren
*/ */
#undef input
#undef output
#undef unput
#define MAXBACKUP 50 #define MAXBACKUP 50
#include <stdio.h> #include <stdio.h>
@ -25,6 +21,10 @@ static char rcsid2[]="$Header$";
#include "booth.h" #include "booth.h"
#include "y.tab.h" #include "y.tab.h"
int lineno = 1;
extern char *iname;
extern char *scopy();
%} %}
%p 2000 %p 2000
@ -113,8 +113,8 @@ return return(RETURN);
} }
[a-z] {yylval.yy_char = yytext[0]; return(LCASELETTER);} [a-z] {yylval.yy_char = yytext[0]; return(LCASELETTER);}
[0-9]* {yylval.yy_int = atoi(yytext);return(NUMBER);} [0-9]* {yylval.yy_int = atoi(yytext);return(NUMBER);}
(\"|"%)") { char *p; int c,tipe; (\"|"%)") { char *p; int c,tipe; char stringbuf[BUFSIZ];
p=yytext; p=stringbuf;
for (;;) { for (;;) {
c = input(); c = input();
switch(c) { switch(c) {
@ -138,54 +138,30 @@ return return(RETURN);
} }
endstr: endstr:
*p++ = 0; *p++ = 0;
yylval.yy_string = scopy(yytext); yylval.yy_string = scopy(stringbuf);
return(tipe); return(tipe);
} }
^\#.*$ | ^\#(line)?[ \t]*[0-9]+[ \t]+\".*\".*$ {
[ \t]* | int ind,ind2;
\n ; for (ind=0; yytext[ind] < '0' || yytext[ind]>'9'; ind++)
;
lineno=atoi(&yytext[ind])-1;
for(;yytext[ind]!='"';ind++)
;
for(ind2=ind+1;yytext[ind2]!='"';ind2++)
;
yytext[ind2]=0;
if (!iname || strcmp(yytext+ind+1,iname)!=0)
iname=scopy(yytext+ind+1);
}
[ \t]* ;
\n { lineno++; }
. return(yytext[0]); . return(yytext[0]);
%% %%
char linebuf[256];
char prevbuf[256];
int linep;
int linepos; /* corrected for tabs */
char charstack[MAXBACKUP];
int nbackup=0;
output(c) {
assert(0);
}
input() {
if(nbackup)
return(charstack[--nbackup]);
if(linebuf[linep]==0) {
strcpy(prevbuf,linebuf);
if(fgets(linebuf,256,stdin)==NULL)
return(0);
lino++;
linepos=linep=0;
}
if (linebuf[linep] == '\t')
linepos = (linepos+8) & ~07;
else linepos++;
return(linebuf[linep++]);
}
unput(c) {
chktabsiz(nbackup,MAXBACKUP,"Lexical backup table");
charstack[nbackup++] = c;
}
yyerror(s,a1,a2,a3,a4) string s; { yyerror(s,a1,a2,a3,a4) string s; {
fprintf(stderr,"%d\t%s%d\t%s\t%*c ",lino-1,prevbuf,lino,linebuf, fprintf(stderr,"\"%s\", line %d:",iname ? iname : "",lineno);
linepos-1,'^');
fprintf(stderr,s,a1,a2,a3,a4); fprintf(stderr,s,a1,a2,a3,a4);
fprintf(stderr,"\n"); fprintf(stderr,"\n");
nerrors++; nerrors++;

View file

@ -12,6 +12,7 @@ int myatoi();
int lineno=1; int lineno=1;
extern char *filename; extern char *filename;
#undef yywrap
%} %}
%% %%
@ -39,11 +40,6 @@ extern char *filename;
if (strcmp(yytext+ind+1,filename)!=0) if (strcmp(yytext+ind+1,filename)!=0)
filename=mystrcpy(yytext+ind+1); filename=mystrcpy(yytext+ind+1);
} }
[a-z]{3} { if (!emhere || (yylval.yy_int=mlookup(yytext))==0)
REJECT;
return(EMMNEM);
}
"==" return(CMPEQ); "==" return(CMPEQ);
"!=" return(CMPNE); "!=" return(CMPNE);
"<" return(CMPLT); "<" return(CMPLT);
@ -65,6 +61,11 @@ extern char *filename;
\%[a-z] { yylval.yy_int = yytext[1]-'a'; return(ALLREG); } \%[a-z] { yylval.yy_int = yytext[1]-'a'; return(ALLREG); }
[0-9]+|0x[0-9A-Fa-f]+ { yylval.yy_int = myatoi(yytext); return(NUMBER); } [0-9]+|0x[0-9A-Fa-f]+ { yylval.yy_int = myatoi(yytext); return(NUMBER); }
[_A-Za-z][_A-Za-z0-9]* { register symbol *sy_p; [_A-Za-z][_A-Za-z0-9]* { register symbol *sy_p;
if (yyleng==3 &&
emhere &&
(yylval.yy_int=mlookup(yytext))!=0) {
return(EMMNEM);
}
if ((sy_p=lookup(yytext,symkeyw,justlooking))!=0) if ((sy_p=lookup(yytext,symkeyw,justlooking))!=0)
return(sy_p->sy_value.syv_keywno); return(sy_p->sy_value.syv_keywno);
yylval.yy_str = mystrcpy(yytext); return(IDENT); yylval.yy_str = mystrcpy(yytext); return(IDENT);

View file

@ -27,7 +27,8 @@ rom return(ROM);
int m; int m;
m = mlookup(yytext); m = mlookup(yytext);
if (m==0) { if (m==0) {
REJECT; yyless(1);
return yytext[0];
} else { } else {
yylval.y_int = m; yylval.y_int = m;
return(MNEM); return(MNEM);