|
|
1.1 ! root 1: %Start A str def thru sh ! 2: ! 3: %{ ! 4: #undef input ! 5: #undef unput ! 6: #include <stdio.h> ! 7: #include <ctype.h> ! 8: #include "grap.h" ! 9: #include "y.tab.h" ! 10: ! 11: extern struct symtab symtab[]; ! 12: ! 13: #define CADD cbuf[clen++] = yytext[0]; \ ! 14: if (clen >= CBUFLEN-1) { \ ! 15: ERROR "string too long", cbuf WARNING; BEGIN A; } ! 16: #define CBUFLEN 1500 ! 17: char cbuf[CBUFLEN]; ! 18: int clen, cflag; ! 19: int c, delim, shcnt; ! 20: %} ! 21: ! 22: A [a-zA-Z_] ! 23: B [a-zA-Z0-9_] ! 24: D [0-9] ! 25: WS [ \t] ! 26: ! 27: %% ! 28: if (yybgin-yysvec-1 == 0) { /* witchcraft */ ! 29: BEGIN A; ! 30: } ! 31: ! 32: <A>{WS} ; ! 33: <A>"\\"\n ; ! 34: <A>\n return(ST); ! 35: <A>";" return(ST); ! 36: ! 37: <A>line return(yylval.i = LINE); ! 38: <A>arrow { yylval.i = ARROW; return(LINE); } ! 39: <A>circle return(yylval.i = CIRCLE); ! 40: <A>frame return(FRAME); ! 41: <A>tick(s)? return(TICKS); ! 42: <A>grid(line)?(s)? return(GRID); ! 43: <A>coord(s)? return(COORD); ! 44: <A>log return(LOG); ! 45: <A>exp return(EXP); ! 46: <A>sin return(SIN); ! 47: <A>cos return(COS); ! 48: <A>atan2 return(ATAN2); ! 49: <A>sqrt return(SQRT); ! 50: <A>rand return(RAND); ! 51: <A>max return(MAX); ! 52: <A>min return(MIN); ! 53: <A>int return(INT); ! 54: <A>print return(PRINT); ! 55: <A>sprintf return(SPRINTF); ! 56: <A>pic{WS}.* { yylval.p = tostring(yytext+3); return(PIC); } ! 57: <A>graph{WS}.* { yylval.p = tostring(yytext+5); return(GRAPH); } ! 58: ! 59: <A>for return(FOR); ! 60: <A>^Endfor\n { endfor(); } ! 61: <A>do { yylval.p = delimstr("loop body"); BEGIN A; return(DOSTR); } ! 62: ! 63: <A>copy|include { return(COPY); } ! 64: <A>thru|through { BEGIN thru; return(THRU); } ! 65: <thru>{WS}+ ; ! 66: <thru>{A}{B}*|. { yylval.op = copythru(yytext); BEGIN A; return(DEFNAME); } ! 67: <A>until return(UNTIL); ! 68: ! 69: <A>if return(IF); ! 70: <A>then { yylval.p = delimstr("then part"); BEGIN A; return(THEN); } ! 71: <A>else { yylval.p = delimstr("else part"); BEGIN A; return(ELSE); } ! 72: ! 73: <A>next return(NEXT); ! 74: <A>draw return(yylval.i = DRAW); ! 75: <A>new return(yylval.i = NEW); ! 76: <A>plot return(yylval.i = PLOT); ! 77: <A>label(s)? return(LABEL); ! 78: <A>x return(X); ! 79: <A>y return(Y); ! 80: ! 81: <A>top { yylval.i = TOP; return SIDE; } ! 82: <A>bot(tom)? { yylval.i = BOT; return SIDE; } ! 83: <A>left { yylval.i = LEFT; return SIDE; } ! 84: <A>right { yylval.i = RIGHT; return SIDE; } ! 85: <A>up return(yylval.i = UP); ! 86: <A>down return(yylval.i = DOWN); ! 87: <A>across return(yylval.i = ACROSS); ! 88: <A>height|ht return(yylval.i = HEIGHT); ! 89: <A>wid(th)? return(yylval.i = WIDTH); ! 90: <A>rad(ius)? return(yylval.i = RADIUS); ! 91: <A>invis return(yylval.i = INVIS); ! 92: <A>dot(ted) return(yylval.i = DOT); ! 93: <A>dash(ed) return(yylval.i = DASH); ! 94: <A>solid return(yylval.i = SOLID); ! 95: ! 96: <A>ljust { yylval.i = LJUST; return JUST; } ! 97: <A>rjust { yylval.i = RJUST; return JUST; } ! 98: <A>above { yylval.i = ABOVE; return JUST; } ! 99: <A>below { yylval.i = BELOW; return JUST; } ! 100: <A>size return(yylval.i = SIZE); ! 101: ! 102: <A>from return(yylval.i = FROM); ! 103: <A>to return(yylval.i = TO); ! 104: <A>by|step return(yylval.i = BY); ! 105: <A>at return(yylval.i = AT); ! 106: <A>with return(yylval.i = WITH); ! 107: <A>in return(yylval.i = IN); ! 108: <A>out return(yylval.i = OUT); ! 109: <A>off return(yylval.i = OFF); ! 110: ! 111: <A>sh{WS}+ { BEGIN sh; ! 112: if ((delim = input()) == '{') { ! 113: shcnt = 1; ! 114: delim = '}'; ! 115: } ! 116: shell_init(); ! 117: } ! 118: <sh>{A}{B}* { ! 119: int c; ! 120: Obj *p; ! 121: if (yytext[0] == delim) { ! 122: shell_exec(); ! 123: BEGIN A; ! 124: } else { ! 125: p = lookup(yytext, 0); ! 126: if (p != NULL && p->type == DEFNAME) { ! 127: c = input(); ! 128: unput(c); ! 129: if (c == '(') ! 130: dodef(p); ! 131: else ! 132: pbstr(p->val); ! 133: } else ! 134: shell_text(yytext); ! 135: } ! 136: } ! 137: <sh>"{" { shcnt++; shell_text(yytext); } ! 138: <sh>"}" { if (delim != '}' || --shcnt > 0) ! 139: shell_text(yytext); ! 140: else { ! 141: shell_exec(); ! 142: BEGIN A; ! 143: } ! 144: } ! 145: <sh>.|\n { if (yytext[0] == delim) { ! 146: shell_exec(); ! 147: BEGIN A; ! 148: } else ! 149: shell_text(yytext); ! 150: } ! 151: ! 152: <A>define{WS}+ { BEGIN def; } ! 153: <def>{A}{B}* { definition(yytext); BEGIN A; } ! 154: ! 155: <A>({D}+("."?){D}*|"."{D}+)((e|E)("+"|-)?{D}+)?i? { ! 156: yylval.f = atof(yytext); return(NUMBER); } ! 157: ! 158: <A>^"."[^0-9].* { if (yytext[1] == 'G' && yytext[2] == '2') { ! 159: yylval.i = yytext[2]; ! 160: return(EOF); ! 161: } else { ! 162: yylval.p = tostring(yytext); ! 163: return(PIC); ! 164: } ! 165: } ! 166: ! 167: <A>{A}{B}* { ! 168: int c; ! 169: Obj *p; ! 170: p = lookup(yytext, 1); ! 171: if (p->type == DEFNAME) { ! 172: c = input(); ! 173: unput(c); ! 174: if (c == '(') /* it's name(...) */ ! 175: dodef(p); ! 176: else /* no argument list */ ! 177: pbstr(p->val); ! 178: } else { ! 179: yylval.op = p; ! 180: return p->type; /* NAME or VARNAME */ ! 181: } ! 182: } ! 183: ! 184: <A>"==" return(EQ); ! 185: <A>">=" return(GE); ! 186: <A>"<=" return(LE); ! 187: <A>"!=" return(NE); ! 188: <A>">" return(GT); ! 189: <A>"<" return(LT); ! 190: <A>"&&" return(AND); ! 191: <A>"||" return(OR); ! 192: <A>"!" return(NOT); ! 193: ! 194: <A>\" { BEGIN str; clen = 0; } ! 195: ! 196: <A>#.* ; ! 197: ! 198: <A>. { yylval.i = yytext[0]; return(yytext[0]); } ! 199: ! 200: <str>\" { BEGIN A; cbuf[clen] = 0; ! 201: yylval.p = tostring(cbuf); return(STRING); } ! 202: <str>\n { ERROR "newline in string" WARNING; BEGIN A; return(ST); } ! 203: <str>"\\\"" { cbuf[clen++] = '\\'; cbuf[clen++] = '"'; } ! 204: <str>"\\\\" { cbuf[clen++] = '\\'; cbuf[clen++] = '\\'; } ! 205: <str>. { CADD; } ! 206: ! 207: %%
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.