Remove useless associativity/precedence from parsers - Mailing list pgsql-hackers

From Akim Demaille
Subject Remove useless associativity/precedence from parsers
Date
Msg-id 3A125F91-5810-4E5A-93C6-178A7B34DB3D@lrde.epita.fr
Whole thread Raw
Responses Re: Remove useless associativity/precedence from parsers  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi all,

Many of the grammars could be clarified.  For instance there's a number of useless associativity and/or precedence
declarations. Maybe the point is to leave some form of a documentation, but actually, since it's not used at all by the
tool,that documentation is not checked. 

In the following two proposed patches, I remove directives that are completely useless.  In other places, some
associativityis declared (e.g., with %left) although the associativity is useless, only the precedence matters.  I have
notchanged this, because I don't know what is the version of Bison that is required.  Given that it's a maintainer-side
tool,I would suggest targeting recent versions of Bison, but opinions might differ here. 

Cheers!

commit 75e597aa239d8ebc332d3a29630ecad0133d3d6f
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sun May 19 14:24:33 2019 +0200

    json_path: remove useless precedence directives

    These directives are useless: the generated parser is exactly the
    same (except for line number changes).

diff --git a/src/backend/utils/adt/jsonpath_gram.y b/src/backend/utils/adt/jsonpath_gram.y
index 22c2089f78..82b6529414 100644
--- a/src/backend/utils/adt/jsonpath_gram.y
+++ b/src/backend/utils/adt/jsonpath_gram.y
@@ -115,11 +115,9 @@ static JsonPathParseItem *makeItemLikeRegex(JsonPathParseItem *expr,

 %left    OR_P
 %left    AND_P
-%right    NOT_P
 %left    '+' '-'
 %left    '*' '/' '%'
 %left    UMINUS
-%nonassoc '(' ')'

 /* Grammar follows */
 %%



This second patch could be made simpler: just remove the %token declarations I provided, but then the generated files
aredifferent (but, of course, both parsers are equivalent). 

commit 5322f7303a1a9dfa7cd959d68caeced847ae0466
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sun May 19 14:32:15 2019 +0200

    parser: remove useless associativity/precedence

    Use %token instead to guarantee that the token numbers are the same
    before and after this patch.  As a consequence, the generated files
    are equal.

diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 3dc0e8a4fb..3d4c552cfa 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -766,10 +766,10 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 %left        AT                /* sets precedence for AT TIME ZONE */
 %left        COLLATE
 %right        UMINUS
-%left        '[' ']'
+%token        '[' ']'
 %left        '(' ')'
 %left        TYPECAST
-%left        '.'
+%token        '.'
 /*
  * These might seem to be low-precedence, but actually they are not part
  * of the arithmetic hierarchy at all in their use as JOIN operators.






pgsql-hackers by date:

Previous
From: Dean Rasheed
Date:
Subject: Re: Multivariate MCV stats can leak data to unprivileged users
Next
From: Greg Stark
Date:
Subject: Re: Create TOAST table only if AM needs