Pristine Ack-5.5
[Ack-5.5.git] / util / cgg / bootlex.l
1 %{
2
3 #ifndef NORCSID
4 static char rcsid2[]="$Id: bootlex.l,v 2.10 1994/06/24 10:16:08 ceriel Exp $";
5 #endif
6 /*
7  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
8  * See the copyright notice in the ACK home directory, in the file "Copyright".
9  *
10  * Author: Hans van Staveren
11  */
12
13 #define MAXBACKUP 50
14
15 #include <stdio.h>
16 #include <assert.h>
17 #include <em_spec.h>
18 #include <em_flag.h>
19 #include <em_reg.h>
20
21 #include "booth.h"
22 #include "y.tab.h"
23
24 int lineno = 1;
25 extern char *iname;
26 extern char *scopy();
27 %}
28
29 %p 2000
30 %%
31 "/*"                    { char c;
32                           c = input();
33                           do {
34                                 while (c!='*')
35                                         c = input();
36                                 c = input();
37                           } while (c!='/');
38                         }
39 "REGISTERS:"            return(REGISTERHEAD);
40 "TOKENS:"               return(TOKENHEAD);
41 "TOKENEXPRESSIONS:"     return(EXPRESSIONHEAD);
42 "CODE:"                 return(CODEHEAD);
43 "MOVES:"                return(MOVEHEAD);
44 "TESTS:"                return(TESTHEAD);
45 "STACKS:"               return(STACKHEAD);
46 "SIZEFACTOR"            return(SIZEFAC);
47 "TIMEFACTOR"            return(TIMEFAC);
48 "FORMAT"                return(FORMAT);
49
50 "cost"                  return(COST);
51 "remove"                return(REMOVE);
52 "|"                     return(SEP);
53 "samesign"              return(SAMESIGN);
54 "inreg"                 return(INREG);
55 "sfit"                  return(SFIT);
56 "ufit"                  return(UFIT);
57 "defined"               return(DEFINED);
58 "rom"                   return(ROM);
59 "loww"                  return(LOWW);
60 "highw"                 return(HIGHW);
61 "move"                  return(MOVE);
62 "erase"                 return(ERASE);
63 "allocate"              return(ALLOCATE);
64 "tostring"              return(TOSTRING);
65 "nocc"                  return(NOCC);
66 "setcc"                 return(SETCC);
67 "samecc"                return(SAMECC);
68 "test"                  return(TEST);
69 "STACK"                 return(STACK);
70 "nocoercions"           return(NOCOERC);
71
72 "&&"                    return(AND2);
73 "||"                    return(OR2);
74 "=="                    return(CMPEQ);
75 "!="                    return(CMPNE);
76 "<="                    return(CMPLE);
77 "<"                     return(CMPLT);
78 ">"                     return(CMPGT);
79 ">="                    return(CMPGE);
80 ">>"                    return(RSHIFT);
81 "<<"                    return(LSHIFT);
82 "!"                     return(NOT);
83 "~"                     return(COMP);
84 "..."                   return(ELLIPS);
85
86 EM_WSIZE                { yylval.yy_intp = &wsize; return(CIDENT); }
87 EM_PSIZE                { yylval.yy_intp = &psize; return(CIDENT); }
88 EM_BSIZE                { yylval.yy_intp = &bsize; return(CIDENT); }
89 REGISTER                { yylval.yy_string = "REGISTER"; return(TYPENAME); }
90 INT                     { yylval.yy_string = "INT"; return(TYPENAME); }
91 STRING                  { yylval.yy_string = "STRING"; return(TYPENAME); }
92
93 regvar                  return(REGVAR);
94 loop                    return(LOOP);
95 pointer                 return(POINTER);
96 float                   return(FLOAT);
97 return                  return(RETURN);
98
99 [_A-Za-z][_A-Za-z0-9]+  {register ident_p ip;
100                          if(!lookident || (ip=ilookup(yytext,JUSTLOOKING))==0) {
101                            yylval.yy_string = scopy(yytext);return(IDENT);
102                          } else {
103                            yylval.yy_ident = ip;
104                            switch(ip->i_type) {
105                            default:assert(0);
106                            case IREG:return(RIDENT);
107                            case IPRP:return(PIDENT);
108                            case ITOK:return(TIDENT);
109                            case IEXP:return(EIDENT);
110                            }
111                          }
112                         }
113 [a-z]                   {yylval.yy_char = yytext[0]; return(LCASELETTER);}
114 [0-9]*                  {yylval.yy_int = atoi(yytext);return(NUMBER);}
115 (\"|"%)")               { char *p; int c,tipe; char stringbuf[BUFSIZ];
116                           p=stringbuf;
117                           for (;;) {
118                                 c = input();
119                                 switch(c) {
120                                 default: *p++=c;break;
121                                 case '\\':
122                                         *p++=c; *p++=input(); break;
123                                 case '\n':
124                                         yyerror("Unterminated string");
125                                         unput(c);
126                                         /* fall through */
127                                 case '"':
128                                         tipe=STRING; goto endstr;
129                                 case '%':
130                                         c=input();
131                                         if (c == '(') {
132                                                 tipe=LSTRING;goto endstr;
133                                         } else {
134                                                 *p++ = '%'; unput(c); break;
135                                         }
136                                 }
137                           }
138                         endstr:
139                           *p++ = 0;
140                           yylval.yy_string = scopy(stringbuf);
141                           return(tipe);
142                         }
143 ^\#(line)?[ \t]*[0-9]+[ \t]+\".*\".*$   {
144                           int ind,ind2;
145                           for (ind=0; yytext[ind] < '0' || yytext[ind]>'9'; ind++)
146                                 ;
147                           lineno=atoi(&yytext[ind])-1;
148                           for(;yytext[ind]!='"';ind++)
149                                 ;
150                           for(ind2=ind+1;yytext[ind2]!='"';ind2++)
151                                 ;
152                           yytext[ind2]=0;
153                           if (!iname || strcmp(yytext+ind+1,iname)!=0)
154                                 iname=scopy(yytext+ind+1);
155                         }
156 [ \t]*                  ;
157 \n                      { lineno++; }
158 .                       return(yytext[0]);
159 %%
160
161 yyerror(s,a1,a2,a3,a4) string s; {
162
163         fprintf(stderr,"\"%s\", line %d:",iname ? iname : "",lineno);
164         fprintf(stderr,s,a1,a2,a3,a4);
165         fprintf(stderr,"\n");
166         nerrors++;
167 }