Skip to Content
flex & bison
book

flex & bison

by John Levine
August 2009
Intermediate to advanced
292 pages
7h 31m
English
O'Reilly Media, Inc.
Content preview from flex & bison

Appendix A. SQL Parser Grammar and Cross-Reference

Since the grammar for the SQL parser in Chapter 4 is so large, here’s a list of the rules in the order they appear in the source file, as well as a cross-reference of each token and nonterminal symbol with the rules where they appear. This cross-reference is for the slightly extended version in Chapter 8 that includes error recovery rules.

The listing in Example A-1 and the cross-references in Example A-2 are extracted from the listing file lpmysql.output created when bison compiled the grammar. The listing also includes a list of unused tokens, of which this grammar has quite a few since it defines SQL keywords not used in the subset we parse, and it includes the complete set of parser states and shift and reduce actions. The entire listing is more than 10,000 lines long, much too long to include in this book, but is invaluable for reference when debugging a grammar.

Example A-1. SQL grammar listing

 0 $accept: stmt_list $end 1 stmt_list: stmt ';' 2 | stmt_list stmt ';' 3 | error ';' 4 | stmt_list error ';' 5 stmt: select_stmt 6 select_stmt: SELECT select_opts select_expr_list 7 | SELECT select_opts select_expr_list FROM table_references opt_where opt_groupby opt_having opt_orderby opt_limit opt_into_list 8 opt_where: /* empty */ 9 | WHERE expr 10 opt_groupby: /* empty */ 11 | GROUP BY groupby_list opt_with_rollup 12 groupby_list: expr opt_asc_desc 13 | groupby_list ',' expr opt_asc_desc 14 opt_asc_desc: /* empty */ 15 | ASC 16 | ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rust in Action

Rust in Action

Tim McNamara
Learning React, 2nd Edition

Learning React, 2nd Edition

Alex Banks, Eve Porcello
Generative AI Design Patterns

Generative AI Design Patterns

Valliappa Lakshmanan, Hannes Hapke

Publisher Resources

ISBN: 9780596805418Errata Page