Skip to content

Grammar Specification

Gilberto Barbosa edited this page Jun 1, 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>

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

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

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

<select-expr-list> -> <select-expr> <select-comma-expr>

<select-comma-expr> -> , <select-expr> <select-comma-expr> | <empty>

<select-expr> -> <field-spec>

<from-list> -> <table-name> <from-list-expr>

<from-list-expr> -> <empty> | , <table-name> <from-list-expr>

<where-clause> -> <empty> | WHERE <boolean>

<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-n> <boolean-o>

<boolean-o> -> OR <boolean-n> <boolean-o> | <empty>

<boolean-n> -> <boolean-prim> <boolean-n'>

<boolean-n'> -> AND <boolean-prim> <boolean-n'> | <empty>

<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

<entry-list> -> <entry> | <entry> COMMA <entry-list>

<entry> -> <constant>

<expr> -> <arith-term> | <arith-term> ADD-OP <expr>

<arith-term> -> <arith-factor> | <arith-factor> MULT-OP <arith-term>

<arith-factor> -> <opt-add> <primary>

<opt-add> -> <empty> | ADD-OP

<primary> -> <field-spec> | LPAR <expr> RPAR
                          | <constant>

<constant> -> QUOTE <constant-value> QUOTE | NUMBER

<constant-value> -> IDENTIFIER | VALUE

<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