On Sat, May 29, 2021 at 09:51:22PM -0500, Bruce Gray wrote:
> > On May 29, 2021, at 5:57 PM, rir <rir...@comcast.net> wrote:

> >    rule cmp_expression {
> >        | <str_const> <cmp_op> <identifier>
> >        | <num_const> <cmp_op> <identifier>
> >        | ...
> >    }

> I am not at all clear on what you are asking, so if none of my ideas are 
> helpful,
> please consider adding more detail.

You understood more than you were confident of understanding.

Your number one describes my desire but it is not known to exist.

> 1. [...]
> . So, we do not have a convenient shortcut like:
> [...]
>         | COMMUTATIVE( <str_const> <cmp_op> <identifier> )
>         | COMMUTATIVE( <num_const> <cmp_op> <identifier> )
>         | COMMUTATIVE( ... )

Your number two seems the common pattern. And is my intended
final approach (with variation for LHS and RHS overlap).

> 2. [...]
>     rule cmp_operands_A {
>         | <str_const>
>         | <num_const>
>         | ...
>     }
>     rule cmp_operands_B {
>         | <identifier>
>         | ...
>     }
>     rule cmp_expression {
>           <cmp_operands_A> <cmp_op> <cmp_operands_B>
>         | <cmp_operands_B> <cmp_op> <cmp_operands_A>
>     }

Your number three is effectively the concise pattern I desire.
I think of it as list-op.

> 3. [...]
>     rule cmp_operands { # ??? token instead of rule ???
>         | <str_const>
>         | <num_const>
>         | <identifier>
>         | ...
>     }
>     rule cmp_expression {
>         <cmp_operands> ** 2 % <cmp_op>
>     }

Your four is what I had and wanted to improve.

> 4. If none of that compresses the regex (maybe because not every <A> forms a 
> valid pairing with *every* <B>),
> I would make each BopA variant live on the same line as its AopB cousin:
>     rule cmp_expression {
>         | <str_const> <cmp_op> <identifier>   |   <identifier> <cmp_op> 
> <str_const>
>         | <num_const> <cmp_op> <identifier>   |   <identifier> <cmp_op> 
> <num_const>
>         | ...
>     }


> > I imagine that generally this is a useless question, which is
> > avoided by:
> >
> > rule cmp_expression {
> >   <value_expression> <cmp_op> <value_expression>
> > }
> > 
> > but here many tokens under value_expression exist but are not well
> > defined, nor known by me.

> This paragraph confuses me.

What is happening:  I am working off of Postgresql documentation pages
to parse a specific small SQL codebase to support some code generation
( and to learn about grammars, etc.).  Pg documentation is nearly all
top-notch.  They seem to rename tokens just to clarify the larger
statement or construct.  That hinders me from building my grammar from
the bottom up.  SQL's <EXPRESSION> seems comprehensive but rarely worked
hard.  With those issues and facts, I am just dealing with the specific
cases as they arrive while maintaining a SPoT and, hopefully, dispelling
my ignorance generally and about which tokens share identity.

Thanks for the prize behind door number three.

rir

> -- 
> Hope this helps,
> Bruce Gray (Util of PerlMonks)
> 
> 

Reply via email to