mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Move precedence table to syntax page.
This commit is contained in:
@ -1,130 +0,0 @@
|
||||
^title Grammar
|
||||
^category reference
|
||||
|
||||
**TODO: Fill in the rest of the grammar.**
|
||||
|
||||
## Precedence
|
||||
|
||||
When you mix the different [method call][] syntaxes and other [control flow][]
|
||||
operators together, you need to worry about *precedence*—which ones bind
|
||||
more tightly than others—and *associativity*—how a series of the
|
||||
same kind of call is ordered. Wren mostly follows C, except that it fixes [the
|
||||
bitwise operator mistake][mistake]. The full precedence table, from tightest to
|
||||
loosest, is:
|
||||
|
||||
[method call]: method-calls.html
|
||||
[control flow]: control-flow.html
|
||||
[mistake]: http://www.lysator.liu.se/c/dmr-on-or.html
|
||||
|
||||
<table class="precedence">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Prec</th>
|
||||
<th>Operator</th>
|
||||
<th>Description</th>
|
||||
<th>Assoc</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td><code>()</code> <code>[]</code> <code>.</code></td>
|
||||
<td>Grouping, Subscript, Method call</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td><code>-</code> <code>!</code> <code>~</code></td>
|
||||
<td>Negate, Not, Complement</td>
|
||||
<td>Right</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td><code>*</code> <code>/</code> <code>%</code></td>
|
||||
<td>Multiply, Divide, Modulo</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>4</td>
|
||||
<td><code>+</code> <code>-</code></td>
|
||||
<td>Add, Subtract</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>5</td>
|
||||
<td><code>..</code> <code>...</code></td>
|
||||
<td>Inclusive range, Exclusive range</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>6</td>
|
||||
<td><code><<</code> <code>>></code></td>
|
||||
<td>Left shift, Right shift</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>7</td>
|
||||
<td><code><</code> <code><=</code> <code>></code> <code>>=</code></td>
|
||||
<td>Comparison</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>8</td>
|
||||
<td><code>==</code></td>
|
||||
<td>Equals</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>8</td>
|
||||
<td><code>!=</code></td>
|
||||
<td>Not equal</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>9</td>
|
||||
<td><code>&</code></td>
|
||||
<td>Bitwise and</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>10</td>
|
||||
<td><code>^</code></td>
|
||||
<td>Bitwise xor</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>11</td>
|
||||
<td><code>|</code></td>
|
||||
<td>Bitwise or</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>12</td>
|
||||
<td><code>is</code></td>
|
||||
<td>Type test</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>13</td>
|
||||
<td><code>&&</code></td>
|
||||
<td>Logical and</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>14</td>
|
||||
<td><code>||</code></td>
|
||||
<td>Logical or</td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>15</td>
|
||||
<td><code>?:</code></td>
|
||||
<td>Conditional</td>
|
||||
<td>Right</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>16</td>
|
||||
<td><code>=</code></td>
|
||||
<td>Assign</td>
|
||||
<td>Right</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -123,7 +123,7 @@ We also have a slew of infix operators—they have operands on both sides.
|
||||
They are:
|
||||
|
||||
:::wren
|
||||
== != < > <= >= .. ... | & + - * / % is
|
||||
* / % + - .. ... << >> < <= > >= == != & ^ | is
|
||||
|
||||
Like prefix operators, they are all funny ways of writing method calls. The left
|
||||
operand is the receiver, and the right operand gets passed to it. So `a + b` is
|
||||
|
||||
@ -125,5 +125,133 @@ same as doing:
|
||||
return "single expression"
|
||||
}
|
||||
|
||||
|
||||
## Precedence and Associativity
|
||||
|
||||
We'll talk about Wren's different expression forms and what they mean in the
|
||||
next few pages. But if you want to see how they interact with each other
|
||||
grammatically, here's the whole table.
|
||||
|
||||
It shows which expressions have higher *precedence*—which ones bind more
|
||||
tightly than others—and their *associativity*—how a series of the
|
||||
same kind of expression is ordered. Wren mostly follows C, except that it fixes
|
||||
[the bitwise operator mistake][mistake]. The full precedence table, from
|
||||
tightest to loosest, is:
|
||||
|
||||
[mistake]: http://www.lysator.liu.se/c/dmr-on-or.html
|
||||
|
||||
<table class="precedence">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Prec</th>
|
||||
<th>Operator</th>
|
||||
<th>Description</th>
|
||||
<th>Associates</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td><code>()</code> <code>[]</code> <code>.</code></td>
|
||||
<td>Grouping, <a href="method-calls.html">Subscript, Method call</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td><code>-</code> <code>!</code> <code>~</code></td>
|
||||
<td><a href="method-calls.html#operators">Negate, Not, Complement</a></td>
|
||||
<td>Right</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td><code>*</code> <code>/</code> <code>%</code></td>
|
||||
<td><a href="method-calls.html#operators">Multiply, Divide, Modulo</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>4</td>
|
||||
<td><code>+</code> <code>-</code></td>
|
||||
<td><a href="method-calls.html#operators">Add, Subtract</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>5</td>
|
||||
<td><code>..</code> <code>...</code></td>
|
||||
<td><a href="method-calls.html#operators">Inclusive range, Exclusive range</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>6</td>
|
||||
<td><code><<</code> <code>>></code></td>
|
||||
<td><a href="method-calls.html#operators">Left shift, Right shift</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>7</td>
|
||||
<td><code><</code> <code><=</code> <code>></code> <code>>=</code></td>
|
||||
<td><a href="method-calls.html#operators">Comparison</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>8</td>
|
||||
<td><code>==</code></td>
|
||||
<td><a href="method-calls.html#operators">Equals</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>8</td>
|
||||
<td><code>!=</code></td>
|
||||
<td><a href="method-calls.html#operators">Not equal</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>9</td>
|
||||
<td><code>&</code></td>
|
||||
<td><a href="method-calls.html#operators">Bitwise and</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>10</td>
|
||||
<td><code>^</code></td>
|
||||
<td><a href="method-calls.html#operators">Bitwise xor</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>11</td>
|
||||
<td><code>|</code></td>
|
||||
<td><a href="method-calls.html#operators">Bitwise or</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>12</td>
|
||||
<td><code>is</code></td>
|
||||
<td><a href="method-calls.html#operators">Type test</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>13</td>
|
||||
<td><code>&&</code></td>
|
||||
<td><a href="control-flow.html#logical-operators">Logical and</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>14</td>
|
||||
<td><code>||</code></td>
|
||||
<td><a href="control-flow.html#logical-operators">Logical or</a></td>
|
||||
<td>Left</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>15</td>
|
||||
<td><code>?:</code></td>
|
||||
<td><a href="control-flow.html#the-conditional-operator-">Conditional</a></td>
|
||||
<td>Right</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>16</td>
|
||||
<td><code>=</code></td>
|
||||
<td><a href="variables.html#assignment">Assignment</a>, <a href="method-calls.html#setters">Setter</a></td>
|
||||
<td>Right</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a class="right" href="values.html">Values →</a>
|
||||
<a href="getting-started.html">← Getting Started</a>
|
||||
<a href="getting-started.html">← Getting Started</a>
|
||||
|
||||
@ -48,7 +48,6 @@
|
||||
<li><a href="core">Core Library</a></li>
|
||||
<li><a href="embedding-api.html">Embedding API</a></li>
|
||||
<li><a href="performance.html">Performance</a></li>
|
||||
<li><a href="grammar.html">Grammar</a></li>
|
||||
<li><a href="qa.html">Q & A</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
@ -90,7 +89,6 @@
|
||||
<li><a href="core">Core Library</a></li>
|
||||
<li><a href="embedding-api.html">Embedding API</a></li>
|
||||
<li><a href="performance.html">Performance</a></li>
|
||||
<li><a href="grammar.html">Grammar</a></li>
|
||||
<li><a href="qa.html">Q & A</a></li>
|
||||
</ul>
|
||||
</td>
|
||||
|
||||
@ -19,7 +19,7 @@ import markdown
|
||||
MARKDOWN_HEADER = re.compile(r'#+ ')
|
||||
|
||||
# Clean up a header to be a valid URL.
|
||||
FORMAT_ANCHOR = re.compile(r'\.|\?|!|:|/|\*')
|
||||
FORMAT_ANCHOR = re.compile(r'\?|!|:|/|\*|`')
|
||||
|
||||
def load_template():
|
||||
global template
|
||||
|
||||
Reference in New Issue
Block a user