%{ /* * Changes by Gunnar Ritter, Freiburg i. Br., Germany, October 2005. * * Derived from Plan 9 v4 /sys/src/cmd/pic/ * * Copyright (C) 2003, Lucent Technologies Inc. and others. * All Rights Reserved. * * Distributed under the terms of the Lucent Public License Version 1.02. */ /* Sccsid @(#)picl.l 1.9 (gritter) 8/6/06 */ %} %Start A str def xsc br thru sh %e 1700 %k 150 %a 1800 %o 1600 %p 5000 %n 700 %{ #ifndef FLEX_SCANNER #undef input #undef unput #endif /* !FLEX_SCANNER */ /* #include lex puts one out for us */ #include #include #include #include "pic.h" #include "y.tab.h" #ifdef FLEX_SCANNER #undef YY_INPUT #define YY_INPUT(buf, result, max_size) { \ int c = xxinput(); \ result = (c == EOF || c == 0) ? YY_NULL : (buf[0] = c, 1); \ } #define witchcraft YY_START #else /* !FLEX_SCANNER */ #define witchcraft yybgin-yysvec-1 #endif /* !FLEX_SCANNER */ extern char *filename; extern struct symtab symtab[]; void pbstr(char *); void dodef(struct symtab *stp); void undefine(char *s); void shell_init(void), shell_exec(void), shell_text(char *); void endfor(void); int yyback(int *, int); int yylook(void); int yywrap(void); #define CADD cbuf[clen++]=yytext[0]; \ if (clen>=CBUFLEN-1) { WARNING("string too long", cbuf); 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] FWS ([ \t]|\\\n) %% switch (witchcraft) { case 0: BEGIN A; break; case xsc: BEGIN A; return('}'); case br: BEGIN A; return(']'); } {WS} ; "\\"\n ; \n { return(ST); } ";" { return(ST); } "}" { BEGIN xsc; return(ST); } "]" { BEGIN br; return(ST); } "{"{WS}*(#.*)?\n+ { return(yylval.i = yytext[0]); } ^".PS".* { if (curfile == infile) WARNING(".PS found inside .PS/.PE"); } ^".PE".* { if (curfile == infile) { yylval.p = PEstring = tostring(yytext); 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{FWS}+of { yylval.i = NORTH; return(CORNER); } north{FWS}+of { yylval.i = NORTH; return(CORNER); } bottom{FWS}+of { yylval.i = SOUTH; return(CORNER); } south{FWS}+of { yylval.i = SOUTH; return(CORNER); } left{FWS}+of { yylval.i = WEST; return(CORNER); } west{FWS}+of { yylval.i = WEST; return(CORNER); } right{FWS}+of { yylval.i = EAST; return(CORNER); } east{FWS}+of { yylval.i = EAST; return(CORNER); } center{FWS}+of { yylval.i = CENTER; return(CORNER); } start{FWS}+of { yylval.i = START; return(CORNER); } end{FWS}+of { yylval.i = END; return(CORNER); } upper{FWS}right{FWS}+of { yylval.i = NE; return(CORNER); } lower{FWS}right{FWS}+of { yylval.i = SE; return(CORNER); } upper{FWS}left{FWS}+of { yylval.i = NW; return(CORNER); } lower{FWS}left{FWS}+of { yylval.i = SW; 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); } noedge { yylval.i = INVIS; return ATTR; } fill return(yylval.i = FILL); 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(); xxunput(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(); xxunput(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; WARNING("missing quote in string \"%s\"", cbuf); BEGIN A; return(ST); } "\\\"" { cbuf[clen++]='"'; } "\\"t { cbuf[clen++]='\t'; } "\\\\" { cbuf[clen++]='\\'; } . { CADD; } #.* ; . return(yylval.i = yytext[0]); %% #ifdef FLEX_SCANNER void xxcruft(void) { unput(0); } #endif /* FLEX_SCANNER */