Chapter 5. Parsing SQL
SQL (which stands for Structured Query Language and is usually pronounced sequel) is the most common language used to handle relational data bases. First we’ll develop a SQL parser that checks the syntax of its input but doesn’t do anything else with it. Then we’ll turn that into a preprocessor for SQL embedded in C programs.
This parser is based on the definition of SQL in C. J. Date, A Guide to the SQL Standard, Second Edition, Addison-Wesley, 1989. Date’s description is written in Backus-Naur Form or BNF, a standard form used to write formal language descriptions. Yacc input syntax is similar to BNF except for the punctuation, so in many places it was sufficient to transliterate the BNF to get the corresponding yacc rules. In most cases we use the same symbol names Date did, although in a few places we’ve deviated from his usage in order to make the grammar suitable for yacc.
The ultimate definitions for SQL are the standards documents, ANSI X3.135-1989 (which defines SQL itself) and ANSI X3.168-1989 (which defines the way to embed SQL in other programming languages).
A Quick Overview of SQL
SQL is a special purpose language for relational data bases. Rather than manipulating data in memory, it manipulates data in data base tables, referring to memory only incidentally.
Relational Data Bases
A data base is a collection of tables, which are analogous to files. Each table contains rows and columns, which are analogous to records and fields. The rows in a table ...