sql_list: sql ';' | sql_list sql ';' ; sql: create_table table '(' base_table_element_commalist ')' | insert_into table opt_column_commalist values_spec | select selection from_clause opt_where_clause | update table SET assignment_commalist opt_where_clause | DELETE FROM table opt_where_clause ; /* ----- create table statement ----- */ create_table: CREATE TABLE ; base_table_element_commalist: column_def | base_table_element_commalist ',' column_def ; column_def: column data_type ; /* ----- insert into statement ----- */ insert_into : INSERT INTO ; opt_column_commalist: /* empty */ | '(' column_commalist ')' ; column_commalist: column | column_commalist ',' column ; values_spec: VALUES '(' insert_atom_commalist ')' ; insert_atom_commalist: atom | insert_atom_commalist ',' atom ; /* ----- select statement ----- */ select: SELECT ; selection: '*' | column_ref_commalist ; column_ref_commalist: column_ref | column_ref_commalist ',' column_ref ; from_clause: FROM table ; /* ----- update statement ----- */ update: UPDATE ; assignment_commalist: /* empty */ | assignment | assignment_commalist ',' assignment ; assignment: column '=' scalar_exp ; /* ----- opt_where_clause & its decendents ----- */ opt_where_clause: /* empty - return BooleanAtom TRUE */ | WHERE search_condition ; search_condition: search_condition OR search_condition | search_condition AND search_condition | NOT search_condition | '(' search_condition ')' | predicate ; predicate: scalar_exp COMPARISON scalar_exp | scalar_exp LIKE atom /* scalar_exp & atom must be string type */ | scalar_exp NOT LIKE atom /* scalar_exp & atom must be string type */ ; scalar_exp: scalar_exp '+' scalar_exp | scalar_exp '-' scalar_exp | scalar_exp '*' scalar_exp | scalar_exp '/' scalar_exp | '+' scalar_exp %prec UMINUS | '-' scalar_exp %prec UMINUS | atom | column_ref | '(' scalar_exp ')' ; atom: STRING | INTNUM ; /* miscellaneous */ column_ref: NAME | NAME '.' NAME /* needs semantics */ ; /* data types */ data_type: CHARACTER | INTEGER ; /* the various things you can name */ table: NAME ; column: NAME /* tokens - defined by regular expression */ STRING: '[^'\n]*' INTNUM: [0-9]+ | [0-9]+"."[0-9]* | "."[0-9]* NAME: [A-Za-z][A-Za-z0-9_]*