HEX [0-9A-Fa-f] OCTAL [0-7] DECIMAL [0-9] LETTER [A-Za-z/_] %{ #include "parser.tab.h" #include "xpal.h" int yyback(int *, int); int yylook(void); int yywrap(void); char cbuf[MAXPIN]; int clen; int index; #undef input #undef unput %} %START normal string %% switch (yybgin-yysvec-1) { /* witchcraft */ case 0: BEGIN normal; break; } "0x"{HEX}+ { return(_HEX); } "0"{OCTAL}+ { return(_OCTAL); } {DECIMAL}+ { return(_DECIMAL); } "0b"[01]+ { return(_BINARY); } \" { BEGIN string; clen=0; } \" { cbuf[clen]='\0'; BEGIN normal; return(_STRING); } \n ; " " ; "\\\"" { cbuf[clen++] = '"'; } "\\\\" { cbuf[clen++] = '\\'; } . { cbuf[clen++] = yytext[0]; if(clen>=MAXPIN-1) {yyerror("string too long",cbuf); BEGIN normal; } } %.*$ ; \n ; " " ; \t ; {DECIMAL}+{LETTER}+{DECIMAL}+ { return(_PART); } array return(_ARRAY); inputs return(_INPUTS); outputs return(_OUTPUTS); set return(_SET); reset return(_RESET); clock return(_CLOCK); macrocell return(_MACROCELL); enabled return(_ENABLED); enables return(_ENABLES); clocked return(_CLOCKED); inverted return(_INVERTED); internal return(_INTERNAL); external return(_EXTERNAL); input return(_INPUT); output return(_OUTPUT); fuses return(_FUSES); complement"+" return(_COMPLEMENTPLUS); complement"-" return(_COMPLEMENTMINUS); pins return(_PINS); offset return(_OFFSET); declare return(_DECLARE); supply return(_VCC); ground return(_GND); inverted return(_INVERTED); package return(_PACKAGE); invert return(_INVERT); enable return(_ENABLE); not return(_NOT); {LETTER}({LETTER}|{DECIMAL})* return(_ID); . return(yytext[0]); %% /* input() and unput() are transcriptions of the standard lex macros for input and output with additions for error message printing. God help us all if someone changes how lex works. */ unsigned char ebuf[300]; unsigned char *ep = ebuf; extern FILE * scan_fp; int input() { register c; extern unsigned char *lexprog; if (yysptr > yysbuf) c = U(*--yysptr); else c = fgetc(scan_fp); if (c == '\n') yylineno++; else if (c == EOF) c = 0; if (ep >= ebuf + sizeof ebuf) ep = ebuf; return *ep++ = c; } void unput(c) { yytchar = c; if (yytchar == '\n') yylineno--; *yysptr++ = yytchar; if (--ep < ebuf) ep = ebuf + sizeof(ebuf) - 1; } int yywrap(void) { return(1); }