Re: [PATCH for Dlang support 1/4] Changed rule that was interpreting +number as -number

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <[email protected]>
Hi Adela,

> Le 1 sept. 2020 à 20:54, Adela Vais <[email protected]> a écrit :
> 
> ---
> examples/d/calc.y | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/examples/d/calc.y b/examples/d/calc.y
> index b0dee929..15b4f7c7 100644
> --- a/examples/d/calc.y
> +++ b/examples/d/calc.y
> @@ -61,7 +61,7 @@ exp:
> | exp "-" exp          { $$ = $1 - $3; }
> | exp "*" exp          { $$ = $1 * $3; }
> | exp "/" exp          { $$ = $1 / $3; }
> -| "+" exp  %prec UNARY { $$ = -$2; }
> +| "+" exp  %prec UNARY { $$ = $2; }
> | "-" exp  %prec UNARY { $$ = -$2; }
> | "(" exp ")"          { $$ = $2; }
> ;

Thanks!

I will install your patch as follows.  Please, rewrite your commit
messages to match our style (have a look at git log to get some
idea).

Cheers!

commit f3bcb3de0e4bf9eb3e771857917e19aa271b4c30
Author: Adela Vais <[email protected]>
Date:   Tue Sep 1 21:54:34 2020 +0300

    examples: d: fix the handling of unary +
    
    It was interpreting "+exp" as "-exp".
    
    * examples/d/calc.y: Fix.
    * examples/d/calc.test: Check it.

diff --git a/examples/d/calc.test b/examples/d/calc.test
index cf4f80a8..6b237592 100644
--- a/examples/d/calc.test
+++ b/examples/d/calc.test
@@ -20,6 +20,16 @@ cat >input <<EOF
 EOF
 run 0 7
 
+cat >input <<EOF
++1 + +2 * +3
+EOF
+run 0 7
+
+cat >input <<EOF
+-1 + -2 * -3
+EOF
+run 0 5
+
 cat >input <<EOF
 1 + 2 * * 3
 EOF
diff --git a/examples/d/calc.y b/examples/d/calc.y
index b0dee929..15b4f7c7 100644
--- a/examples/d/calc.y
+++ b/examples/d/calc.y
@@ -61,7 +61,7 @@ exp:
 | exp "-" exp          { $$ = $1 - $3; }
 | exp "*" exp          { $$ = $1 * $3; }
 | exp "/" exp          { $$ = $1 / $3; }
-| "+" exp  %prec UNARY { $$ = -$2; }
+| "+" exp  %prec UNARY { $$ = $2; }
 | "-" exp  %prec UNARY { $$ = -$2; }
 | "(" exp ")"          { $$ = $2; }
 ;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.