From ff1453f2e2d086a984905bbb85a89712ea3c78bb Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 30 Oct 2020 16:08:14 -0400 Subject: Generate expression displays from compiled bytecode, not an ad-hoc parser --- docs/tutorial/expression.html | 150 +++++++++++++++++++++++++----------------- 1 file changed, 91 insertions(+), 59 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/expression.html b/docs/tutorial/expression.html index cea81292..22da2272 100644 --- a/docs/tutorial/expression.html +++ b/docs/tutorial/expression.html @@ -119,37 +119,37 @@ (4÷3) × π × 23 - - - - - - - - - + + + + + + + + + - 4 - ÷ - 3 - × - π - × - 2 - 3 + + 2 + × + π + × + 3 + ÷ + 4 - 4 - ÷ - 3 - × - π - × - 2 - 3 + + 2 + × + π + × + 3 + ÷ + 4 @@ -172,46 +172,46 @@ (3 + 2×√2) - 1+√2 - - - - - - - - - - - - + + + + + + + + + + + + - - 3 - + - 2 - × - - 2 - - - 1 - + - 2 + + + + 1 + - + 2 + + × + 2 + + + 3 + - - 3 - + - 2 - × - - 2 - - - 1 - + - 2 + + + + 1 + - + 2 + + × + 2 + + + 3 + @@ -351,6 +351,38 @@ + 3 4 + + + + 3 ט+ 4 + + + + + + + + + + 4 + + + + ˜ + × + 3 + + + 4 + + + + ˜ + × + 3 + + + + +

This ordering is more consistent with the fact that the operand of a 1-modifier goes to its left. If we tried going from right to left we'd end up with ×(˜+), which uses ˜ as an operand to . But a modifier can't be used as an operand. To make it work we'd essentially have to give 1-modifiers a higher precedence than 2-modifiers.

In fact, the rules for modifiers are exactly the same as those for functions, but reversed. So why is there a distinction between 1- and 2-modifiers, when for functions we can look to the left to see whether there is a left argument? The reason is that it's natural to follow a 1-modifier by a subject or function that isn't supposed to be its operand. Using an example from the last section, +˜ 3 has a subject to the right of the 1-modifier ˜. Even worse, +˜ ÷ 3 looks the same syntactically as + ÷ 3, but it's two functions +˜ and ÷ applied to 3 while the version with Atop is a single function +÷ applied to 3. So the two-layer system of functions and modifiers forces modifiers to have a fixed number of operands even every function (including those derived by applying modifiers) can be called with one or two arguments.

Remember that 1-modifiers are all superscripts? The characters for 2-modifiers use a different rule: each contains an unbroken circle (that is, lines might touch it but not go through it). The 2-modifiers in BQN are the combinators ∘○⊸⟜⌾, the sort-of-combinators ⊘◶⍟, and the not-at-all-combinators ⎉⚇⎊. And the functions that make that unbroken circle rule necessary are written ⌽⍉. Since every primitive is a function, 1-modifier, or 2-modifier, you can always tell what type (and role) it has: a superscript is a 1-modifier, an unbroken circle makes it a 2-modifier, and otherwise it's a function.

-- cgit v1.2.3