[antlr-interest] Java out of Memeroy error On my grammor
Jim Idle
jimi at temporal-wave.com
Tue Dec 15 19:19:17 PST 2009
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of ÇüººÍ¼
Sent: Tuesday, December 15, 2009 6:27 PM
To: antlr-interest at antlr.org
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091215/a0554b28/attachment.html
More information about the antlr-interest
mailing list