From d2b372b66c473d4dbd51df6870ce5cb8ce9706b5 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 25 Aug 2020 18:54:01 -0400 Subject: =?UTF-8?q?Highlight=20=5F=F0=9D=95=A3=20and=20=5F=F0=9D=95=A3=5F?= =?UTF-8?q?=20correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/spec/evaluate.html | 2 +- docs/spec/grammar.html | 4 ++-- docs/spec/token.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/spec') diff --git a/docs/spec/evaluate.html b/docs/spec/evaluate.html index 0f4e07c2..1df68613 100644 --- a/docs/spec/evaluate.html +++ b/docs/spec/evaluate.html @@ -12,7 +12,7 @@

A PROGRAM or BODY is a list of STMTs (for BODY, the last must be an EXPR, a particular kind of STMT), which are evaluated in program order. The statement nothing does nothing when evaluated, while EXPR evaluates some APL code and possibly assigns the results, as described below.

A block consists of several BODY terms, some of which may have an accompanying header describing accepted inputs and how they are processed. An immediate block brImm can only have one BODY, and is evaluated by evaluating the code in it. Other types of blocks do not evaluate any BODY immediately, but instead return a function or modifier that obtains its result by evaluating a particular BODY. The BODY is identified and evaluated once the block has received enough inputs (operands or arguments), which for modifiers can take one or two calls: if two calls are required, then on the first call the operands are simply stored and no code is evaluated yet. Two calls are required if there is more than one BODY term, if the BODY contains the special names ๐•จ๐•ฉ๐•ค๐•Ž๐•๐•Š, or if its header specifies arguments (the header-body combination is a _mCase or _cCase_). Otherwise only one is required.

To evaluate a block when enough inputs have been received, first the correct case must be identified. To do this, first each special case (FCase, _mCase, or _cCase_) is checked in order to see if its arguments are strucurally compatible with the given arguments. That is, is headW is a subject, there must be a left argument matching that structure, and if headX is a subject, the right argument must match that structure. This means that ๐•จ not only matches any left argument but also no argument. The test for compatibility is the same as for multiple assignment described below, except that the header may contain constants, which must match the corresponding part of the given argument.If no special case matches, then an appropriate general case (FMain, _mMain, or _cMain_) is used: if there are two, the first is used with no left argument and the second with a left argument; if there are one, it is always used, and if there are none, an error results.

-

The only remaining step before evaluating the BODY is to bind the inputs and other names. Special names are always bound when applicable: ๐•จ๐•ฉ๐•ค if arguments are used, ๐•จ if there is a left argument, ๐•—๐•˜ if operands are used, and _๐•ฃ and _๐•ฃ_ for modifiers and combinators, respectively. Any names in the header are also bound, allowing multiple assignment for arguments.

+

The only remaining step before evaluating the BODY is to bind the inputs and other names. Special names are always bound when applicable: ๐•จ๐•ฉ๐•ค if arguments are used, ๐•จ if there is a left argument, ๐•—๐•˜ if operands are used, and _๐•ฃ and _๐•ฃ_ for modifiers and combinators, respectively. Any names in the header are also bound, allowing multiple assignment for arguments.

If there is no left argument, but the BODY contains ๐•จ at the top level, then it is conceptually re-parsed with ๐•จ replaced by ยท to give a monadic version before application. As the only effect when this re-parsed form is valid is to change some instances of arg to nothing, this can be achieved efficiently by annotating parts of the AST that depend on ๐•จ as conditionally-nothing. However, it also causes an error if ๐•จ is used as an operand or list element, where nothing is not allowed by the grammar.

Assignment

An assignment is one of the four rules containing ASGN. It is evaluated by first evaluating the right-hand-side subExpr, FuncExpr, _m1Expr, or _m2Exp_ expression, and then storing the result in the left-hand-side identifier or identifiers. The result of the assignment expression is the result of its right-hand side. Except for subjects, only a lone identifier is allowed on the left-hand side and storage sets it equal to the result. For subjects, multiple assignment with a list left-hand side is also allowed. Multiple assignment is performed recursively by assigning right-hand-side values to the left-hand-side targets, with single-identifier (s) assignment as the base case. When matching the right-hand side to a list left-hand side, the left hand side is treated as a list of lhs targets. The evaluated right-hand side must be a list (rank-1 array) of the same length, and is matched to these targets element-wise.

diff --git a/docs/spec/grammar.html b/docs/spec/grammar.html index 82964547..77678a95 100644 --- a/docs/spec/grammar.html +++ b/docs/spec/grammar.html @@ -120,7 +120,7 @@ _brMod1 ๐•—๐•ฃ ๐”ฝ -_๐•ฃ +_๐•ฃ @@ -129,7 +129,7 @@ ๐•˜ ๐”พ None -_๐•ฃ_ +_๐•ฃ_ diff --git a/docs/spec/token.html b/docs/spec/token.html index a4b708cd..3d04a407 100644 --- a/docs/spec/token.html +++ b/docs/spec/token.html @@ -9,7 +9,7 @@

BQN source code should be considered as a series of unicode code points, which we refer to as "characters". The separator between lines in a file is considered to be a single character, newline, even though some operating systems such as Windows typically represent it with a two-character CRLF sequence. Implementers should note that not all languages treat unicode code points as atomic, as exposing the UTF-8 or UTF-16 representation instead is common. For a language such as JavaScript that uses UTF-16, the double-struck characters ๐•จ๐•Ž๐•ฉ๐•๐•—๐”ฝ๐•˜๐”พ are represented as two 16-bit surrogate characters, but BQN treats them as a single unit.

A BQN character literal consists of a single character between single quotes, such as 'a', and a string literal consists of any number of characters between double quotes, such as "" or "abc". Character and string literals take precedence with comments over other tokenization rules, so that # between quotes does not start a comment and whitespace between quotes is not removed, but a quote within a comment does not start a character literal. Almost any character can be included directly in a character or string literal without escaping. The only exception is the double quote character ", which must be written twice to include it in a string, as otherwise it would end the string instead. Character literals require no escaping at all, as the length is fixed. In particular, literals for the double and single quote characters are written ''' and '"', while length-1 strings containing these characters are "'" and """".

A comment consists of the hash character # and any following text until (not including) the next newline character. The initial # must not be part of a string literal started earlier. Comments are ignored entirely and do not form tokens.

-

Identifiers and numeric literals share the same token formation rule. These tokens are formed from the numeric characters ยฏโˆžฯ€.0123456789 and alphabetic characters _abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ and the oddball ๐•ฃ. Any sequence of these characters adjacent to each other forms a single token, which is a numeric literal if it begins with a numeric character and an identifier if it begins with an alphabetic character. Numeric literals are also subject to numeric literal rules, which specify which numeric literals are valid and which numbers they represent. If the token contains ๐•ฃ it must be either ๐•ฃ, _๐•ฃ, or _๐•ฃ_ and is considered a special name (see below). As the value taken by this identifier can only be a modifier, the uppercase character โ„ is not allowed.

+

Identifiers and numeric literals share the same token formation rule. These tokens are formed from the numeric characters ยฏโˆžฯ€.0123456789 and alphabetic characters _abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ and the oddball ๐•ฃ. Any sequence of these characters adjacent to each other forms a single token, which is a numeric literal if it begins with a numeric character and an identifier if it begins with an alphabetic character. Numeric literals are also subject to numeric literal rules, which specify which numeric literals are valid and which numbers they represent. If the token contains ๐•ฃ it must be either ๐•ฃ, _๐•ฃ, or _๐•ฃ_ and is considered a special name (see below). As the value taken by this identifier can only be a modifier, the uppercase character โ„ is not allowed.

Following this step, the whitespace characters space and tab are ignored, and do not form tokens. Only these whitespace characters, and the newline character, which does form a token, are allowed.

Otherwise, a single character forms a token. Only the specified set of characters can be used; others result in an error. The classes of characters are given below.

-- cgit v1.2.3