* Author: Hans van Staveren
*/
-#undef input
-#undef output
-#undef unput
-
#define MAXBACKUP 50
#include <stdio.h>
#include "booth.h"
#include "y.tab.h"
+
+int lineno = 1;
+extern char *iname;
+extern char *scopy();
%}
%p 2000
}
[a-z] {yylval.yy_char = yytext[0]; return(LCASELETTER);}
[0-9]* {yylval.yy_int = atoi(yytext);return(NUMBER);}
-(\"|"%)") { char *p; int c,tipe;
- p=yytext;
+(\"|"%)") { char *p; int c,tipe; char stringbuf[BUFSIZ];
+ p=stringbuf;
for (;;) {
c = input();
switch(c) {
}
endstr:
*p++ = 0;
- yylval.yy_string = scopy(yytext);
+ yylval.yy_string = scopy(stringbuf);
return(tipe);
}
-^\#.*$ |
-[ \t]* |
-\n ;
+^\#(line)?[ \t]*[0-9]+[ \t]+\".*\".*$ {
+ int ind,ind2;
+ 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]);
%%
-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; {
- fprintf(stderr,"%d\t%s%d\t%s\t%*c ",lino-1,prevbuf,lino,linebuf,
- linepos-1,'^');
+ fprintf(stderr,"\"%s\", line %d:",iname ? iname : "",lineno);
fprintf(stderr,s,a1,a2,a3,a4);
fprintf(stderr,"\n");
nerrors++;
int lineno=1;
extern char *filename;
+#undef yywrap
%}
%%
if (strcmp(yytext+ind+1,filename)!=0)
filename=mystrcpy(yytext+ind+1);
}
-[a-z]{3} { if (!emhere || (yylval.yy_int=mlookup(yytext))==0)
- REJECT;
- return(EMMNEM);
- }
-
"==" return(CMPEQ);
"!=" return(CMPNE);
"<" return(CMPLT);
\%[a-z] { yylval.yy_int = yytext[1]-'a'; return(ALLREG); }
[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;
+ if (yyleng==3 &&
+ emhere &&
+ (yylval.yy_int=mlookup(yytext))!=0) {
+ return(EMMNEM);
+ }
if ((sy_p=lookup(yytext,symkeyw,justlooking))!=0)
return(sy_p->sy_value.syv_keywno);
yylval.yy_str = mystrcpy(yytext); return(IDENT);