1 %{
2 
3 #ifndef lint
4 static char sccsid[] = "@(#)lextab.l	4.2	(Berkeley)	07/22/88";
5 #endif not lint
6 
7 #include "y.tab.h"
8 #include "b.h"
9 #undef	input
10 #define input()	ninput()
11 #undef	unput
12 #define unput(c)	nunput(c)
13 extern char *malloc();
14 extern int yylval;
15 #define xxbpmax	1700
16 char xxbuf[xxbpmax + 2];
17 int xxbp = -1;
18 #define xxunmax	200
19 char xxunbuf[xxunmax + 2];
20 int xxunbp = -1;
21 
22 
23 int blflag;
24 %}
25 
26 D	[0-9]
27 A	[0-9a-z]
28 L	[a-z]
29 SP	[^0-9a-z]
30 
31 %%
32 
33 %{
34 char *xxtbuff;
35 int xxj, xxn, xxk;
36 char *xxp;
37 %}
38 [=/,(]{D}+[h]			{
39 				blflag = 1;
40 				sscanf(&yytext[1],"%d",&xxn);
41 				xxtbuff = malloc(2*xxn+3);
42 				for (xxj = xxk = 1; xxj <= xxn; ++xxj)
43 					{
44 					xxtbuff[xxk] = ninput();
45 					if (xxtbuff[xxk] == '"')
46 						xxtbuff[++xxk] = '"';
47 					++xxk;
48 					}
49 				xxtbuff[0] = xxtbuff[xxk++] = '"';
50 				xxtbuff[xxk] = '\0';
51 				putback(xxtbuff);
52 				free(xxtbuff);
53 
54 				backup(yytext[0]);
55 				blflag = 0;
56 				xxbp = -1;
57 				}
58 IF			{fixval(); xxbp = -1; return(xxif);}
59 ELSE			{fixval(); xxbp = -1; return(xxelse);}
60 REPEAT			{fixval(); xxbp = -1; return(xxrept); }
61 WHILE			{fixval(); xxbp = -1; return(xxwhile); }
62 UNTIL			{ fixval(); xxbp = -1; return(xxuntil); }
63 DO			{fixval(); xxbp = -1; return(xxdo); }
64 SWITCH			{fixval(); xxbp = -1; return(xxswitch); }
65 CASE			{fixval(); xxbp = -1; return(xxcase); }
66 DEFAULT			{fixval(); xxbp = -1; return(xxdefault); }
67 END			{fixval(); xxbp = -1; return(xxend); }
68 
69 ".true."		|
70 ".false."		|
71 
72 {L}{A}*		{fixval(); xxbp = -1; return(xxident); }
73 ~{D}+			{xxbuf[0] = ' '; fixval(); xxbp = -1; return(xxnum); }
74 {D}+/"."(ge|gt|le|lt|eq|ne|not|or|and)"."	|
75 {D}+\.?			|
76 {D}+\.?[de][+-]?{D}+		|
77 {D}*\.{D}+[de][+-]?{D}+		|
78 {D}*\.{D}+			{fixval(); xxbp = -1; return(xxnum); }
79 
80 ".gt."			{ putback(">"); xxbp = -1; }
81 ".ge."			{ putback(">=");xxbp = -1; }
82 ".lt."			{ putback("<"); xxbp = -1; }
83 ".le."			{ putback("<="); xxbp = -1; }
84 ".eq."			{ putback("=="); xxbp = -1; }
85 ".ne."			{ putback("!="); xxbp = -1; }
86 ".not."			{ putback("!"); xxbp = -1; }
87 ".or."			{ putback("||"); xxbp = -1; }
88 ".and."			{ putback("&&"); xxbp = -1; }
89 ">="		{fixval(); xxbp = -1;  return(xxge);  }
90 "<="		{fixval(); xxbp = -1;  return(xxle); }
91 ==			{fixval(); xxbp = -1; return(xxeq); }
92 !=			{fixval(); xxbp = -1; return(xxne); }
93 "||"			{fixval(); xxbp = -1; return('|'); }
94 "&&"			{fixval(); xxbp = -1;  return('&'); }
95 "**"			{fixval(); xxbp = -1; return('^'); }
96 
97 #.*			{fixval(); xxbp = -1; return(xxcom); }
98 \"([^"]|\"\")*\"		{fixval(); xxbp = -1; return(xxstring); }
99 '([^']|'')*'				{
100 					fixval();
101 					xxp = (char *)yylval;
102 					xxn = slength(xxp);
103 					xxtbuff = malloc(2*xxn+1);
104 					xxtbuff[0] = '"';
105 					for (xxj = xxk = 1; xxj < xxn-1; ++xxj)
106 						{
107 						if (xxp[xxj] == '\'' && xxp[++xxj] == '\'')
108 							xxtbuff[xxk++] = '\'';
109 						else if (xxp[xxj] == '"')
110 							{
111 							xxtbuff[xxk++] = '"';
112 							xxtbuff[xxk++] = '"';
113 							}
114 						else
115 							xxtbuff[xxk++] = xxp[xxj];
116 						}
117 					xxtbuff[xxk++] = '"';
118 					xxtbuff[xxk] = '\0';
119 					free(xxp);
120 					yylval = (int)xxtbuff;
121 					xxbp = -1;
122 					return(xxstring);
123 					}
124 
125 ^\n		xxbp = -1;
126 \n		{xxbp = -1; if (newflag) {fixval(); return('\n'); }  }
127 {SP}		{fixval(); xxbp = -1; return(yytext[0]); }
128 
129 %%
130 
131 rdchar()
132 	{
133 	int c;
134 	if (xxunbp >= 0)
135 		return(xxunbuf[xxunbp--]);
136 	c = getchar();
137 	if (c == EOF) return('\0');
138 	else return((char)c);
139 	}
140 
141 backup(c)
142 char c;
143 	{
144 	if (++xxunbp > xxunmax)
145 		{
146 		xxunbuf[xxunmax + 1] = '\0';
147 		error("RATFOR beautifying; input backed up too far during lex:\n",
148 			xxunbuf,"\n");
149 		}
150 	xxunbuf[xxunbp] = c;
151 	}
152 
153 nunput(c)
154 char c;
155 	{
156 	backup(c);
157 	if (xxbp < 0) return;
158 	if (c != xxbuf[xxbp])
159 		{
160 		xxbuf[xxbp + 1] = '\0';
161 		error("RATFOR beautifying; lex call of nunput with wrong char:\n",
162 			xxbuf,"\n");
163 		}
164 	for ( --xxbp; xxbp >= 0 && (xxbuf[xxbp] == ' ' || xxbuf[xxbp] == '\t'); --xxbp)
165 		backup(xxbuf[xxbp]);
166 	xxbuf[xxbp+1] = '\0';
167 	}
168 
169 ninput()
170 	{
171 	char c,d;
172 	if (blflag) c = rdchar();
173 	else
174 		while ( (c = rdchar()) == ' ' || c == '\t')
175 		addbuf(c);
176 	if (c != '\n')
177 		return(addbuf(c));
178 	while ( (d = rdchar()) == ' ' || d == '\t');
179 	if (d == '&')
180 		return(ninput());
181 	backup(d);
182 	return(addbuf('\n'));
183 	}
184 
185 addbuf(c)
186 char c;
187 	{
188 	if (++xxbp > xxbpmax)
189 		{
190 		xxbuf[xxbpmax +1] = '\0';
191 		error("RATFOR beautifying; buffer xxbuf too small for token beginning:\n",
192 			xxbuf,"\n");
193 		}
194 	xxbuf[xxbp] = c;
195 	xxbuf[xxbp + 1] = '\0';
196 	return(c);
197 	}
198 
199 
200 fixval()
201 	{
202 	int i, j, k;
203 	for (j = 0; xxbuf[j] == ' ' || xxbuf[j] == '\t'; ++j);
204 	for (k = j; xxbuf[k] != '\0'; ++k);
205 	for (--k; k > j && xxbuf[k] == ' ' || xxbuf[k]  == '\t'; --k);
206 	xxbuf[k+1] = '\0';
207 	i = slength(&xxbuf[j]) + 1;
208 	yylval = malloc(i);
209 	str_copy(&xxbuf[j],yylval,i);
210 	}
211 
212 
213 
214 putback(str)
215 char *str;
216 	{
217 	int i;
218 	for (i = 0; str[i] != '\0'; ++i);
219 	for (--i; i >= 0; --i)
220 		backup(str[i]);
221 	}
222 
223