You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Daniel Sun <re...@hotmail.com> on 2018/02/22 08:29:46 UTC
[GEP] Refine parsing negative numbers
Hi all,
Groovy parses negative numbers as unary expression. For example, `-1`
is parsed as `-``1`, older parser parses negative numbers twice, so does the
Parrot parser for the identical output...
I suggest to parse negative numbers as REAL numbers instead of unary
expression[1]. It will break the edge case, for example: `-1(a, b, c)` is
parsed as `-(1.call(a, b, c))`, after refining, `-1(a, b, c)` is parsed as
`-1.call(a, b, c)`.
Any thoughts? If no PMC votes -1 on this GEP in 72 hours, I will
work on it.
Cheers,
Daniel.Sun
[1]
https://github.com/danielsun1106/groovy-parser/blob/master/src/main/antlr/GroovyParser.g4#L796
--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Re: [GEP] Refine parsing negative numbers
Posted by "Daniel.Sun" <su...@apache.org>.
OK. I see ;-)
--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Re: [GEP] Refine parsing negative numbers
Posted by Guillaume Laforge <gl...@gmail.com>.
We have to be careful with such breaking changes, as it could change the
results of existing calculations.
The other aspect being the fact that the AST would be different, so it
might have a small impact on some AST transformations that would look at
such constant numbers.
On Thu, Feb 22, 2018 at 10:53 AM, Daniel Sun <re...@hotmail.com>
wrote:
> Hi Paul,
>
> Thanks for your finding these discussion.
>
> As Jochen said: Ruby and Python calculate `-2**4` and return `-16`,
> Groovy returns the same value currently.
>
> But Scala/Excel returns `16`...
>
> Maybe Ruby/Python/Groovy behaves properly for most people...
>
>
> blackdrag wrote
> > I just checked Ruby and Python and there -2**4 will return -16, same for
> > -2^4 in
> > Lua. So now I am wondering if that is the right thing for unary minus
> >
> >
> > bye blackdrag
>
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>
--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform
Blog: http://glaforge.appspot.com/
Social: @glaforge <http://twitter.com/glaforge> / Google+
<https://plus.google.com/u/0/114130972232398734985/posts>
Re: [GEP] Refine parsing negative numbers
Posted by Daniel Sun <re...@hotmail.com>.
Hi Paul,
Thanks for your finding these discussion.
As Jochen said: Ruby and Python calculate `-2**4` and return `-16`,
Groovy returns the same value currently.
But Scala/Excel returns `16`...
Maybe Ruby/Python/Groovy behaves properly for most people...
blackdrag wrote
> I just checked Ruby and Python and there -2**4 will return -16, same for
> -2^4 in
> Lua. So now I am wondering if that is the right thing for unary minus
>
>
> bye blackdrag
Cheers,
Daniel.Sun
--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Re: [GEP] Refine parsing negative numbers
Posted by Paul King <pa...@asert.com.au>.
This and similar issues have come up before. It would be worthwhile
searching the mail archives.
At least one related change we backed out of last time. I'd be interested
to see how it impacts the examples in previous discussions:
https://issues.apache.org/jira/browse/GROOVY-7428
http://markmail.org/thread/6qrcvnmxuqys45vh
On Thu, Feb 22, 2018 at 6:29 PM, Daniel Sun <re...@hotmail.com> wrote:
> Hi all,
>
> Groovy parses negative numbers as unary expression. For example,
> `-1`
> is parsed as `-``1`, older parser parses negative numbers twice, so does
> the
> Parrot parser for the identical output...
>
> I suggest to parse negative numbers as REAL numbers instead of unary
> expression[1]. It will break the edge case, for example: `-1(a, b, c)` is
> parsed as `-(1.call(a, b, c))`, after refining, `-1(a, b, c)` is parsed as
> `-1.call(a, b, c)`.
>
> Any thoughts? If no PMC votes -1 on this GEP in 72 hours, I will
> work on it.
>
> Cheers,
> Daniel.Sun
>
> [1]
> https://github.com/danielsun1106/groovy-parser/blob/master/src/main/antlr/
> GroovyParser.g4#L796
>
>
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>