%Start A str def sc br thru sh %e 1700 %k 120 %a 1800 %o 1500 %p 5000 %n 700 %{ #undef input #undef unput #include #include #include "pic.h" #include "y.tab.h" extern double atof(); extern char *filename; extern struct symtab symtab[]; extern struct symtab*copythru(); #define CADD cbuf[clen++]=yytext[0]; if(clen>=CBUFLEN-1) {ERROR "string too long", cbuf WARNING; BEGIN A;} #define CBUFLEN 500 char cbuf[CBUFLEN]; int c, clen, cflag, delim; int ifsw = 0; /* 1 if if statement in progress */ %} A [a-zA-Z_] B [a-zA-Z0-9_] D [0-9] WS [ \t] %% switch (yybgin-yysvec-1) { /* witchcraft */ case 0: BEGIN A; break; case sc: BEGIN A; return('}'); case br: BEGIN A; return(']'); } {WS} ; "\\"\n ; \n { return(ST); } ";" { return(ST); } "}" { BEGIN sc; return(ST); } "]" { BEGIN br; return(ST); } ^".PS".* { if (curfile == infile) ERROR ".PS found inside .PS/.PE" WARNING; } ^"."P[EF].* { if (curfile == infile) { yylval.i = yytext[2]; PEseen = 1; return(EOF); } } ^".".* { yylval.p = tostring(yytext); return(TROFF); } print return(yylval.i = PRINT); box return(yylval.i = BOX); circle return(yylval.i = CIRCLE); arc return(yylval.i = ARC); ellipse return(yylval.i = ELLIPSE); arrow return(yylval.i = ARROW); spline return(yylval.i = SPLINE); line return(yylval.i = LINE); move return(yylval.i = MOVE); "[]" return(yylval.i = BLOCK); reset return(RESET); sprintf return(SPRINTF); same return(SAME); between return(BETWEEN); and return(AND); of ; the ; way ; "."(e|east) { yylval.i = EAST; return(CORNER); } "."(r|right) { yylval.i = EAST; return(CORNER); } "."(w|west) { yylval.i = WEST; return(CORNER); } "."(l|left) { yylval.i = WEST; return(CORNER); } "."(n|north) { yylval.i = NORTH; return(CORNER); } "."(t|top) { yylval.i = NORTH; return(CORNER); } "."(s|south) { yylval.i = SOUTH; return(CORNER); } "."(b|bot|bottom) { yylval.i = SOUTH; return(CORNER); } "."(c|center) { yylval.i = CENTER; return(CORNER); } ".start" { yylval.i = START; return(CORNER); } ".end" { yylval.i = END; return(CORNER); } ".ne" { yylval.i = NE; return(CORNER); } ".se" { yylval.i = SE; return(CORNER); } ".nw" { yylval.i = NW; return(CORNER); } ".sw" { yylval.i = SW; return(CORNER); } top" "+of { yylval.i = NORTH; return(CORNER); } north" "+of { yylval.i = NORTH; return(CORNER); } bottom" "+of { yylval.i = SOUTH; return(CORNER); } south" "+of { yylval.i = SOUTH; return(CORNER); } left" "+of { yylval.i = WEST; return(CORNER); } west" "+of { yylval.i = WEST; return(CORNER); } right" "+of { yylval.i = EAST; return(CORNER); } east" "+of { yylval.i = EAST; return(CORNER); } center" "+of { yylval.i = CENTER; return(CORNER); } start" "+of { yylval.i = START; return(CORNER); } end" "+of { yylval.i = END; return(CORNER); } height|ht { yylval.i = HEIGHT; return(ATTR); } width|wid { yylval.i = WIDTH; return(ATTR); } radius|rad { yylval.i = RADIUS; return(ATTR); } diameter|diam { yylval.i = DIAMETER; return(ATTR); } size { yylval.i = SIZE; return(ATTR); } left { yylval.i = LEFT; return(DIR); } right { yylval.i = RIGHT; return(DIR); } up { yylval.i = UP; return(DIR); } down { yylval.i = DOWN; return(DIR); } cw { yylval.i = CW; return(ATTR); } clockwise { yylval.i = CW; return(ATTR); } ccw { yylval.i = CCW; return(ATTR); } invis(ible)? { yylval.i = INVIS; return(ATTR); } fill { yylval.i = FILL; return ATTR; } solid ; dot(ted)? return(yylval.i = DOT); dash(ed)? return(yylval.i = DASH); chop return(yylval.i = CHOP); spread { yylval.i = SPREAD; return TEXTATTR; } ljust { yylval.i = LJUST; return TEXTATTR; } rjust { yylval.i = RJUST; return TEXTATTR; } above { yylval.i = ABOVE; return TEXTATTR; } below { yylval.i = BELOW; return TEXTATTR; } center { yylval.i = CENTER; return TEXTATTR; } "<-" { yylval.i = HEAD1; return(HEAD); } "->" { yylval.i = HEAD2; return(HEAD); } "<->" { yylval.i = HEAD12; return(HEAD); } ".x" return(yylval.i = DOTX); ".y" return(yylval.i = DOTY); "."(ht|height) return(yylval.i = DOTHT); "."(wid|width) return(yylval.i = DOTWID); "."(rad|radius) return(yylval.i = DOTRAD); from return(yylval.i = FROM); to return(yylval.i = TO); at return(yylval.i = AT); by return(yylval.i = BY); with return(yylval.i = WITH); last return(yylval.i = LAST); log return(LOG); exp return(EXP); sin return(SIN); cos return(COS); atan2 return(ATAN2); sqrt return(SQRT); rand return(RAND); max return(MAX); min return(MIN); int return(INT); "==" return(EQ); ">=" return(GE); "<=" return(LE); "!=" return(NEQ); ">" return(GT); "<" return(LT); "&&" return(ANDAND); "||" return(OROR); "!" return(NOT); Here return(yylval.i = HERE); for return(FOR); ^Endfor\n { endfor(); } do { yylval.p = delimstr("loop body"); return(DOSTR); } copy|include return(COPY); (thru|through){WS}+ { BEGIN thru; return(THRU); } {A}{B}*|. { yylval.st = copythru(yytext); BEGIN A; return(DEFNAME); } until return(UNTIL); if { ifsw = 1; return(IF); } then { if (!ifsw) { yylval.i = THEN; return(ATTR); } yylval.p = delimstr("then part"); ifsw = 0; return(THENSTR); } else { yylval.p = delimstr("else part"); return(ELSESTR); } sh{WS}+ { BEGIN sh; if ((delim = input()) == '{') delim = '}'; /* no nested {} */ shell_init(); } {A}{B}* { struct symtab *p; if (yytext[0] == delim) { shell_exec(); BEGIN A; } else { p = lookup(yytext); if (p != NULL && p->s_type == DEFNAME) { c = input(); unput(c); if (c == '(') dodef(p); else pbstr(p->s_val.p); } else shell_text(yytext); } } .|\n { if (yytext[0] == delim) { shell_exec(); BEGIN A; } else shell_text(yytext); } define{WS}+ { BEGIN def; } {A}{B}* { definition(yytext); BEGIN A; } undef(ine)?{WS}+{A}{B}* { undefine(yytext); } first { yylval.i = 1; return(NTH); } {D}+(th|nd|rd|st) { yylval.i = atoi(yytext); return(NTH); } ({D}+("."?){D}*|"."{D}+)((e|E)("+"|-)?{D}+)?i? { yylval.f = atof(yytext); return(NUMBER); } {A}{B}* { struct symtab *p; p = lookup(yytext); if (p != NULL && p->s_type == DEFNAME) { c = input(); unput(c); if (c == '(') /* it's name(...) */ dodef(p); else { /* no argument list */ pbstr(p->s_val.p); dprintf("pushing back `%s'\n", p->s_val.p); } } else if (islower(yytext[0])) { yylval.p = tostring(yytext); return(VARNAME); } else { yylval.p = tostring(yytext); return(PLACENAME); } } \" { BEGIN str; clen=0; } \" { cbuf[clen]=0; yylval.p = tostring(cbuf); BEGIN A; return(TEXT); } \n { cbuf[clen]=0; ERROR "missing quote in string \"%s\"", cbuf WARNING; BEGIN A; return(ST); } "\\\"" { cbuf[clen++]='"'; } "\\\\" { cbuf[clen++]='\\'; } . { CADD; } #.* ; . return(yylval.i = yytext[0]); %%