DB2 DDL Parser using ANTLR 3 -
i trying build antlr 3 grammar db2 ddl statement (create table) , finding decision can match input such "data" using multiple alternatives: 1, 2. following db2 ddl documentation document.
i have mapped syntax diagrams grammar. problem there optional clauses , path can same point , hence multiple alternatives. have used backtrack option want other solution of this. can please me in regard.
please have @ grammar:
unit: create_table_statement ; create_table_statement: create_table_statement_rest ; create_table_statement_rest: create table id create_table_opts organize_by_items? data capture (none|changes) in_tbspc_cyc tablespace_opts? distribution_clause? partitioning_clause? compress_ny_val_compression with_restrict_on_drop? not_logged_init? ccsid_ascii_unicode? (security policy name)? (options lparen add name name (comma name name)* rparen)? ; with_restrict_on_drop: restrict on drop ; not_logged_init: not logged ; ccsid_ascii_unicode: ccsid (ascii|unicode) ; create_table_opts: element_list |of name typed_table_opts? |materialized_query_definition |staging_table_definition |like name copy_opts? ; organize_by_items: organize (dimensions_item|key_sequence_items) ; dimensions_item: dimensions? lparen id (comma id)* rparen ; key_sequence_items: key sequence sequence_key_spec ; sequence_key_spec: lparen seq_key_spec_one (comma seq_key_spec_one) rparen (allow|disallow) overflow (pctfree digit)? ; seq_key_spec_one: id (starting from? constant)? ending at? digit ; in_tbspc_cyc: in (name (comma name)*) no? cycle? ; tablespace_opts: //tablespace_opt_one? (index in name)? (log in name (comma name)*)? ; distribution_clause: distribute distribute_by_opts ; distribute_by_opts: distribution_item_one |distribution_item_two ; distribute_by: distribute ; distribution_item_one: hash lparen id (comma id)* rparen ; distribution_item_two: replication ; tablespace_opt_one: index in name log in name ; element_list: lparen element_list_items (comma element_list_items)* rparen ; materialized_query_definition: (id (comma id)*)? lparen fullselect rparen materialized_query_table_opts ; staging_table_definition: (lparen name (comma name)* rparen) name propagate immediate ; fullselect: ; materialized_query_table_opts: no data copy_opts? | refreshable_table_opts ; element_list_items: column_definition|referential_constraint|check_constraint ; column_definition: name data_type? column_opts? ; copy_opts: ((including|excluding) column? defaults)? (excluding|including) identity (column attributes)? ; refreshable_table_opts: data deferred refresh (deferred|immediate) (enable|disable) query optimization (maintained (system|user|federated_tool))? ; data_type: smallint |integer|int |bigint |float (lparen digit rparen)? |real |double precision? |(decimal|dec|numeric|num) (lparen digit (comma integer)? rparen)? |(dt_char|dt_vchar|long varchar) (for bit data)? |((blob|binary large object)|(clob|(character|char) large object|dbclob) (lparen digit (k|m|g) rparen)?) |graphic (lparen digit rparen) |vargraphic (lparen digit rparen) |long vargraphic |date |time |timestamp |xml //|name //added name instead of 2 below replaced //|distinct_type_name //|structured_type_name |ref name |(lparen sysproc dot rparen)? db2securitylabel ; dt_char : (character|char)(lparen digit rparen)? ; dt_vchar : (varchar|((char|character) varying))lparen digit rparen ; distinct_type_name : name ; structured_type_name : name ; column_opts: column_options_items+ ; column_options_items: not null |lob_opts |scope name |((constraint name)? ((primary key|unique)| references_clause|(check_condition constraint_attributes))) |generated_column_spec |(inline length digit) |(compress system default) |(column secured id) ; lob_opts: not? logged not? compact ; generated_column_spec: default_clause|generated_by_identity|generated_by_exp ; default_clause: with? default default_values? ; default_values: default_values_items |cast_function lparen default_values_items rparen |null ; default_values_items : constant |datetime_special_register |user_special_register |current schema ; datetime_special_register: current date |current time |current timestamp ; user_special_register: current user |session_user |system_user ; cast_function: //needs figured out ; generated_by_identity: generated (always|(by default)) identity_opts? ; identity_opts: identity lparen identity_options_items (identity_options_items)* rparen ; identity_options_items: start digit |increment digit |no minvalue |minvalue digit |no maxvalue |maxvalue digit |no cycle |cycle | (no cache | cache digit)//cache 20 needs seen |no order |order ; generated_by_exp: generated always? generation_expression ; generation_expression: //needs figured out ; unique_constraint: (constraint name)? (unique|primary key) lparen name (comma name)* rparen ; referential_constraint: (constraint id)? foreign key lparen id (comma id)* rparen references_clause ; references_clause: references name (lparen id (comma id)* rparen)? rule_clause constraint_attributes ; rule_clause: on delete (no action | restrict|cascade|set null) on update (no action|restrict) ; check_constraint: (constraint name) check check_condition constraint_attributes ; check_condition: search_condition|functional_dependency ; constraint_attributes: not? enforced (enable|disable) query optimization ; search_condition: //needs done ; functional_dependency: (id | (lparen id (comma id)* rparen)) determined (id | (lparen id (comma id)* rparen)) ; typed_table_opts: (hierarchy name|under_clause)? typed_element_list? ; typed_table_options_item2: under_clause ; under_clause: under name inherit select privileges ; typed_element_list: lparen typed_element_list_items (comma typed_element_list_items)* rparen ; typed_element_list_items: oid_column_definition | with_opts | unique_constraint | check_constraint ; oid_column_definition: ref name user generated ; with_opts: name options column_opts ; partitioning_clause: part_by_range range_partition_spec ; part_by_range: partition range? ; compress_ny_val_compression: compress (no|yes) (value compression)? ; range_partition_spec: lparen partition_expression (comma partition_expression)* rparen lparen partition_element (comma partition_element)* rparen ; partition_element: partition_boundry_element |start_with_boundry_spec ; partition_boundry_element: (partition name)? boundary_spec (in name)? ; start_with_boundry_spec: boundary_spec every (duration_with_paren|duration_without_paren) ; duration_with_paren: lparen constant duration_label rparen ; duration_without_paren: constant duration_label ; partition_expression: nulls (last|first) ; boundary_spec: boundary_spec_path_one|boundary_spec_path_two ; boundary_spec_path_one: starting_clause ending_clause ; boundary_spec_path_two: ending_clause ; starting_clause: starting from? (starting_ending_with_repeat|starting_ending_without_repeat) (inclusive|exclusive) ; ending_clause: ending at? (starting_ending_with_repeat|starting_ending_without_repeat) (inclusive|exclusive) ; starting_ending_with_repeat: lparen starting_ending_clause_values (comma starting_ending_clause_values)* rparen ; starting_ending_without_repeat: starting_ending_clause_values ; duration_label: year|years|month|months|day|days|hour|hours|minute|minutes|second|seconds|microsecond|microseconds ; starting_ending_clause_values: constant|minvalue|maxvalue ; constant: digit ; name : id; ///////////////////////////////////////////////end parser rules/////////////////////////////////////////////////// ///////////////////////////////////////////////lexer rules/////////////////////////////////////////////////////// ws : ( '\t' | ' ' | '\r' | '\n' )+ { $channel = hidden; } ; comma : ',' ; equal: '='; string_literal
: ('n'|'u')?'\''( ~('\'') | '\'\'' )* '\'' ;
id : ('a'..'z'|'a'..'z'|'_') ('a'..'z'|'a'..'z'|'0'..'9'|'_')* ; digit : '0'..'9'+ ;
any in regard appreciated.
Comments
Post a Comment