aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2022-08-31 17:00:31 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2022-08-31 17:00:31 -0400
commit99f3205c897c82b378b9b022ac295085005cef5e (patch)
treef2f85c012addd8b28c875e8a740cde33db992e91 /docs
parent76bc9fe08d41b08b3c08edf01f46b38abc1f126e (diff)
Fix grammar for arg not allowing assignment within expressions
Diffstat (limited to 'docs')
-rw-r--r--docs/spec/grammar.html12
1 files changed, 6 insertions, 6 deletions
diff --git a/docs/spec/grammar.html b/docs/spec/grammar.html
index 8dde8b83..a161b928 100644
--- a/docs/spec/grammar.html
+++ b/docs/spec/grammar.html
@@ -47,7 +47,7 @@
</pre>
<p>Subject expressions consist mainly of function application. We also define nothing-statements, which have very similar syntax to subject expressions but do not permit assignment. They can be used as an <code><span class='Function'>STMT</span></code> or in place of a left argument.</p>
<pre><span class='Value'>arg</span> <span class='Function'>=</span> <span class='Value'>subject</span>
- <span class='Function'>|</span> <span class='Paren'>(</span> <span class='Value'>subject</span> <span class='Function'>|</span> <span class='Value'>nothing</span> <span class='Paren'>)</span><span class='Head'>?</span> <span class='Function'>Derv</span> <span class='Value'>arg</span>
+ <span class='Function'>|</span> <span class='Paren'>(</span> <span class='Value'>subject</span> <span class='Function'>|</span> <span class='Value'>nothing</span> <span class='Paren'>)</span><span class='Head'>?</span> <span class='Function'>Derv</span> <span class='Value'>subExpr</span>
<span class='Value'>nothing</span> <span class='Function'>=</span> <span class='String'>&quot;ยท&quot;</span>
<span class='Function'>|</span> <span class='Paren'>(</span> <span class='Value'>subject</span> <span class='Function'>|</span> <span class='Value'>nothing</span> <span class='Paren'>)</span><span class='Head'>?</span> <span class='Function'>Derv</span> <span class='Value'>nothing</span>
<span class='Value'>subExpr</span> <span class='Function'>=</span> <span class='Value'>arg</span>
@@ -148,10 +148,10 @@
</tr>
</tbody>
</table>
-<p>The rules for special names can be expressed in BNF by making many copies of all expression rules above. For each &quot;level&quot;, or row in the table, a new version of every rule should be made that allows that level but not higher ones, and another version should be made that requires exactly that level. The values themselves should be included in <code><span class='Value'>s</span></code>, <code><span class='Function'>F</span></code>, <code><span class='Modifier'>_m</span></code>, and <code><span class='Modifier2'>_c_</span></code> for these copies. Then the &quot;allowed&quot; rules are made simply by replacing the terms they contain (excluding <code><span class='Value'>blSub</span></code> and so on) with the same &quot;allowed&quot; versions, and &quot;required&quot; rules are constructed using both &quot;allowed&quot; and &quot;required&quot; rules. For every part of a production rule, an alternative should be created that requires the relevant name in that part while allowing it in the others. For example, <code><span class='Paren'>(</span> <span class='Value'>subject</span> <span class='Function'>|</span> <span class='Value'>nothing</span> <span class='Paren'>)</span><span class='Head'>?</span> <span class='Function'>Derv</span> <span class='Value'>arg</span></code> would be transformed to</p>
-<pre><span class='Value'>arg_req1</span> <span class='Function'>=</span> <span class='Value'>subExpr_req1</span>
- <span class='Function'>|</span> <span class='Paren'>(</span> <span class='Value'>subject_req1</span> <span class='Function'>|</span> <span class='Value'>nothing_req1</span> <span class='Paren'>)</span> <span class='Function'>Derv_allow1</span> <span class='Value'>arg_allow1</span>
- <span class='Function'>|</span> <span class='Paren'>(</span> <span class='Value'>subject_allow1</span> <span class='Function'>|</span> <span class='Value'>nothing_allow1</span> <span class='Paren'>)</span><span class='Head'>?</span> <span class='Function'>Derv_req1</span> <span class='Value'>arg_allow1</span>
- <span class='Function'>|</span> <span class='Paren'>(</span> <span class='Value'>subject_allow1</span> <span class='Function'>|</span> <span class='Value'>nothing_allow1</span> <span class='Paren'>)</span><span class='Head'>?</span> <span class='Function'>Derv_allow1</span> <span class='Value'>arg_req1</span>
+<p>The rules for special names can be expressed in BNF by making many copies of all expression rules above. For each &quot;level&quot;, or row in the table, a new version of every rule should be made that allows that level but not higher ones, and another version should be made that requires exactly that level. The values themselves should be included in <code><span class='Value'>s</span></code>, <code><span class='Function'>F</span></code>, <code><span class='Modifier'>_m</span></code>, and <code><span class='Modifier2'>_c_</span></code> for these copies. Then the &quot;allowed&quot; rules are made simply by replacing the terms they contain (excluding <code><span class='Value'>blSub</span></code> and so on) with the same &quot;allowed&quot; versions, and &quot;required&quot; rules are constructed using both &quot;allowed&quot; and &quot;required&quot; rules. For every part of a production rule, an alternative should be created that requires the relevant name in that part while allowing it in the others. For example, the definition of <code><span class='Value'>arg</span></code> as <code><span class='Value'>subject</span> <span class='Function'>|</span> <span class='Paren'>(</span> <span class='Value'>subject</span> <span class='Function'>|</span> <span class='Value'>nothing</span> <span class='Paren'>)</span><span class='Head'>?</span> <span class='Function'>Derv</span> <span class='Value'>subExpr</span></code> would be transformed to</p>
+<pre><span class='Value'>arg_req1</span> <span class='Function'>=</span> <span class='Value'>subject_req1</span>
+ <span class='Function'>|</span> <span class='Paren'>(</span> <span class='Value'>subject_req1</span> <span class='Function'>|</span> <span class='Value'>nothing_req1</span> <span class='Paren'>)</span> <span class='Function'>Derv_allow1</span> <span class='Value'>subExpr_allow1</span>
+ <span class='Function'>|</span> <span class='Paren'>(</span> <span class='Value'>subject_allow1</span> <span class='Function'>|</span> <span class='Value'>nothing_allow1</span> <span class='Paren'>)</span><span class='Head'>?</span> <span class='Function'>Derv_req1</span> <span class='Value'>subExpr_allow1</span>
+ <span class='Function'>|</span> <span class='Paren'>(</span> <span class='Value'>subject_allow1</span> <span class='Function'>|</span> <span class='Value'>nothing_allow1</span> <span class='Paren'>)</span><span class='Head'>?</span> <span class='Function'>Derv_allow1</span> <span class='Value'>subExpr_req1</span>
</pre>
<p>Quite tedious. The explosion of rules is partly due to the fact that the block-typing rule falls into a weaker class of grammars than the other rules. Most of BQN is <a href="https://en.wikipedia.org/wiki/Deterministic_context-free_grammar">deterministic context-free</a> but block-typing is not, only context-free. Fortunately block typing does not introduce the parsing difficulties that can be present in a general context-free grammar, and it can easily be performed in linear time: after <a href="token.html">scanning</a> but before parsing, move through the source code maintaining a stack of the current top-level set of braces. Whenever a colon or special name is encountered, annotate that set of braces to indicate that it is present. When a closing brace is encountered and the top brace is popped off the stack, the type is needed if there was no colon, and can be found based on which names were present. One way to present this information to the parser is to replace the brace tokens with new tokens that indicate the type.</p>