From: [email protected] 
[mailto:[email protected]] On Behalf Of ÇüººÍ¼
Sent: Tuesday, December 15, 2009 6:27 PM
To: [email protected]
Subject: [antlr-interest] Java out of Memeroy error On my grammor
 
Hello all :
    I recently want to make a sql complier to check sql syntax before send it 
to database,i write simple sql grammor for select statement list below:
SimpleSQL.g
grammar SimpleSQL;
 
options {
  language = Java;
}
 
start_rule
  :
  select_query
  ;
 
select_query
  :
  select ('UNION'('ALL'| 'DISTINCT')? select_query)?
  ;
 
select
  :
  'SELECT'('ALL' | 'DISTINCT')? select_list 
   from_clause (where_clause)? (group_clause)? (orderby_clause)?
  ;
 
orderby_clause
  :
  'ORDER' 'BY' order_by_exprs
  ;
 
order_by_exprs
  :
  order_by_expr (COMMA order_by_expr)*
  ;
 
order_by_expr
  :
  (
    identifier
    | (identifier DOT identifier)
  )
  (
    'ASC'
    | 'DESC'
  )?
  ;
 
where_clause
  :
  'WHERE' (search_conditions)
  ;
 
search_condition
  :condition_expr R (ATSIGN)? right_expr |condition_expr RN NULL 
 ;
 
search_conditions
  : 
  search_condition((AND|OR) search_condition)*
  ;
 
group_clause
  :
  'GROUP BY' (column (COMMA column)*) (having_clause)*
  ;
 
having_clause
  :
  'HAVING' (search_conditions)
  ;
ATSIGN:'@';
AND
  :
  'AND'
  ;
 
OR
  :
  'OR'
  ;
 
R
  :
  '='
  | '!='
  | '<'
  | '<='
  | '>'
  | '>='
  ;
 
RN
  :
  'IS'('NOT')?
  ;
 
NULL
  :
  'NULL'
  ;
condition_expr
  :
  column_elemnent
  ;
right_expr:
  RVALUE
  |condition_expr
;
parameters: ;
 
select_list
  :
  ASTERISK
  | column_elemnent (COMMA column_elemnent)*
  ;
 
column_elemnent
  :
  column
  | aggregate_function '(' column ')'
  ;
 
aggregate_function
  :
  'COUNT'
  | 'SUM'
  | 'MAX'
  | 'MIN'
  | 'AVG'
  ;
 
from_clause
  :
  'FROM' table_reference (COMMA table_reference)*
  ;
 
table_reference
  :
  column_alias
  |
  (
    column_alias
    (
      'INNER'
      | 'LEFT'
      | 'RIGHT'
    )?
    'JOIN' table_reference (correlation_name)? ('ON' search_conditions)
  )
  ;
column_alias:
  identifier (correlation_name)
;
table_schema
  :
  identifier
  ;
  
correlation_name
  :
   (AS)? identifier
  ;
 
column
  :
  identifier
  | identifier DOT identifier
  | identifier DOT ASTERISK
  ;
 
identifier
  :
  ID
  | '"' ( ~('"' ))* '"'
 
This does not mean what you think it means and also it conflicts with the fact 
that you have this in your lexer rule ID already.
 
 
In general, make real lexer tokens instead of using 'STRING'. For instance you 
have 'GROUP BY' which will lonely work with one space between. You want a token 
for GROUP and a token for BY.
 
Your RVALUE and ID rules are ambiguous as well as a couple of others. But more 
importantly your RVALUE rule is using * instead of + and this means you lexer 
rule matches an empty string, which it will continue to do until you run out of 
memory J
 
Jim


--

You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to