Commit abb818bc authored by Matthew Dempsky's avatar Matthew Dempsky Committed by Robert Griesemer

spec: fix binary expression grammar rule

The spec explains later in the "Operator precedence" section that *
has a higher precedence than +, but the current production rule
requires that "1 + 2 * 3" be parsed as "(1 + 2) * 3", instead of the
intended "1 + (2 * 3)".

The new production rule better matches cmd/internal/gc/go.y's grammar:

    expr:
            uexpr
    |       expr LOROR expr
    |       expr LANDAND expr
    |       ...

Fixes #10151.

Change-Id: I13c9635d6ddf1263cafe7cc63e68f3e5779e24ba
Reviewed-on: https://go-review.googlesource.com/9163Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent 99475dfb
<!--{ <!--{
"Title": "The Go Programming Language Specification", "Title": "The Go Programming Language Specification",
"Subtitle": "Version of March 20, 2015", "Subtitle": "Version of April 22, 2015",
"Path": "/ref/spec" "Path": "/ref/spec"
}--> }-->
...@@ -3305,7 +3305,7 @@ Operators combine operands into expressions. ...@@ -3305,7 +3305,7 @@ Operators combine operands into expressions.
</p> </p>
<pre class="ebnf"> <pre class="ebnf">
Expression = UnaryExpr | Expression binary_op UnaryExpr . Expression = UnaryExpr | Expression binary_op Expression .
UnaryExpr = PrimaryExpr | unary_op UnaryExpr . UnaryExpr = PrimaryExpr | unary_op UnaryExpr .
binary_op = "||" | "&amp;&amp;" | rel_op | add_op | mul_op . binary_op = "||" | "&amp;&amp;" | rel_op | add_op | mul_op .
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment