Skip to content

Commit

Permalink
spec: fix binary expression grammar rule
Browse files Browse the repository at this point in the history
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/9163
Reviewed-by: Robert Griesemer <[email protected]>
  • Loading branch information
mdempsky authored and griesemer committed May 13, 2015
1 parent 99475df commit abb818b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions doc/go_spec.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of March 20, 2015",
"Subtitle": "Version of April 22, 2015",
"Path": "/ref/spec"
}-->

Expand Down Expand Up @@ -3305,7 +3305,7 @@ <h3 id="Operators">Operators</h3>
</p>

<pre class="ebnf">
Expression = UnaryExpr | Expression binary_op UnaryExpr .
Expression = UnaryExpr | Expression binary_op Expression .
UnaryExpr = PrimaryExpr | unary_op UnaryExpr .

binary_op = "||" | "&amp;&amp;" | rel_op | add_op | mul_op .
Expand Down

0 comments on commit abb818b

Please sign in to comment.