Appendix K. SQL Parser Code
Recycle this page
Lex Scanner
This is file scn2.l.
%{ #include *sql2.h* #include <string.h> int lineno = 1; void yyerror(char *s); /* macro to save the text of a SQL token */ #define SV save_str(yytext) /* macro to save the text and return a token */ #define TOK(name) { SV;return name; } %} %s SQL %% EXEC[ \t]+SQL { BEGIN SQL; start_save () ; } /* literal keyword tokens */ <SQL>ALL TOK (ALL) <SQL>AND TOK (AND) <SQL>AVG TOK (AMMSC) <SQL>MIN TOK (AMMSC) <SQL>MAX TOK (AMMSC) <SQL>SUM TOK (AMMSC) <SQL>COUNT TOK (AMMSC) <SQL>ANY TOK (ANY) <SQL>AS TOK (AS) <SQL>ASC TOK(ASC) <SQL>AUTHORIZATION TOK (AUTHORIZATION) <SQL>BETWEEN TOK (BETWEEN) <SQL>BY TOK(BY) <SQL>CHAR (ACTER)?TOK (CHARACTER) <SQL>CHECK TOK (CHECK) <SQL>CLOSE TOK(CLOSE) <SQL>COMMIT TOK (COMMIT) <SQL>CONTINUE TOK (CONTINUE) <SQL>CREATE TOK (CREATE) <SQL>CURRENT TOK (CURRENT) <SQL>CURSOR TOK (CURSOR) <SQL>DECIMAL TOK (DECIMAL) <SQL>DECLARE TOK (DECLARE) <SQL>DEFAULT TOK (DEFAULT) <SQL>DELETE TOK (DELETE) <SQL>DESC TOK (DESC) <SQL>DISTINCT TOK (DISTINCT) <SQL>DOUBLE TOK (DOUBLE) <SQL>ESCAPE TOK (ESCAPE) <SQL>EXISTS TOK (EXISTS) <SQL>FETCH TOK (FETCH) <SQL>FLOAT TOK (FLOAT) <SQL>FOR TOK (FOR) <SQL>FOREIGN TOK (FOREIGN) <SQL>FOUND TOK (FOUND) <SQL>FROM TOK (FROM) <SQL>GO[ \t]*TO TOX (GOTO) <SQL>GRANT TOK (GRANT) <SQL>GROUP TOK (GROUP) <SQL>HAVING TOK (HAVING) <SQL>IN TOK (IN) <SQL>INDICATOR TOK (INDICATOR) <SQL>INSERT TOK (INSERT) <SQL>INT(EGER)? TOK (INTEGER) <SQL>INTO TOK (INTO) <SQL>IS TOK (IS) <SQL>KEY ...
Get lex & yacc, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.