|
|
1.1 ! root 1: %{ ! 2: #include "ideal.h" ! 3: #include "y.tab.h" ! 4: extern int lineno, yylval; ! 5: extern boolean flyback; ! 6: ! 7: #define BUFLEN 100 ! 8: ! 9: struct filenode { ! 10: struct filenode *next; ! 11: FILE *file; ! 12: int lineno; ! 13: char *name; ! 14: char buf[BUFLEN]; ! 15: int head; ! 16: }; ! 17: ! 18: struct filenode *filestack = NULL; ! 19: ! 20: FILE *curfile; ! 21: #undef input ! 22: #undef unput ! 23: ! 24: boolean file_start = TRUE; ! 25: boolean just_popped = FALSE; ! 26: ! 27: void filepush (); ! 28: void filepop (); ! 29: char input (); ! 30: void unput (); ! 31: %} ! 32: %Start PROGRAM COMMENT OUTSIDE LIBRARY INCLUDE ! 33: %% ! 34: %{ ! 35: int numitems, i; ! 36: char item[5][20]; ! 37: char cmd[20]; ! 38: static int ISnest, bracenest, commnest, omode; ! 39: if (file_start) { ! 40: BEGIN OUTSIDE; ! 41: ISnest = 0; ! 42: }; ! 43: file_start = FALSE; ! 44: %} ! 45: <OUTSIDE>^\.IS.*\n { ! 46: BEGIN PROGRAM; ! 47: if (!ISnest) ! 48: printf ("%s", yytext); ! 49: ISnest ++; ! 50: bracenest = commnest = 0; ! 51: } ! 52: <OUTSIDE>[ \t] { ! 53: if (just_popped) { ! 54: if (omode == LIBFIL) ! 55: BEGIN LIBRARY; ! 56: else if (omode == CHATTY) ! 57: BEGIN INCLUDE; ! 58: else impossible ("idlex"); ! 59: just_popped = FALSE; ! 60: } else ! 61: printf ("%s", yytext); ! 62: } ! 63: <OUTSIDE>. { ! 64: printf ("%s", yytext); ! 65: } ! 66: <OUTSIDE>\n { ! 67: if (just_popped) { ! 68: BEGIN PROGRAM; ! 69: just_popped = FALSE; ! 70: } else { ! 71: printf ("\n"); ! 72: } ! 73: } ! 74: <PROGRAM>box return(yylval = BOX); ! 75: <PROGRAM>var return(yylval = VAR); ! 76: <PROGRAM>bdlist return(yylval = BDLIST); ! 77: <PROGRAM>boundary return(yylval = BDLIST); ! 78: <PROGRAM>put return(yylval = PUT); ! 79: <PROGRAM>conn return(yylval = CONN); ! 80: <PROGRAM>to return(yylval = TO); ! 81: <PROGRAM>using return(yylval = USING); ! 82: <PROGRAM>construct return(yylval = CONSTRUCT); ! 83: <PROGRAM>draw return(yylval = DRAW); ! 84: <PROGRAM>opaque return(yylval = OPAQUE); ! 85: <PROGRAM>left return(yylval = LEFT); ! 86: <PROGRAM>text return(yylval = CENTER); ! 87: <PROGRAM>right return(yylval = RIGHT); ! 88: <PROGRAM>spline return(yylval = SPLINE); ! 89: <PROGRAM>at return(yylval = AT); ! 90: <PROGRAM>interior return(yylval = INTERIOR); ! 91: <PROGRAM>exterior return(yylval = EXTERIOR); ! 92: <PROGRAM>[a-zA-Z][a-zA-Z0-9]* { ! 93: yylval = lookup(&yytext[0]); ! 94: return(NAME); ! 95: } ! 96: <PROGRAM>[0-9]+|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*|[0-9]+\.?[0-9]*[eE]\ *[+\-]?[0-9]+|[0-9]*\.[0-9]+[eE]\ *[+\-]?[0-9]+ { ! 97: float temp; ! 98: sscanf(yytext, "%f", &temp); ! 99: yylval = (int) fextlgen(temp); ! 100: return(CONST); ! 101: } ! 102: <PROGRAM>^\.\.\.forget.* { ! 103: numitems = sscanf (yytext, "%s %s %s %s %s %s", ! 104: cmd, ! 105: &item[0][0], ! 106: &item[1][0], ! 107: &item[2][0], ! 108: &item[3][0], ! 109: &item[4][0] ! 110: ); ! 111: numitems --; ! 112: for (i = 0; i < numitems; i ++) ! 113: forget (lookup (&item[i][0])); ! 114: } ! 115: <PROGRAM>^\.\.\.radians.* radflag = TRUE; ! 116: <PROGRAM>^\.\.\.degrees.* radflag = FALSE; ! 117: <PROGRAM>^\.\.\.libfile { ! 118: omode = LIBFIL; ! 119: BEGIN LIBRARY; ! 120: } ! 121: <LIBRARY>[ \t]+ ; ! 122: <LIBRARY>[^ \t\n]+ { ! 123: idinclude (yytext, LIBFIL); ! 124: BEGIN OUTSIDE + 1; ! 125: } ! 126: <LIBRARY>\n { ! 127: BEGIN PROGRAM + 1; ! 128: } ! 129: <PROGRAM>^\.\.\.include { ! 130: omode = CHATTY; ! 131: BEGIN INCLUDE; ! 132: } ! 133: <INCLUDE>[ \t]+ ; ! 134: <INCLUDE>[^ \t\n]+ { ! 135: idinclude (yytext, CHATTY); ! 136: BEGIN OUTSIDE + 1; ! 137: } ! 138: <INCLUDE>\n { ! 139: BEGIN PROGRAM + 1; ! 140: } ! 141: <PROGRAM>^\.I[EF].*\n { ! 142: interpret (); ! 143: ISnest --; ! 144: if (!ISnest) ! 145: printf ("%s", yytext); ! 146: if (bracenest > 0) ! 147: fprintf (stderr, "ideal: excess {\n"); ! 148: BEGIN OUTSIDE; ! 149: } ! 150: <PROGRAM>^\..* { ! 151: sscanf (yytext, "%s", cmd); ! 152: if (strcmp (cmd, "...libfile") && strcmp (cmd, "...include")) ! 153: printf ("%s\n", yytext); ! 154: else ! 155: REJECT; ! 156: } ! 157: <PROGRAM>#.* ; ! 158: <PROGRAM>"/*" { ! 159: commnest = 1; ! 160: BEGIN COMMENT; ! 161: } ! 162: <COMMENT>"/*" { ! 163: commnest ++; ! 164: } ! 165: <COMMENT>"*/" { ! 166: commnest --; ! 167: if (!commnest) ! 168: BEGIN PROGRAM; ! 169: } ! 170: <COMMENT>. ; ! 171: <COMMENT>\n { ! 172: } ! 173: <PROGRAM>"'"[^']* { ! 174: if (yytext[yyleng-1] == '\\') { ! 175: yytext[yyleng-1] = yytext[yyleng]; ! 176: yyleng --; ! 177: yymore(); ! 178: } else { ! 179: char *temp; ! 180: temp = malloc((unsigned) yyleng+1); ! 181: yytext[yyleng] = '\0'; ! 182: strcpy(temp, &yytext[1]); ! 183: yylval = (int) temp; ! 184: input(); ! 185: return(STRING); ! 186: } ! 187: } ! 188: <PROGRAM>\"[^\"]* { ! 189: if (yytext[yyleng-1] == '\\') { ! 190: yytext[yyleng-1] = yytext[yyleng]; ! 191: yyleng --; ! 192: yymore(); ! 193: } else { ! 194: char *temp; ! 195: temp = malloc((unsigned) yyleng+1); ! 196: yytext[yyleng] = '\0'; ! 197: strcpy(temp, &yytext[1]); ! 198: yylval = (int) temp; ! 199: input(); ! 200: return(STRING); ! 201: } ! 202: } ! 203: <PROGRAM>[ \t]+ { ! 204: if (just_popped) { ! 205: if (omode == LIBFIL) ! 206: BEGIN LIBRARY; ! 207: else if (omode == CHATTY) ! 208: BEGIN INCLUDE; ! 209: else impossible ("idlex"); ! 210: just_popped = FALSE; ! 211: } ! 212: } ! 213: <PROGRAM>\n { ! 214: } ! 215: <PROGRAM>"{" { ! 216: bracenest ++; ! 217: return (yylval = LBRACE); ! 218: } ! 219: <PROGRAM>"}" { ! 220: bracenest --; ! 221: if (bracenest < 0) ! 222: fprintf (stderr, "ideal: excess }\n"); ! 223: return (yylval = RBRACE); ! 224: } ! 225: <PROGRAM>[\<\>\(\)\[\]\+\-\*\/\=\,\;\:\.\^\~] return(yytext[0]); ! 226: <PROGRAM>. fprintf(stderr, "ideal: unknown input token %s flushed\n", &yytext[0]); ! 227: %% ! 228: void filepush (f) ! 229: FILE *f; ! 230: { ! 231: struct filenode *newfile; ! 232: newfile = (struct filenode *) calloc (1, sizeof (struct filenode)); ! 233: if (newfile) { ! 234: newfile->next = filestack; ! 235: newfile->file = curfile = f; ! 236: newfile->head = -1; ! 237: if (filestack) ! 238: filestack->lineno = lineno; ! 239: newfile->name = malloc ((unsigned)strlen(filename)+1); ! 240: strcpy (newfile->name, filename); ! 241: filestack = newfile; ! 242: lineno = 1; ! 243: } else { ! 244: fprintf (stderr, "ideal: no room for file descriptor\n"); ! 245: exit (1); ! 246: } ! 247: } ! 248: ! 249: void filepop () ! 250: { ! 251: struct filenode *oldfile; ! 252: if (filestack) { ! 253: if (filestack->head > -1) ! 254: fprintf (stderr, "ideal: characters ignored in file %s\n", filename); ! 255: oldfile = filestack; ! 256: filestack = filestack->next; ! 257: fclose (oldfile->file); ! 258: if (filestack) { ! 259: curfile = filestack->file; ! 260: lineno = filestack->lineno; ! 261: filename = filestack->name; ! 262: } else ! 263: curfile = NULL; ! 264: free ((char *)oldfile); ! 265: } else { ! 266: fprintf (stderr, "ideal: file stack botch\n"); ! 267: exit (1); ! 268: } ! 269: } ! 270: ! 271: int idgetc (f) ! 272: struct filenode *f; ! 273: { ! 274: int c; ! 275: if (!f) ! 276: return (EOF); ! 277: if (f->head > -1) { ! 278: c = f->buf[f->head--]; ! 279: } else ! 280: c = getc(f->file); ! 281: return (c); ! 282: } ! 283: ! 284: char input () ! 285: { ! 286: int c; ! 287: c = 0; ! 288: if (filestack) ! 289: c = idgetc(filestack); ! 290: while (c == EOF && filestack) { ! 291: filepop(); ! 292: if (filestack) { ! 293: c = idgetc(filestack); ! 294: just_popped = TRUE; ! 295: } ! 296: else ! 297: c = EOF; ! 298: } ! 299: if (c == '\n') ! 300: lineno++; ! 301: return ((c == EOF)?0:c); ! 302: } ! 303: ! 304: void unput (c) ! 305: char c; ! 306: { ! 307: struct filenode *f; ! 308: if (f = filestack) { ! 309: if (f->head < BUFLEN) { ! 310: f->buf[++f->head] = c; ! 311: if (c == '\n') ! 312: -- lineno; ! 313: } else { ! 314: fprintf (stderr, "ideal: out of pushback space\n"); ! 315: exit (1); ! 316: } ! 317: } ! 318: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.