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 J. SQL Parser Code

Here we display the complete code for the embedded SQL translator, including the lexer, the parser, and the supporting C code. Since the parser is so long, we have numbered the lines and included a cross-reference of all of the symbols by line number at the end.

The main() and yyerror() routines are at the end of the lex scanner.

Yacc Parser

In this printed listing, some of the lines have been split in two so they fit on the page. The line numbers correspond to the original lines in the grammar file.

 /* symbolic tokens */ %union { int intval; 5 double floatval; char *strval; int subtok; } 10 %token NAME %token STRING %token INTNUM APPROXNUM /* operators */ 15 %left OR %left AND %left NOT %left <subtok> COMPARISON /* = <> < > <= >= */ 20 %left '+' '-' %left '*' '/' %nonassoc UMINUS /* literal keyword tokens */ 25 %token ALL AMMSC ANY AS ASC AUTHORIZATION BETWEEN BY %token CHARACTER CHECK CLOSE COMMIT CONTINUE CREATE CURRENT %token CURSOR DECIMAL DECLARE DEFAULT DELETE DESC DISTINCT DOUBLE %token ESCAPE EXISTS FETCH FLOAT FOR FOREIGN FOUND FROM GOTO 30 %token GRANT GROUP HAVING IN INDICATOR INSERT INTEGER INTO %token IS KEY LANGUAGE LIKE NULLX NUMERIC OF ON OPEN OPTION %token ORDER PARAMETER PRECISION PRIMARY PRIVILEGES PROCEDURE %token PUBLIC REAL REFERENCES ROLLBACK SCHEMA SELECT SET %token SMALLINT SOME SQLCODE SQLERROR TABLE TO UNION 35 %token UNIQUE UPDATE USER VALUES VIEW WHENEVER WHERE WITH WORK %% sql_list: 40 sql ';' { end_sql (); } | sql_list sql ...

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