www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Redundancy/conflicts in expression rules.

reply "Iain Buclaw" <ibuclaw gdcproject.org> writes:
This might be because the rules I have in place are not complete 
(I'm not implementing a complete D expression parser), but I have 
my doubts on this, and currently leaning on a possible problem in 
the documentation.


I've built up rules in yacc based on what's documented here: 
http://dlang.org/expression.html

However I seem to be getting shift/reduce conflicts around:

AndAndExpression:
         OrExpression
|       AndAndExpression && OrExpression
         CmpExpression
|       AndAndExpression && CmpExpression
;

OrExpression:
         XorExpression
|       OrExpression | XorExpression
;

XorExpression:
         AndExpression
|       XorExpression ^ AndExpression
;

AndExpression:
         ShiftExpression
|       AndExpression & ShiftExpression
;

CmpExpression:
         ShiftExpression
|       EqualExpression
|       IdentityExpression
|       RelExpression
;

CmpExpression:
         ShiftExpression
|       EqualExpression
|       IdentityExpression
|       RelExpression
;


---
Conflict between 'XorExpression: XorExpression '^' AndExpression' 
and token '&'
Conflict between 'ShiftExpression: ShiftExpression RSH 
AddExpression' and token '+'
Conflict between 'ShiftExpression: ShiftExpression RSH 
AddExpression' and token '-'
Conflict between 'ShiftExpression: ShiftExpression LSH 
AddExpression' and token '+'
Conflict between 'ShiftExpression: ShiftExpression LSH 
AddExpression' and token '-'
Conflict between 'AddExpression: AddExpression '+' MulExpression' 
and token '*'
Conflict between 'AddExpression: AddExpression '-' MulExpression' 
and token '*'
---


It's not too much of a problem, I can tweak it (so it follows 
same-ish rules as Java) and it will pass just fine:

AndAndExpression:
         OrExpression
|       AndAndExpression && OrExpression
;

OrExpression:
         XorExpression
|       OrExpression | XorExpression
;

XorExpression:
         AndExpression
|       XorExpression ^ AndExpression
;

AndExpression:
         CmpExpression
|       AndExpression & CmpExpression
;

CmpExpression:
         ShiftExpression
|       EqualExpression
|       IdentityExpression
|       RelExpression
;


I'm just curious if anyone else has stumbled onto this, and 
whether or not it's just human error on my part.  :o)

Regards
Iain.
Feb 12 2014
next sibling parent reply "Brian Schott" <briancschott gmail.com> writes:
On Thursday, 13 February 2014 at 00:00:11 UTC, Iain Buclaw wrote:
 I'm just curious if anyone else has stumbled onto this, and 
 whether or not it's just human error on my part.  :o)

 Regards
 Iain.

It's dangerous to go alone. Take this! https://github.com/Hackerpilot/DGrammar
Feb 12 2014
next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/12/2014 4:24 PM, Iain Buclaw wrote:
 In any case, everything looks lean enough that I'll probably believe
 your documented grammar more than the official dlang site. ;-)

Should issue pull requests for errors found in the grammar!
Feb 12 2014
parent Walter Bright <newshound2 digitalmars.com> writes:
On 2/12/2014 5:37 PM, Brian Schott wrote:
 On Thursday, 13 February 2014 at 01:28:39 UTC, Iain Buclaw wrote:
 On 13 February 2014 01:16, Walter Bright <newshound2 digitalmars.com> wrote:
 On 2/12/2014 4:24 PM, Iain Buclaw wrote:
 In any case, everything looks lean enough that I'll probably believe
 your documented grammar more than the official dlang site. ;-)

Should issue pull requests for errors found in the grammar!

Will do ... in the morning.

See_also: http://d.puremagic.com/issues/show_bug.cgi?id=10233

Thank you. It's important to make such a log of all such errors you find, otherwise the next poor soul will have to suffer through it all over again.
Feb 12 2014
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 2/13/2014 12:42 AM, Iain Buclaw wrote:
 On 13 February 2014 06:17, Kenji Hara <k.hara.pg gmail.com> wrote:
 In git head, 'Grammar' page is added.

 https://github.com/D-Programming-Language/dlang.org/blob/master/grammar.dd

Bleh, that contains the same mistakes!

It should, because it should contain exactly the same grammar as is distributed around the rest of the spec. The two should be corrected in sync, not independently.
Feb 14 2014
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
On 13 February 2014 00:06, Brian Schott <briancschott gmail.com> wrote:
 On Thursday, 13 February 2014 at 00:00:11 UTC, Iain Buclaw wrote:
 I'm just curious if anyone else has stumbled onto this, and whether or not
 it's just human error on my part.  :o)

 Regards
 Iain.

It's dangerous to go alone. Take this! https://github.com/Hackerpilot/DGrammar

Thanks! Having a look at D.g4, I'm seeing that you do the same with the rules: andAndExpression: orExpression | andAndExpression '&&' orExpression ; /*...*/ andExpression: cmpExpression | andExpression '&' cmpExpression ; cmpExpression: shiftExpression | equalExpression | identityExpression | relExpression | inExpression ;
Feb 12 2014
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
On 13 February 2014 00:18, Iain Buclaw <ibuclaw gdcproject.org> wrote:
 On 13 February 2014 00:06, Brian Schott <briancschott gmail.com> wrote:
 On Thursday, 13 February 2014 at 00:00:11 UTC, Iain Buclaw wrote:
 I'm just curious if anyone else has stumbled onto this, and whether or not
 it's just human error on my part.  :o)

 Regards
 Iain.

It's dangerous to go alone. Take this! https://github.com/Hackerpilot/DGrammar

Thanks! Having a look at D.g4, I'm seeing that you do the same with the rules:

In any case, everything looks lean enough that I'll probably believe your documented grammar more than the official dlang site. ;-)
Feb 12 2014
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
On 13 February 2014 01:16, Walter Bright <newshound2 digitalmars.com> wrote:
 On 2/12/2014 4:24 PM, Iain Buclaw wrote:
 In any case, everything looks lean enough that I'll probably believe
 your documented grammar more than the official dlang site. ;-)

Should issue pull requests for errors found in the grammar!

Will do ... in the morning.
Feb 12 2014
prev sibling next sibling parent "Brian Schott" <briancschott gmail.com> writes:
On Thursday, 13 February 2014 at 01:16:47 UTC, Walter Bright 
wrote:
 On 2/12/2014 4:24 PM, Iain Buclaw wrote:
 In any case, everything looks lean enough that I'll probably 
 believe
 your documented grammar more than the official dlang site. ;-)

Should issue pull requests for errors found in the grammar!

Use of my parser keeps finding places where my grammar is wrong. Here's an example from today: https://github.com/Hackerpilot/Dscanner/commit/54118e905f55239fb7c03c101db84b22e4368e51#diff-6331f8b31e134d0bacb245c850fe5404 This reminds me that I haven't synchronized the parser's doc comments with that ANTLR file in a while. Hopefully I'll have time for that on the weekend.
Feb 12 2014
prev sibling next sibling parent "Brian Schott" <briancschott gmail.com> writes:
On Thursday, 13 February 2014 at 01:28:39 UTC, Iain Buclaw wrote:
 On 13 February 2014 01:16, Walter Bright 
 <newshound2 digitalmars.com> wrote:
 On 2/12/2014 4:24 PM, Iain Buclaw wrote:
 In any case, everything looks lean enough that I'll probably 
 believe
 your documented grammar more than the official dlang site. ;-)

Should issue pull requests for errors found in the grammar!

Will do ... in the morning.

See_also: http://d.puremagic.com/issues/show_bug.cgi?id=10233
Feb 12 2014
prev sibling next sibling parent Kenji Hara <k.hara.pg gmail.com> writes:
--047d7b5d256addfffa04f243a473
Content-Type: text/plain; charset=UTF-8

2014-02-13 9:24 GMT+09:00 Iain Buclaw <ibuclaw gdcproject.org>:

 On 13 February 2014 00:18, Iain Buclaw <ibuclaw gdcproject.org> wrote:
 On 13 February 2014 00:06, Brian Schott <briancschott gmail.com> wrote:
 On Thursday, 13 February 2014 at 00:00:11 UTC, Iain Buclaw wrote:
 I'm just curious if anyone else has stumbled onto this, and whether or



 it's just human error on my part.  :o)

 Regards
 Iain.

It's dangerous to go alone. Take this! https://github.com/Hackerpilot/DGrammar

Thanks! Having a look at D.g4, I'm seeing that you do the same with the


In any case, everything looks lean enough that I'll probably believe your documented grammar more than the official dlang site. ;-)

In git head, 'Grammar' page is added. https://github.com/D-Programming-Language/dlang.org/blob/master/grammar.dd Kenji Hara --047d7b5d256addfffa04f243a473 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">2014= -02-13 9:24 GMT+09:00 Iain Buclaw <span dir=3D"ltr">&lt;<a href=3D"mailto:i= buclaw gdcproject.org" target=3D"_blank">ibuclaw gdcproject.org</a>&gt;</sp= an>:<br><blockquote class=3D"gmail_quote" style=3D"margin-top:0px;margin-ri= ght:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-le= ft-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> <div class=3D"">On 13 February 2014 00:18, Iain Buclaw &lt;<a href=3D"mailt= o:ibuclaw gdcproject.org">ibuclaw gdcproject.org</a>&gt; wrote:<br> &gt; On 13 February 2014 00:06, Brian Schott &lt;<a href=3D"mailto:briancsc= hott gmail.com">briancschott gmail.com</a>&gt; wrote:<br> &gt;&gt; On Thursday, 13 February 2014 at 00:00:11 UTC, Iain Buclaw wrote:<= br> &gt;&gt;&gt;<br> &gt;&gt;&gt; I&#39;m just curious if anyone else has stumbled onto this, an= d whether or not<br> &gt;&gt;&gt; it&#39;s just human error on my part. =C2=A0:o)<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; Regards<br> &gt;&gt;&gt; Iain.<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; It&#39;s dangerous to go alone. Take this!<br> &gt;&gt;<br> &gt;&gt; <a href=3D"https://github.com/Hackerpilot/DGrammar" target=3D"_bla= nk">https://github.com/Hackerpilot/DGrammar</a><br> &gt;<br> &gt; Thanks! =C2=A0Having a look at D.g4, I&#39;m seeing that you do the sa= me with the rules:<br> &gt;<br> <br> </div>In any case, everything looks lean enough that I&#39;ll probably beli= eve<br> your documented grammar more than the official dlang site. ;-)<br> </blockquote></div><br></div><div class=3D"gmail_extra">In git head, &#39;G= rammar&#39; page is added.<div><br></div><div><a href=3D"https://github.com= /D-Programming-Language/dlang.org/blob/master/grammar.dd">https://github.co= m/D-Programming-Language/dlang.org/blob/master/grammar.dd</a>=C2=A0<br> </div><div><br></div><div>Kenji Hara</div></div></div> --047d7b5d256addfffa04f243a473--
Feb 12 2014
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
On 13 February 2014 02:23, Walter Bright <newshound2 digitalmars.com> wrote:
 On 2/12/2014 5:37 PM, Brian Schott wrote:
 On Thursday, 13 February 2014 at 01:28:39 UTC, Iain Buclaw wrote:
 On 13 February 2014 01:16, Walter Bright <newshound2 digitalmars.com>
 wrote:
 On 2/12/2014 4:24 PM, Iain Buclaw wrote:
 In any case, everything looks lean enough that I'll probably believe
 your documented grammar more than the official dlang site. ;-)

Should issue pull requests for errors found in the grammar!

Will do ... in the morning.

See_also: http://d.puremagic.com/issues/show_bug.cgi?id=10233

Thank you. It's important to make such a log of all such errors you find, otherwise the next poor soul will have to suffer through it all over again.

I checked over the already existing reports, and this is what I'm seeing: http://d.puremagic.com/issues/show_bug.cgi?id=10232
Feb 13 2014
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
On 13 February 2014 06:17, Kenji Hara <k.hara.pg gmail.com> wrote:
 2014-02-13 9:24 GMT+09:00 Iain Buclaw <ibuclaw gdcproject.org>:

 On 13 February 2014 00:18, Iain Buclaw <ibuclaw gdcproject.org> wrote:
 On 13 February 2014 00:06, Brian Schott <briancschott gmail.com> wrote:
 On Thursday, 13 February 2014 at 00:00:11 UTC, Iain Buclaw wrote:
 I'm just curious if anyone else has stumbled onto this, and whether or
 not
 it's just human error on my part.  :o)

 Regards
 Iain.

It's dangerous to go alone. Take this! https://github.com/Hackerpilot/DGrammar

Thanks! Having a look at D.g4, I'm seeing that you do the same with the rules:

In any case, everything looks lean enough that I'll probably believe your documented grammar more than the official dlang site. ;-)

In git head, 'Grammar' page is added. https://github.com/D-Programming-Language/dlang.org/blob/master/grammar.dd

Bleh, that contains the same mistakes!
Feb 13 2014
prev sibling next sibling parent Rainer Schuetze <r.sagitario gmx.de> writes:
On 13.02.2014 01:00, Iain Buclaw wrote:
 This might be because the rules I have in place are not complete (I'm
 not implementing a complete D expression parser), but I have my doubts
 on this, and currently leaning on a possible problem in the documentation.


 I've built up rules in yacc based on what's documented here:
 http://dlang.org/expression.html

 However I seem to be getting shift/reduce conflicts around:

 AndAndExpression:
          OrExpression
 |       AndAndExpression && OrExpression
          CmpExpression
 |       AndAndExpression && CmpExpression
 ;

 OrExpression:
          XorExpression
 |       OrExpression | XorExpression
 ;

 XorExpression:
          AndExpression
 |       XorExpression ^ AndExpression
 ;

 AndExpression:
          ShiftExpression
 |       AndExpression & ShiftExpression
 ;

 CmpExpression:
          ShiftExpression
 |       EqualExpression
 |       IdentityExpression
 |       RelExpression
 ;

 CmpExpression:
          ShiftExpression
 |       EqualExpression
 |       IdentityExpression
 |       RelExpression
 ;

I think this is by design to disallow comparison operators and binary operators in the same expression without paranthesis: int x = a & b < c; op.d(2): Error: b < c must be parenthesized when next to operator & The grammar in the spec doesn't play nice with generators and isn't always correct, but in this case, I think it is.
Feb 14 2014
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
On 14 February 2014 19:40, Rainer Schuetze <r.sagitario gmx.de> wrote:
 I think this is by design to disallow comparison operators and binary
 operators in the same expression without paranthesis:

 int x = a & b < c;

Yeah, I didn't buy that argument at first. Not least because it didn't look like the conflicts came from '&'
 op.d(2): Error: b < c must be parenthesized when next to operator &

 The grammar in the spec doesn't play nice with generators and isn't always
 correct, but in this case, I think it is.

Enforced brackets could be what is missing here... --- AndAndExpression: ( OrExpression ) | AndAndExpression && ( OrExpression ) | CmpExpression | AndAndExpression && CmpExpression ; /* ... */ AndExpression: CmpExpression | AndExpression & ( CmpExpression ) ; --- Bison likes it... however that seems to have broken expression parsing in other ways. I assume this is because I haven't yet introduced brackets into the grammar yet. :o) Regards Iain.
Feb 15 2014
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
On 15 February 2014 20:09, Iain Buclaw <ibuclaw gdcproject.org> wrote:
 On 14 February 2014 19:40, Rainer Schuetze <r.sagitario gmx.de> wrote:
 I think this is by design to disallow comparison operators and binary
 operators in the same expression without paranthesis:

 int x = a & b < c;

Yeah, I didn't buy that argument at first. Not least because it didn't look like the conflicts came from '&'

As soon as I introduced PrimaryExpression: ( Expression ) ; I just ended up reverting it back, so the expression parser happily accepts (a & b < c); as well as variants with multiple brackets inside. At the moment it's just good to get a D expression evaluator thats' actually working, then worry about was is invalid D later. :o) Regards Iain.
Feb 18 2014
prev sibling next sibling parent "Dejan Lekic" <dejan.lekic gmail.com> writes:
On Thursday, 13 February 2014 at 00:06:11 UTC, Brian Schott wrote:
 On Thursday, 13 February 2014 at 00:00:11 UTC, Iain Buclaw 
 wrote:
 I'm just curious if anyone else has stumbled onto this, and 
 whether or not it's just human error on my part.  :o)

 Regards
 Iain.

It's dangerous to go alone. Take this! https://github.com/Hackerpilot/DGrammar

Brian's ANTLR grammar file is one that matches closely current stat of affairs. I use it in two small Java apps. :)
Feb 18 2014
prev sibling next sibling parent Marco Leise <Marco.Leise gmx.de> writes:
Am Thu, 13 Feb 2014 00:06:10 +0000
schrieb "Brian Schott" <briancschott gmail.com>:

 On Thursday, 13 February 2014 at 00:00:11 UTC, Iain Buclaw wrote:
 I'm just curious if anyone else has stumbled onto this, and 
 whether or not it's just human error on my part.  :o)

 Regards
 Iain.

It's dangerous to go alone. Take this! https://github.com/Hackerpilot/DGrammar

Is it a bad sign if I happen to remember the reference ? :p -- Marco
Feb 18 2014
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 18 Feb 2014 13:18:00 -0500, Marco Leise <Marco.Leise gmx.de> wrote:

 Am Thu, 13 Feb 2014 00:06:10 +0000
 schrieb "Brian Schott" <briancschott gmail.com>:

 On Thursday, 13 February 2014 at 00:00:11 UTC, Iain Buclaw wrote:
 I'm just curious if anyone else has stumbled onto this, and
 whether or not it's just human error on my part.  :o)

 Regards
 Iain.

It's dangerous to go alone. Take this! https://github.com/Hackerpilot/DGrammar

Is it a bad sign if I happen to remember the reference ? :p

No, but it is bad if the "da da da DAAAAA" sound plays in your head while reading it :) -Steve
Feb 18 2014