Shift-Reduce Error but not classic hanging else?

5 views
Skip to first unread message

JonathanAn...@gmail.com

unread,
Mar 17, 2008, 9:08:33 PM3/17/08
to GOLD Parsing System

Ok Gurus, I have rendered 99% of TSQL 2005 into a grammar.
Everything is looking pretty good. Except for one pesky little
problem with the TSQL select statement and the TSQL 'WITH' keyword.

Please consider this TSQL 2005 syntax fragment:

WITH foo (name,address) AS ( SELECT name,address FROM customer )
SELECT * from Customer WITH ( NOLOCK )

-or-

WITH foo (name,address) AS ( SELECT name,address FROM customer )
SELECT * from Customer GROUP BY State WITH CUBE

The first line of both queries is option as are ending portion of both
second lines (WITH NOLOCK, WITH CUBE)

What would the proper production for this look like?

TIA
-Jonathan






Dave Dolan

unread,
Mar 18, 2008, 8:53:03 AM3/18/08
to gold-pars...@googlegroups.com
what does the production you've got now look like?
--
---------------------------------------------------------------
Dave Dolan
Certified Computer Geek-inator
http://davedolan.com/blog
dave....@gmail.com

JonathanAn...@gmail.com

unread,
Mar 20, 2008, 12:11:08 AM3/20/08
to GOLD Parsing System
Here is simplified version. A TSQL select statement may optionally
begin with the 'WITH' keyword/clause and optionally end with a 'WITH'
keyword/clause. I have created a simple grammar to demonstrate this
problem:

"Start Symbol" = <Statement Block>

{ID Head} = {Letter} + [_]
{ID Tail} = {Alphanumeric} + [_]
Identifier = {ID Head}{ID Tail}*

<Statement Block> ::= <Test statement> <Statement Block>
| <Test statement>

<Test statement> ::= <With> 'SELECT' <Lock>

<Lock> ::= 'WITH' '(' 'NOLOCK' ')'
|

<With> ::= 'WITH' Identifier
|

This is only a problem in a <statement block> and not a single <test
statement>.

Thanks
-Jonathan
> dave.do...@gmail.com- Hide quoted text -
>
> - Show quoted text -

Manfred_Nowak

unread,
Mar 20, 2008, 6:26:09 AM3/20/08
to GOLD Parsing System


On Mar 20, 5:11 am, JonathanAndrewNew...@gmail.com wrote:
> <Test statement> ::= <With> 'SELECT' <Lock>

A sequence of <Test statement> is not LALR(1) because after
recognizing the 'SELECT' and on seeing the 'WITH' nobody can decide
wether the 'WITH' will be the start of a <With> or a <Lock>. Note that
assuming a <Lock> would require a Shift and assuming a <With> would
require a reduction.

This can be solved for example by changing the current productions for
the language described by the regular expression
( [<With>] 'SELECT' [<Lock])*
to productions for a superlanguage described by the regular expression
( [<With>] ('SELECT' [<Lock>][<With>])*
or similar---the details are left to the reader---and in the
semantical phase disallow the words which are in the superlanguage
only

-manfred.

JonathanAn...@gmail.com

unread,
Mar 20, 2008, 8:51:28 AM3/20/08
to GOLD Parsing System
Thanks manfred. I came to the same conclusion that the sequnce of
<Test statement> is not LALR(1). But I am not sure that I understand
the description of your solution. I am not familiar with the term
'superlanguage' I know how to solve my problem by preprocessing the
input with a regular expression. Is this possible from within GOLD
parser with a single grammar?

Thanks
-Jonathan

Manfred_Nowak

unread,
Mar 20, 2008, 1:57:29 PM3/20/08
to GOLD Parsing System
On Mar 20, 1:51 pm, JonathanAndrewNew...@gmail.com wrote:
> I am not familiar with the term 'superlanguage'

It is quite possible, that this term is not in common usage. I thought
that it would be clear from the example.
Please note, that in my example of a superlanguage a trailing <With>
would be accepted without a following 'SELECT'.
This means that more words are accepted than in the original intended
language; in this sense the example uses a superior, i.e. super,
language.

>  I know how to solve my problem by preprocessing the
> input with a regular expression.  Is this possible from within GOLD
> parser with a single grammar?

No GOLD is a LALR(1) parser generator only, not a parsing system in
any sense. However, if one knows how to preprocess a source with a
regular expression parser, one should be able to implement the
resulting finite automaton as productions within GOLD. I just dont'
want to do all your work ;-)

-manfred

JonathanAn...@gmail.com

unread,
Mar 20, 2008, 8:54:50 PM3/20/08
to GOLD Parsing System
Got it.

Thanks
-Jonathan
Reply all
Reply to author
Forward
0 new messages