Browse Source

Made acceptable for flex

ceriel 33 years ago
parent
commit
efa476b5b3
3 changed files with 31 additions and 53 deletions
  1. 23 47
      util/cgg/bootlex.l
  2. 6 5
      util/ncgg/scan.l
  3. 2 1
      util/opt/scan.l

+ 23 - 47
util/cgg/bootlex.l

@@ -10,10 +10,6 @@ static char rcsid2[]="$Header$";
  * Author: Hans van Staveren
  */
 
-#undef input
-#undef output
-#undef unput
-
 #define MAXBACKUP 50
 
 #include <stdio.h>
@@ -25,6 +21,10 @@ static char rcsid2[]="$Header$";
 
 #include "booth.h"
 #include "y.tab.h"
+
+int lineno = 1;
+extern char *iname;
+extern char *scopy();
 %}
 
 %p 2000
@@ -113,8 +113,8 @@ return			return(RETURN);
                         }
 [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) {
@@ -138,54 +138,30 @@ return			return(RETURN);
                           }
                         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++;

+ 6 - 5
util/ncgg/scan.l

@@ -12,6 +12,7 @@ int   myatoi();
 
 int lineno=1;
 extern char *filename;
+#undef yywrap
 %}
 
 %%
@@ -39,11 +40,6 @@ extern char *filename;
 			  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);
@@ -65,6 +61,11 @@ extern char *filename;
 \%[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);

+ 2 - 1
util/opt/scan.l

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