Compilers
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs Compilers

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old May 9th, 2008, 02:50 PM
judicator3
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Bison conflict ?

Hello All:

I am writing a parser to parse SQL (actually T-SQL for MS Sql Server).
I am getting a shift/reduce conflict that I don't know how to solve. I
know the reason of the conflict and I can give you 2 valid SQL
statements that can be parsed in two different ways. I just don't know
how to solve that in my grammar.

Consider the following two valid SQL statements:

Statement #1:
select b from s where b not in ( (select a from t where a = 1), 8, 9 );

Statement #2:
select b from s where b not in ( (select a from t where a = 1)
union (select a from t where a = 2) );


In stmt#1, the search condition inside the "not in" is a list of
expressions. In stmt#2, the search condition inside the "not in" is
another query combined with UNIN.

Here is a simplified version of my bison grammar:

expression: ICNST
| expression '+' expression
| expression '-' expression
| expression '*' expression
| expression '/' expression
| expression '%' expression


| '(' expression ')'
| '(' query_specification ')'


;

exp_list: exp_list ',' expression
| expression
;

predicate: expression '>' expression
| expression '<' expression
| expression LIKE expression


| expression IN '(' exp_list ')'
| expression NT IN '(' exp_list ')'
| expression IN '(' query_list ')'
| expression NT IN '(' query_list ')'


;

query_list: query_list UNIN query_list
| '(' query_list ')'
| query_specification
;

/*
* This is the grammar for a select statement
*/
query_specification: SELECT select_list into_clause from_clause
where_clause group_by_clause having_clause



The ambiguity arise when I give a statement like this:

Statement #3:
select b from s where b not in ( (select a from t where a = 1) );

The parser can treat the search condition as an exp_list or a
query_list.

Can someone point me out how to formulate my grammar.

Thanks
Richard

Reply With Quote
  #2  
Old May 10th, 2008, 09:11 PM
Yunzhong
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Bison conflict ?

Richard,
Consider changing these rules:
exp_list =expression;
expression ='(' query_specification ')';
query_list ='(' query_list ')';
query_list =query_specification;

Whether the query_spec in your statement #3 should reduce to exp_list
or query_list will depend on the particular SQL dialect you are
working with, especially the treatment of redundant parentheses. You
may also consider creating an extra nonterminal such as
exp_or_query_list.

Hope it helps.
Y.


Reply With Quote
Reply

Viewing: Web Development Archives FAQs Compilers > Bison conflict ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT