110 likes | 281 Views
The SQL Database Grammar. BNF Grammar for SQL /* The grammar rules that follow have been taken from */ /* "System R", Appendix II, M.M. Astrahan, et al., ACM Trans. */ /* on Database Systems, Vol. 1, No. 2, June 1976. */
E N D
The SQL Database Grammar BNF Grammar for SQL /* The grammar rules that follow have been taken from */ /* "System R", Appendix II, M.M. Astrahan, et al., ACM Trans. */ /* on Database Systems, Vol. 1, No. 2, June 1976. */ /* The rules given below in BNF have the following assumptions: */ /* (1) all non-terminals are in lower-case, */ /* (2) all terminals (recognized by LEX/lex.yy.c) are in upper-case, */ <statement> ::= <dml-statement> | <ddl-statement> <dml-statement> ::= <selection> | <insertion> | <deletion> | <update> <selection> ::= <select-clause> FROM <from-list> <where-clause> <grp-ord-clause> <select-clause> ::= SELECT <select-list> <select-list> ::= <sel-expr-list> | MULT-OP <sel-expr-list> ::= <sel-expr> | <sel-expr-list> COMMA <sel-expr> <sel-expr> ::= <expr>
The SQL Database Grammar <from-list> ::= <table-name> | <from-list> COMMA <table-name> <where-clause> ::= <empty> | WHERE <boolean> <nested-select> <nested-select> ::= <empty> | <and-or> <table-name> <comparison> LPAR <selection> RPAR <grp-ord-clause> ::= <empty> | GROUP BY <field-spec-list> | ORDER BY <field-spec-list> <insertion> ::= INSERT INTO <receiver> COLON <insert-spec-source> <receiver> ::= <table-name> <insert-spec-target> <insert-spec-target> ::= <empty> | LPAR <field-name-list> RPAR <field-name-list> ::= <field-name > | <field-name-list> COMMA <field-name> <field-name-list> ::= <field-name > | <field-name-list> COMMA <field-name> <insert-spec-source> ::= <literal>
The SQL Database Grammar <deletion> ::= DELETE <table-name> <where-clause> <update> ::= UPDATE <table-name> <set-clause-list> <where-clause> <set-clause-list> ::= <set-clause> <set-clause> ::= SET <field-name> EQ <expr> <boolean> ::= <boolean-term> | <boolean> OR <boolean-term> <boolean-term> ::= <boolean-factor> | <boolean-term> AND <boolean-factor> <boolean-factor> ::= <boolean-primary> <boolean-primary> ::= <predicate> <predicate> ::= <expr> <comparison> <table-spec> <comparison> ::= <comp-op> <comp-op> ::= EQ | <relat-op> <all-any-opt> | <in-notin> <all-any-opt> ::= <empty> | <all-any>
The SQL Database Grammar <all-any> ::= ALL |ANY <in-notin> ::= IN |NOT IN <relat-op> ::= NE |RWEDGE |GE |LWEDGE |LE <table-spec> ::= <literal> | <expr> <literal> ::= <lit-tuple> | LPAR <entry-list> RPAR <lit-tuple> ::= <entry> | LWEDGE <entry-list> RWEDGE <entry-list> ::= <entry> | <entry-list> COMMA <entry> <entry> ::= <constant> <expr> ::= <arith-term > | <expr> ADD-OP <arith-term> <arith-term> ::= <arith-factor> | <arith-term> MULT-OP <arith-factor> <arith-factor> ::= <opt-add-op> <primary> <opt-add-op> ::= <empty> |ADD-OP <and-or> ::= AND |OR
The SQL Database Grammar <primary> ::= <field-spec> | <set-fn> LPAR <expr> RPAR | LPAR <expr> RPAR | <constant> <field-spec-list> ::= <field-spec> <field-spec> ::= <field-name> | <table-name> DOT <field-name> <set-fn> ::= AVG |MAX |MIN |SUM |COUNT <constant> ::= QUOTE <constant-value> QUOTE | INTEGER <constant-value> ::= IDENTIFIER |VALUE <field-name> ::= IDENTIFIER <table-name> ::= IDENTIFIER <empty> ::= EPSILON
The SQL Database Grammar <ddl-statement> ::= <create-table> <create-table> ::= CREATE TABLE <table-name> COLON <field-defn-list> <field-defn-list> ::= <field-defn> | <field-defn-list> COMMA <field-defn> <field-defn> ::= <field-name> LPAR <type> <null-opt> RPAR <type> ::= CHAR LPAR INTEGER RPAR | INT LPAR INTEGER RPAR | FLOAT LPAR INTEGER RPAR <null-opt> ::= <empty> | COMMA NONULL