Skip to content

Grammar Specification

Rodrigo Machado edited this page May 21, 2020 · 9 revisions

First of all, we need to specify the basic statement sql:

<statement> -> <dme-statement> | <dde-statement> | ...

Where the ... means the other type of statements that will be included after.

Now we have to specify the dme-statement that will include the SELECT statement.

<dme-statement> -> <selection> | <insertion> | <update> | <deletion>

For now we just need the <selection> specification.

<selection> -> <select-clause> FROM <from-list> <where-clause> <group-order-clause>

<select-clause> -> SELECT <distinct-clause> <select-list>

<distinct-clause> -> <empty> | DISTINCT

<select-list> -> <select-expr-list> | *

<select-expr-list> -> <select-expr> |  COMMA <select-expr-list>

<select-expr> -> <expr>

<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

<group-order-clause> -> <empty> |
                        GROUP BY <field-spec-list> |
                        ORDER BY <field-spec-list>

<boolean> -> <boolean-term> |
             <boolean> OR <boolean-term>

<boolean-term> -> <boolean-factor> |
                  <boolean-term> AND <boolean-factor>

<boolean-factor> -> <boolean-prim>

<boolean-prim> -> <predicate>

<predicate> -> <expr> <comparison> <table-spec>

<comparison> -> <comp-op>

<comp-op> -> EQ |
             <relop> <all-any-opt> |
             <in-notin>

<all-any-opt> -> <empty> |
                 <all-any>

<all-any> -> ALL | ANY

<in-notin> -> IN | NOT IN

<relop> -> NE | GT | LT | LWEDGE | RWEDGE

<table-spec> -> <literal> | <expr>

<literal> -> <literal-tuple> | LPAR <entry-list> RPAR

<literal-tuple> -> <entry> | LWEDGE <entry-list> RWEDGE

<and-or> -> AND | OR

<field-spec-list> -> <field-spec>

<field-spec> -> <field-name> | <table-name> . <field-name>

<field-name> -> IDENTIFIER

<table-name> -> IDENTIFIER

<empty> -> EPSN 

Clone this wiki locally