help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interesting problem with PostgreSQL grammar ...


From: Hans Aberg
Subject: Re: Interesting problem with PostgreSQL grammar ...
Date: Mon, 22 Nov 2004 00:35:30 +0100
User-agent: Microsoft-Outlook-Express-Macintosh-Edition/5.0.6

You do not say what shift/reduce conflicts you get, so it is hard to follow.
Please make sure to always include pertinent info.

But a casual look suggests that you may get a conflicts between two empty
rules. If that is so, you need to rewrite your grammar.

Otherwise, token precedence (via %right, etc.) can sometimes be used to
resolve shift/reduce conflicts. Look into the .output file to see which
tokens that should be given precedence .


At 13:18 +0000 2004/11/21, Hans-Juergen Schoenig wrote:
>Folks,
>
>I am currently working on some features for PostgreSQL. My target is to
>implement a NOWAIT clause into DELETE, UPDATE and SELECT / SELECT FOR
>UPDATE:
>
>Current the syntax of SELECT looks like that:
>
>microtec=# \h SELECT
>Command:     SELECT
>Description: retrieve rows from a table or view
>Syntax:
>SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
>    * | expression [ AS output_name ] [, ...]
>    [ FROM from_item [, ...] ]
>    [ WHERE condition ]
>    [ GROUP BY expression [, ...] ]
>    [ HAVING condition [, ...] ]
>    [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ]
>    [ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ]
>    [ LIMIT { count | ALL } ]
>    [ OFFSET start ]
>    [ FOR UPDATE [ OF table_name [, ...] ] ]
> 
>where from_item can be one of:
> 
>    [ ONLY ] table_name [ * ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
>    ( select ) [ AS ] alias [ ( column_alias [, ...] ) ]
>    function_name ( [ argument [, ...] ] ) [ AS ] alias [ ( column_alias
>[, ...] | column_definition [, ...] ) ]
>    function_name ( [ argument [, ...] ] ) AS ( column_definition [, ...] )
>    from_item [ NATURAL ] join_type from_item [ ON join_condition |
>USING ( join_column [, ...] ) ]
> 
>
>I want to add NOWAIT to FOR UPDATE ...
>
>    [ FOR UPDATE [ OF table_name [, ...] ]  [NOWAIT]]
>
>I am running into shift / reduce problems when adding the NOWAIT keyword.
>Here are the (to me) relevant parts of
>postgresql-snapshot/src/backend/parser/gram.y:
>
>select_no_parens:
>                  
>simple_select                                           { $$ = $1; }
>                        | select_clause sort_clause
>                                {
>                                        insertSelectOptions((SelectStmt
>*) $1, $2, NIL,
>                  
>NULL, NULL);
>                                        $$ = $1;
>                                }
>                        | select_clause opt_sort_clause
>for_update_clause opt_select_limit
>                                {
>                                        insertSelectOptions((SelectStmt
>*) $1, $2, $3,
>                  
>list_nth($4, 0), list_nth($4, 1));
>                                        $$ = $1;
>                                }
>                        | select_clause opt_sort_clause select_limit
>opt_for_update_clause
>                                {
>                                        insertSelectOptions((SelectStmt
>*) $1, $2, $4,
>                  
>list_nth($3, 0), list_nth($3, 1));
>                                        $$ = $1;
>                                }
>                ;
>
>
>.......
>
>
>for_update_clause:
>                        FOR UPDATE
>update_list                                  { $$ = $3; }
>                        | FOR READ
>ONLY                                                 { $$ = NULL; }
>                ;
>                  
>
>opt_for_update_clause:
>                  
>for_update_clause                                               { $$ = $1; }
>                        | /* EMPTY
>*/                                                   { $$ = NULL; }
>                ;
>                  
>
>update_list:
>                        OF
>name_list                                                    { $$ = $2; }
>                        | /* EMPTY
>*/                                                   { $$ =
>list_make1(NULL); }
>                ;
>
>
>what i have tried is to add opt_nowait to "select_clause opt_sort_clause
>select_limit opt_for_update_clause". this will cause errors.
>opt_nowait is defined as:
>
>opt_nowait:     NOWAIT                  { $$ = TRUE; }
>                        |
>/*EMPTY*/                                             { $$ = FALSE; }
>                ;
>
>Interestingly opt_nowait works for LOCK statements:
>LockStmt:       LOCK_P opt_table qualified_name_list opt_lock opt_nowait
>                                {
>                                        LockStmt *n = makeNode(LockStmt);
>                  
>
>                                        n->relations = $3;
>                                        n->mode = $4;
>                                        n->nowait = $5;
>                                        $$ = (Node *)n;
>                                }
>                ;
>                  
>
>opt_lock:       IN_P lock_type MODE                     { $$ = $2; }
>                        |
>/*EMPTY*/                                             { $$ =
>AccessExclusiveLock; }
>                ;
>                  
>
>lock_type:      ACCESS SHARE                                    { $$ =
>AccessShareLock; }
>                        | ROW
>SHARE                                             { $$ = RowShareLock; }
>                        | ROW EXCLUSIVE
>{ $$ = RowExclusiveLock; }
>                        | SHARE UPDATE EXCLUSIVE                { $$ =
>ShareUpdateExclusiveLock; }
>                        |
>SHARE                                                 { $$ = ShareLock; }
>                        | SHARE ROW EXCLUSIVE                   { $$ =
>ShareRowExclusiveLock; }
>                        |
>EXCLUSIVE                                             { $$ =
>ExclusiveLock; }
>                        | ACCESS EXCLUSIVE
>{ $$ = AccessExclusiveLock; }
>                ;
>                  
>
>opt_nowait:     NOWAIT                  { $$ = TRUE; }
>                        |
>/*EMPTY*/                                             { $$ = FALSE; }
>                ;
>                  
>
>In this case adding opt_nowait will not cause problems at all.
>Can anybody tell me why?
>
>    Best regards,
>
>       Hans
>
>
>
>
>
>
>
>
>
>
>
>
>_______________________________________________
>address@hidden http://lists.gnu.org/mailman/listinfo/help-bison






reply via email to

[Prev in Thread] Current Thread [Next in Thread]