O'Reilly logo

lex & yacc, 2nd Edition by Tony Mason, John Levine, Doug Brown

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required