Bison Grammar

When you create your own database, you also have to define a query language. A query language can be as confusing as a real world language if the syntax rules are not well defined. A query can be as short as a single line or may span across a few pages.

Our expectation is that the language grammar rules should identify

  1. Whether the query strictly follows the rules.
  2. The meaning of query does not create ambiguity for database server.
  3. Error cases where query does not conform to rules.

Writing the above in any programming language like C, C++, Java, Python is quite difficult and not desirable when you have a major task of writing a database. Bison is a generator of query parser. Bison generator expects a input file where the grammar rules are specified. Typically the file is given a .y extension. From this grammar file, the Bison generator can generate a parser in C/C++ with functions that do the parsing work.

parser_generator

We will study in detail about grammar and parsing logic later.