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