diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-07-07 21:23:06 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-07-07 21:23:26 -0400 |
| commit | 77c6ab5c8435c9fcde7c4742ee0e5eb06341eeff (patch) | |
| tree | 48ff9cf3b9066aea0e38111a9dc5ce92f87ebe96 /docs | |
| parent | f14c4af888dc678eefe1de323b8fe41f7387e82b (diff) | |
Separate token and constant documentation into its own page
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/doc/arithmetic.html | 2 | ||||
| -rw-r--r-- | docs/doc/arrayrepr.html | 4 | ||||
| -rw-r--r-- | docs/doc/expression.html | 2 | ||||
| -rw-r--r-- | docs/doc/glossary.html | 6 | ||||
| -rw-r--r-- | docs/doc/index.html | 3 | ||||
| -rw-r--r-- | docs/doc/syntax.html | 47 | ||||
| -rw-r--r-- | docs/doc/token.html | 41 | ||||
| -rw-r--r-- | docs/help/character.html | 2 | ||||
| -rw-r--r-- | docs/help/comment.html | 2 | ||||
| -rw-r--r-- | docs/help/infinity.html | 2 | ||||
| -rw-r--r-- | docs/help/minus.html | 2 | ||||
| -rw-r--r-- | docs/help/nullcharacter.html | 2 | ||||
| -rw-r--r-- | docs/help/pi.html | 2 | ||||
| -rw-r--r-- | docs/help/separator.html | 2 | ||||
| -rw-r--r-- | docs/help/string.html | 2 |
15 files changed, 77 insertions, 44 deletions
diff --git a/docs/doc/arithmetic.html b/docs/doc/arithmetic.html index 9e511044..918bd9c5 100644 --- a/docs/doc/arithmetic.html +++ b/docs/doc/arithmetic.html @@ -96,7 +96,7 @@ <span class='Function'>√</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>4</span> ⟨ 0 1 1.414213562373095 2 ⟩ </pre> -<p>Take note of the difference between the function <code><span class='Function'>-</span></code>, and the "high minus" character <code><span class='Number'>¯</span></code>, which is a part of <a href="syntax.html#constants">numeric notation</a>. Also shown is the number <code><span class='Number'>∞</span></code>, which BQN supports along with <code><span class='Number'>¯∞</span></code> (but depending on implementation BQN may or may not keep track of <code><span class='Number'>¯0</span></code>. Integer optimization loses the distinction so it's best not to rely on it).</p> +<p>Take note of the difference between the function <code><span class='Function'>-</span></code>, and the "high minus" character <code><span class='Number'>¯</span></code>, which is a part of <a href="token.html#numbers">numeric notation</a>. Also shown is the number <code><span class='Number'>∞</span></code>, which BQN supports along with <code><span class='Number'>¯∞</span></code> (but depending on implementation BQN may or may not keep track of <code><span class='Number'>¯0</span></code>. Integer optimization loses the distinction so it's best not to rely on it).</p> <p>The logarithm is written with <a href="undo.html">Undo</a>: <code><span class='Function'>⋆</span><span class='Modifier'>⁼</span></code>. As with Power, the default base is <em>e</em>, giving a natural logarithm.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4ouG4oG8IDEwCgoyIOKLhuKBvCAxMDI0">↗️</a><pre> <span class='Function'>⋆</span><span class='Modifier'>⁼</span> <span class='Number'>10</span> 2.302585092994046 diff --git a/docs/doc/arrayrepr.html b/docs/doc/arrayrepr.html index 159bb8f7..5218009e 100644 --- a/docs/doc/arrayrepr.html +++ b/docs/doc/arrayrepr.html @@ -162,7 +162,7 @@ <p><em>The tutorial section <a href="../tutorial/list.html#list-notation">here</a> also covers this topic.</em></p> <p>Now it's time to discuss ways to write arrays in a BQN program. There are three kinds literal notation for lists: strings, list notation, and stranding. Strings indicate character lists (with space for the <a href="fill.html">fill</a>) and the other two can combine any sequence of elements. Additionally, there's a square bracket notation that can form higher-rank arrays.</p> <h3 id="strings"><a class="header" href="#strings">Strings</a></h3> -<p>A <strong>string</strong> consists of a sequence of characters surrounded by double quotes <code><span class='String'>""</span></code>. The only rule for the characters inside is that any double quote must be escaped by repeating it twice; otherwise the string ends at that point.</p> +<p>A <a href="token.html#characters-and-strings"><strong>string</strong> literal</a> consists of a sequence of characters surrounded by double quotes <code><span class='String'>""</span></code>. The only rule for the characters inside is that any double quote must be escaped by repeating it twice; otherwise the string ends at that point.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=Ii0nw5clIiIqIgoKIi0nw5clIioiICAjIEVzY2FwaW5nIGZhaWx1cmU=">↗️</a><pre> <span class='String'>"-'×%""*"</span> "-'×%""*" @@ -171,7 +171,7 @@ </pre> <p>Even special characters like a newline can appear in a string literal, so that string literals are automatically multi-line.</p> <h3 id="brackets"><a class="header" href="#brackets">Brackets</a></h3> -<p><strong>List notation</strong> uses angle brackets <code><span class='Bracket'>⟨⟩</span></code>. The contents are structurally identical to those of a <a href="block.html">block</a>, that is, a list of expressions <a href="syntax.html#separators">separated</a> by <code><span class='Separator'>,</span></code> or <code><span class='Separator'>⋄</span></code> or newlines. Unlike a block, a list doesn't need to have any expressions: <code><span class='Bracket'>⟨⟩</span></code> or <code><span class='Bracket'>⟨</span><span class='Separator'>⋄</span><span class='Bracket'>⟩</span></code> or <code><span class='Bracket'>⟨</span><span class='Separator'>,,⋄,</span><span class='Bracket'>⟩</span></code> will create an empty list. Other differences are that a list doesn't introduce a new <a href="lexical.html">scope</a> and all of the expressions have to result in a value, not <a href="expression.html#nothing">Nothing</a> (<code><span class='Nothing'>·</span></code>).</p> +<p><strong>List notation</strong> uses angle brackets <code><span class='Bracket'>⟨⟩</span></code>. The contents are structurally identical to those of a <a href="block.html">block</a>, that is, a list of expressions <a href="token.html#separators">separated</a> by <code><span class='Separator'>,</span></code> or <code><span class='Separator'>⋄</span></code> or newlines. Unlike a block, a list doesn't need to have any expressions: <code><span class='Bracket'>⟨⟩</span></code> or <code><span class='Bracket'>⟨</span><span class='Separator'>⋄</span><span class='Bracket'>⟩</span></code> or <code><span class='Bracket'>⟨</span><span class='Separator'>,,⋄,</span><span class='Bracket'>⟩</span></code> will create an empty list. Other differences are that a list doesn't introduce a new <a href="lexical.html">scope</a> and all of the expressions have to result in a value, not <a href="expression.html#nothing">Nothing</a> (<code><span class='Nothing'>·</span></code>).</p> <p>Entries in a list are evaluated in source order, and the value will be the list of those results. The list has a subject <a href="expression.html#syntactic-role">role</a>, even if it contains expressions with other roles. Any value can be an element.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oQCwg4o2Jy5gsIOKJjSJhYmMi4p+p">↗️</a><pre> <span class='Bracket'>⟨</span><span class='String'>@</span><span class='Separator'>,</span> <span class='Function'>⍉</span><span class='Modifier'>˘</span><span class='Separator'>,</span> <span class='Function'>≍</span><span class='String'>"abc"</span><span class='Bracket'>⟩</span> ┌─ diff --git a/docs/doc/expression.html b/docs/doc/expression.html index 81f2a048..b8f9254c 100644 --- a/docs/doc/expression.html +++ b/docs/doc/expression.html @@ -5,7 +5,7 @@ </head> <div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">doc</a></div> <h1 id="expression-syntax"><a class="header" href="#expression-syntax">Expression syntax</a></h1> -<p>BQN expressions are the part of <a href="syntax.html">syntax</a> that describes computations to perform. Programs are mainly made up of expressions with a little organizing material like <a href="block.html">blocks</a> and <a href="namespace.html">namespaces</a> around them. This page explains how functions, modifiers, and assignment combine with their inputs. It doesn't describe <a href="syntax.html#constants">constant</a> and <a href="arrayrepr.html#array-literals">array</a> literals, which each form a single subject for grammatical purposes.</p> +<p>BQN expressions are the part of <a href="syntax.html">syntax</a> that describes computations to perform. Programs are mainly made up of expressions with a little organizing material like <a href="block.html">blocks</a> and <a href="namespace.html">namespaces</a> around them. This page explains how functions, modifiers, and assignment combine with their inputs. It doesn't describe <a href="token.html">constant</a> and <a href="arrayrepr.html#array-literals">array</a> literals, which each form a single subject for grammatical purposes.</p> <p>The <a href="../tutorial/expression.html">first tutorial</a> also covers how to build and read BQN expressions.</p> <h2 id="overview"><a class="header" href="#overview">Overview</a></h2> <p>BQN expressions consist of subjects, functions, and modifiers arranged in sequence, with parentheses to group parts into subexpressions. Assignment arrows <code><span class='Gets'>←</span></code> and <code><span class='Gets'>↩</span></code> can also be present and mostly act like functions. <a href="ops.html#functions">Functions</a> can be applied to subjects or grouped into <a href="train.html">trains</a>, while <a href="ops.html#modifiers">modifiers</a> can be applied to subjects or functions. The most important kinds of application are:</p> diff --git a/docs/doc/glossary.html b/docs/doc/glossary.html index 3588a8d8..daf3ec43 100644 --- a/docs/doc/glossary.html +++ b/docs/doc/glossary.html @@ -99,10 +99,10 @@ <li><a href="primitive.html"><strong>Primitive</strong></a>: One of several fixed operations defined by the language, denoted by a single-character token.</li> <li><strong>Word</strong>: A sequence of alphabetic or numeric characters.</li> <li><strong>Name</strong>: A word that starts with an alphabetic character. Names are compared case-insensitively and ignoring underscores <code><span class='Modifier2'>_</span></code>.</li> -<li><a href="syntax.html#constants"><strong>Numeric literal</strong></a>: A word that starts with a numeric character, indicating a number.</li> +<li><a href="token.html#numbers"><strong>Numeric literal</strong></a>: A word that starts with a numeric character, indicating a number.</li> <li><a href="arrayrepr.html#strings"><strong>String literal</strong></a>: A literal written with double quotes <code><span class='String'>""</span></code>, indicating a string.</li> -<li><a href="syntax.html#constants"><strong>Character literal</strong></a>: A literal written with single quotes <code><span class='String'>''</span></code>, indicating a string.</li> -<li><a href="syntax.html#constants"><strong>Null literal</strong></a>: The literal <code><span class='String'>@</span></code>, indicating the null character (code point 0).</li> +<li><a href="token.html#characters-and-strings"><strong>Character literal</strong></a>: A literal written with single quotes <code><span class='String'>''</span></code>, indicating a string.</li> +<li><a href="token.html#characters-and-strings"><strong>Null literal</strong></a>: The literal <code><span class='String'>@</span></code>, indicating the null character (code point 0).</li> </ul> <h2 id="grammar"><a class="header" href="#grammar">Grammar</a></h2> <ul> diff --git a/docs/doc/index.html b/docs/doc/index.html index deded4be..4edd0d0e 100644 --- a/docs/doc/index.html +++ b/docs/doc/index.html @@ -24,6 +24,9 @@ </ul> <p>Concepts:</p> <ul> +<li><a href="token.html">Tokens and constants</a> + +</li> <li><a href="expression.html">Expression syntax</a> <ul> <li><a href="context.html">Context-free grammar</a></li> diff --git a/docs/doc/syntax.html b/docs/doc/syntax.html index 94bace3c..ef6c1804 100644 --- a/docs/doc/syntax.html +++ b/docs/doc/syntax.html @@ -56,7 +56,7 @@ </tr> <tr> <td></td> -<td><a href="#separators">Separator</a></td> +<td><a href="token.html#separators">Separator</a></td> <td></td> <td><code><span class='Separator'>⋄,</span></code> and newline</td> <td><code><span class='Head'>?</span></code></td> @@ -77,7 +77,7 @@ </tr> </tbody> </table> -<p>While all of BQN's grammar fits into this table somehow, it's not really the whole story because subexpressions including parentheses and blocks might behave like functions or modifiers.</p> +<p>While all of BQN's grammar fits into this table somehow, it's not really the whole story because subexpressions including parentheses and blocks might behave like functions or modifiers. See <a href="#expressions">expressions</a> and <a href="#blocks">blocks</a>.</p> <h2 id="special-glyphs"><a class="header" href="#special-glyphs">Special glyphs</a></h2> <p>The following glyphs are used for BQN syntax. <a href="primitive.html">Primitives</a> (built-in functions and modifiers) are not listed in this table, and have their own page. Digits, characters, and the underscore <code><span class='Modifier2'>_</span></code> are used for numbers and variable names.</p> <table> @@ -90,19 +90,19 @@ <tbody> <tr> <td><code><span class='Comment'>#</span></code></td> -<td><a href="#comments">Comment</a></td> +<td><a href="token.html#comments">Comment</a></td> </tr> <tr> <td><code><span class='String'>'"</span></code></td> -<td><a href="#constants">Character or string literal</a></td> +<td><a href="token.html#characters-and-strings">Character or string literal</a></td> </tr> <tr> <td><code><span class='String'>@</span></code></td> -<td><a href="#constants">Null character</a></td> +<td><a href="token.html#characters-and-strings">Null character</a></td> </tr> <tr> <td><code><span class='Number'>¯∞π</span></code></td> -<td><a href="#constants">Used in numeric literals</a></td> +<td><a href="token.html#numbers">Used in numeric literals</a></td> </tr> <tr> <td><code><span class='Nothing'>·</span></code></td> @@ -130,7 +130,7 @@ </tr> <tr> <td><code><span class='Separator'>⋄,</span></code> or newline</td> -<td>Statement or element <a href="#separators">separator</a></td> +<td>Statement or element <a href="token.html#separators">separator</a></td> </tr> <tr> <td><code><span class='Bracket'>⟨⟩</span></code></td> @@ -186,25 +186,16 @@ </tr> </tbody> </table> -<h2 id="comments"><a class="header" href="#comments">Comments</a></h2> -<p>A comment starts with a <code><span class='Comment'>#</span></code> that isn't part of a character or string literal, and continues to the end of the line.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=JyMnIC0gMSAgI1RoaXMgaXMgdGhlIGNvbW1lbnQ=">↗️</a><pre> <span class='String'>'#'</span> <span class='Function'>-</span> <span class='Number'>1</span> <span class='Comment'>#This is the comment -</span>'"' -</pre> -<h2 id="constants"><a class="header" href="#constants">Constants</a></h2> -<p>BQN has single-token notation for numbers, strings, and characters.</p> -<p><a href="types.html#numbers">Numbers</a> are written as decimals, allowing <code><span class='Number'>¯</span></code> for the negative sign (because <code><span class='Function'>-</span></code> is a function) and <code><span class='Value'>e</span></code> or <code><span class='Function'>E</span></code> for scientific notation. They must have digits before and after the decimal point (so, <code><span class='Number'>0.5</span></code> instead of <code><span class='Number'>.5</span></code>), and any exponent must be an integer. Two special numbers <code><span class='Number'>∞</span></code> and <code><span class='Number'>π</span></code> are supported, possibly with a minus sign. If complex numbers are supported (no implementation to date has them), then they can be written with the components separated by <code><span class='Value'>i</span></code> or <code><span class='Function'>I</span></code>.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oIMKvz4Ag4ouEIDAuNSDii4QgNWXCrzEg4ouEIDEuNUUzIOKLhCDiiJ4g4p+pICAgIyBBIGxpc3Qgb2YgbnVtYmVycw==">↗️</a><pre> <span class='Bracket'>⟨</span> <span class='Number'>¯π</span> <span class='Separator'>⋄</span> <span class='Number'>0.5</span> <span class='Separator'>⋄</span> <span class='Number'>5e¯1</span> <span class='Separator'>⋄</span> <span class='Number'>1.5E3</span> <span class='Separator'>⋄</span> <span class='Number'>∞</span> <span class='Bracket'>⟩</span> <span class='Comment'># A list of numbers -</span>⟨ ¯3.141592653589793 0.5 0.5 1500 ∞ ⟩ -</pre> -<p>Strings—lists of characters—are written with double quotes <code><span class='String'>""</span></code>, and <a href="types.html#characters">characters</a> with single quotes <code><span class='String'>''</span></code> with a single character in between. Only one character ever needs to be escaped: a double quote in a string is written twice. So <code><span class='String'>""""</span></code> is a one-character string of <code><span class='String'>"</span></code>, and if two string literals are next to each other, they have to be separated by a space. Character literals don't have even one escape, as the length is already known. Other than the double quote, character and string literals can contain anything: newlines, null characters, or any other Unicode.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omgwqgg4p+oICJzdHIiIOKLhCAicyd0IiJyIiDii4QgJ2MnIOKLhCAnJycg4ouEICciJyDin6kgICAjICIiIGlzIGFuIGVzY2FwZQoK4omhwqgg4p+oICJhIiDii4QgJ2EnIOKfqSAgICMgQSBzdHJpbmcgaXMgYW4gYXJyYXkgYnV0IGEgY2hhcmFjdGVyIGlzbid0">↗️</a><pre> <span class='Function'>≠</span><span class='Modifier'>¨</span> <span class='Bracket'>⟨</span> <span class='String'>"str"</span> <span class='Separator'>⋄</span> <span class='String'>"s't""r"</span> <span class='Separator'>⋄</span> <span class='String'>'c'</span> <span class='Separator'>⋄</span> <span class='String'>'''</span> <span class='Separator'>⋄</span> <span class='String'>'"'</span> <span class='Bracket'>⟩</span> <span class='Comment'># "" is an escape -</span>⟨ 3 5 1 1 1 ⟩ - - <span class='Function'>≡</span><span class='Modifier'>¨</span> <span class='Bracket'>⟨</span> <span class='String'>"a"</span> <span class='Separator'>⋄</span> <span class='String'>'a'</span> <span class='Bracket'>⟩</span> <span class='Comment'># A string is an array but a character isn't -</span>⟨ 1 0 ⟩ -</pre> -<p>But including a null character in your source code is probably not a great idea for other reasons. The null character (code point 0) has a dedicated literal representation <code><span class='String'>@</span></code>. Null can be used with <a href="arithmetic.html#character-arithmetic">character arithmetic</a> to directly convert between characters and numeric code points, which among many other uses allows tricky characters to be entered by code point: for example, a non-breaking space is <code><span class='String'>@</span><span class='Function'>+</span><span class='Number'>160</span></code>.</p> +<h2 id="tokens"><a class="header" href="#tokens">Tokens</a></h2> +<p><em><a href="token.html">Full documentation</a></em></p> +<p>BQN syntax is made up of tokens, which are mostly single characters. But there are a few exceptions:</p> +<ul> +<li><a href="token.html#comments">Comments</a> start with <code><span class='Comment'>#</span></code> and end at the end of the line.</li> +<li><a href="token.html#characters-and-strings">Character literals</a> start and end with <code><span class='String'>'</span></code>, and have exactly one character in between.</li> +<li><a href="token.html#characters-and-strings">String literals</a> start and end with <code><span class='String'>"</span></code>. Pairs of quotes <code><span class='String'>""</span></code> in between represent one quote character, and other characters (including <code><span class='String'>'</span></code>) represent themselves.</li> +<li><a href="token.html#numbers">Numbers</a> support decimal (<code><span class='Value'>.</span></code>) and scientific (<code><span class='Value'>e</span></code>) notation, plus <code><span class='Number'>π</span></code> and <code><span class='Number'>∞</span></code>, and use <code><span class='Number'>¯</span></code> for a minus sign.</li> +<li><a href="token.html#names">Variable names</a> allow letters, underscores, and numeric characters. They're matched case-insensitively, with a <a href="expression.html#role-spellings">spelling system</a> that determines role.</li> +</ul> <h2 id="expressions"><a class="header" href="#expressions">Expressions</a></h2> <p><em><a href="expression.html">Full documentation</a></em></p> <p>BQN expressions are composed of subjects, functions, and modifiers, with parentheses to group parts into subexpressions. <a href="ops.html#functions">Functions</a> can be applied to subjects or grouped into <a href="train.html">trains</a>, while <a href="ops.html#modifiers">modifiers</a> can be applied to subjects or functions. The most important kinds of application are:</p> @@ -263,9 +254,7 @@ <p><a href="expression.html#assignment">Assignment</a> arrows <code><span class='Gets'>←</span></code>, <code><span class='Gets'>↩</span></code>, and <code><span class='Gets'>⇐</span></code> store expression results in variables: <code><span class='Gets'>←</span></code> and <code><span class='Gets'>⇐</span></code> create new variables while <code><span class='Gets'>↩</span></code> modifies existing ones. The general format is <code><span class='Function'>Name</span> <span class='Gets'>←</span> <span class='Function'>Value</span></code>, where the two sides have the same role. Additionally, <code><span class='Value'>lhs</span> <span class='Function'>F</span><span class='Gets'>↩</span> <span class='Value'>rhs</span></code> is a shortened form of <code><span class='Value'>lhs</span> <span class='Gets'>↩</span> <span class='Value'>lhs</span> <span class='Function'>F</span> <span class='Value'>rhs</span></code> and <code><span class='Value'>lhs</span> <span class='Function'>F</span><span class='Gets'>↩</span></code> expands to <code><span class='Value'>lhs</span> <span class='Gets'>↩</span> <span class='Function'>F</span> <span class='Value'>lhs</span></code>.</p> <p>The double arrow <code><span class='Gets'>⇐</span></code> is used for functionality relating to <a href="namespace.html">namespaces</a>. It has a few purposes: exporting assignment <code><span class='Value'>name</span><span class='Gets'>⇐</span><span class='Value'>value</span></code>, plain export <code><span class='Value'>name</span><span class='Gets'>⇐</span></code>, and aliasing <code><span class='Bracket'>⟨</span><span class='Value'>alias</span><span class='Gets'>⇐</span><span class='Value'>field</span><span class='Bracket'>⟩</span><span class='Gets'>←</span><span class='Value'>namespace</span></code>. A block that uses it for export returns a namespace rather than the result of its last statement. The other namespace-related bit of syntax is field access <code><span class='Value'>ns.field</span></code>.</p> <h2 id="arrays-and-blocks"><a class="header" href="#arrays-and-blocks">Arrays and blocks</a></h2> -<p>Arrays and code blocks can both be represented as sequences of expressions in source code. There are paired bracket representations, using <code><span class='Bracket'>⟨⟩</span></code> for lists, <code><span class='Bracket'>[]</span></code> for arrays, and <code><span class='Brace'>{}</span></code> for blocks, as well as a shortcut "stranding" notation using <code><span class='Ligature'>‿</span></code> for lists.</p> -<h3 id="separators"><a class="header" href="#separators">Separators</a></h3> -<p>The characters <code><span class='Separator'>⋄</span></code> and <code><span class='Separator'>,</span></code> and newline are completely interchangeable and are used to separate expressions. An expression might be an element in a list or a line in a block. Empty sections—those that consist only of whitespace—are ignored. This means that any number of separators can be used between expressions, and that leading and trailing separators are also allowed. The expressions are evaluated in text order: left to right and top to bottom.</p> +<p>Arrays and code blocks can both be represented as sequences of expressions in source code. There are paired bracket representations, using <code><span class='Bracket'>⟨⟩</span></code> for lists, <code><span class='Bracket'>[]</span></code> for arrays, and <code><span class='Brace'>{}</span></code> for blocks, as well as a shortcut "stranding" notation using <code><span class='Ligature'>‿</span></code> for lists. Elements within brackets are divided by <a href="token.html#separators">separators</a>: <code><span class='Separator'>,</span></code> or <code><span class='Separator'>⋄</span></code> or a line break.</p> <h3 id="list-and-array-notation"><a class="header" href="#list-and-array-notation">List and array notation</a></h3> <p><em><a href="arrayrepr.html#array-literals">Full documentation</a></em></p> <p>Lists (1-dimensional arrays) are enclosed in angle brackets <code><span class='Bracket'>⟨⟩</span></code>, with the results of the expressions in between being the list's elements. Lists of two elements or more can also be written with the ligature character <code><span class='Ligature'>‿</span></code>. This character has higher binding strength than any part of an expression except <code><span class='Value'>.</span></code> for namespace field access. If one of the elements is a compound expression, then it will need to be enclosed in parentheses.</p> diff --git a/docs/doc/token.html b/docs/doc/token.html new file mode 100644 index 00000000..75387cde --- /dev/null +++ b/docs/doc/token.html @@ -0,0 +1,41 @@ +<head> + <link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/> + <link href="../style.css" rel="stylesheet"/> + <title>BQN: Tokens</title> +</head> +<div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">doc</a></div> +<h1 id="tokens"><a class="header" href="#tokens">Tokens</a></h1> +<p>A "token" is the smallest part of syntax, much like a word in English. BQN's rules for forming tokens are simpler than most programming languages, because most of them are single characters. There are only a few kinds of multi-character tokens: character and string literals written with <code><span class='String'>'</span></code> and <code><span class='String'>"</span></code>, and words which are numbers, names, or system values.</p> +<p>Strings (and characters) and comments have starting and ending conditions, but can't overlap. The first one that starts first "wins": it needs to end before any other token or comment can start. These also take precedence over other token rules, that is, characters inside a string or comment don't form other tokens.</p> +<h2 id="non-tokens"><a class="header" href="#non-tokens">Non-tokens</a></h2> +<p>Comments, and the horizontal whitespace characters space and tab, don't form tokens, since they don't do anything as far as the program's concerned. However, whitespace can be used to separate adjacent words or strings. Comments can only end with a newline, which doesn't need separating, so they <em>really</em> don't do anything, other than inform the reader about whatever you have to say. Note that newline characters (either LF or CR) are <a href="#separators">separators</a>, which are tokens.</p> +<h3 id="comments"><a class="header" href="#comments">Comments</a></h3> +<p>A comment starts with a <code><span class='Comment'>#</span></code> that isn't part of a character or string literal, and continues to the end of the line.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=JyMnIC0gMSAgI1RoaXMgaXMgdGhlIGNvbW1lbnQ=">↗️</a><pre> <span class='String'>'#'</span> <span class='Function'>-</span> <span class='Number'>1</span> <span class='Comment'>#This is the comment +</span>'"' +</pre> +<p>Every line of commentary needs its own <code><span class='Comment'>#</span></code>; there's no multi-line comment syntax.</p> +<h2 id="characters-and-strings"><a class="header" href="#characters-and-strings">Characters and strings</a></h2> +<p>Strings—lists of characters—are written with double quotes <code><span class='String'>""</span></code>, and <a href="types.html#characters">characters</a> with single quotes <code><span class='String'>''</span></code> with a single character in between. Only one character ever needs to be escaped: a double quote in a string is written twice. So <code><span class='String'>""""</span></code> is a one-character string of <code><span class='String'>"</span></code>, and if two string literals are next to each other, they have to be separated by a space. Character literals don't have even one escape, as the length is already known. Other than the double quote, character and string literals can contain any character directly: newlines, null characters, or other Unicode.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omgwqgg4p+oICJzdHIiIOKLhCAicyd0IiJyIiDii4QgJ2MnIOKLhCAnJycg4ouEICciJyDin6kgICAjICIiIGlzIGFuIGVzY2FwZQoK4omhwqgg4p+oICJhIiDii4QgJ2EnIOKfqSAgICMgQSBzdHJpbmcgaXMgYW4gYXJyYXkgYnV0IGEgY2hhcmFjdGVyIGlzbid0">↗️</a><pre> <span class='Function'>≠</span><span class='Modifier'>¨</span> <span class='Bracket'>⟨</span> <span class='String'>"str"</span> <span class='Separator'>⋄</span> <span class='String'>"s't""r"</span> <span class='Separator'>⋄</span> <span class='String'>'c'</span> <span class='Separator'>⋄</span> <span class='String'>'''</span> <span class='Separator'>⋄</span> <span class='String'>'"'</span> <span class='Bracket'>⟩</span> <span class='Comment'># "" is an escape +</span>⟨ 3 5 1 1 1 ⟩ + + <span class='Function'>≡</span><span class='Modifier'>¨</span> <span class='Bracket'>⟨</span> <span class='String'>"a"</span> <span class='Separator'>⋄</span> <span class='String'>'a'</span> <span class='Bracket'>⟩</span> <span class='Comment'># A string is an array but a character isn't +</span>⟨ 1 0 ⟩ +</pre> +<p>But including a null character in your source code is probably not a great idea for other reasons. The null character (code point 0) has a dedicated literal representation <code><span class='String'>@</span></code>. Null can be used with <a href="arithmetic.html#character-arithmetic">character arithmetic</a> to directly convert between characters and numeric code points, which among many other uses allows tricky characters to be entered by code point: for example, a non-breaking space is <code><span class='String'>@</span><span class='Function'>+</span><span class='Number'>160</span></code>.</p> +<h2 id="words"><a class="header" href="#words">Words</a></h2> +<p>Numbers and variable names share a token formation rule, and are collectively called words. A word is a number if it starts with a digit or numeric character <code><span class='Number'>¯∞π</span></code>, and a name otherwise.</p> +<p>Words are formed from digits, letters, and the characters <code><span class='Modifier2'>_</span><span class='Value'>.</span><span class='Number'>¯∞π</span></code>. All these characters stick together, so that you need to separate words with whitespace in order to write them next to each other. But <code><span class='Value'>.</span></code> only counts if it's followed by a digit: otherwise it forms its own token to support <a href="namespace.html#imports">namespace syntax</a> <code><span class='Value'>ns.field</span></code>. A word may be preceded by <code><span class='Value'>•</span></code> to form a system name.</p> +<p>The character <code><span class='Value'>𝕣</span></code> also sticks with other word-forming characters, but is only allowed form the special names <code><span class='Value'>𝕣</span></code>, <code><span class='Modifier'>_𝕣</span></code>, and <code><span class='Modifier2'>_𝕣_</span></code>.</p> +<h3 id="numbers"><a class="header" href="#numbers">Numbers</a></h3> +<p><a href="types.html#numbers">Numbers</a> are written as decimals, allowing <code><span class='Number'>¯</span></code> for the negative sign (because <code><span class='Function'>-</span></code> is a function) and <code><span class='Value'>e</span></code> or <code><span class='Function'>E</span></code> for scientific notation. They must have digits before and after the decimal point (so, <code><span class='Number'>0.5</span></code> instead of <code><span class='Number'>.5</span></code>), and any exponent must be an integer. Two special numbers <code><span class='Number'>∞</span></code> and <code><span class='Number'>π</span></code> are supported, possibly with a minus sign. If complex numbers are supported (no implementation to date has them), then they can be written with the components separated by <code><span class='Value'>i</span></code> or <code><span class='Function'>I</span></code>.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oIMKvz4Ag4ouEIDAuNSDii4QgNWXCrzEg4ouEIDEuNUUzIOKLhCDiiJ4g4p+pICAgIyBBIGxpc3Qgb2YgbnVtYmVycw==">↗️</a><pre> <span class='Bracket'>⟨</span> <span class='Number'>¯π</span> <span class='Separator'>⋄</span> <span class='Number'>0.5</span> <span class='Separator'>⋄</span> <span class='Number'>5e¯1</span> <span class='Separator'>⋄</span> <span class='Number'>1.5E3</span> <span class='Separator'>⋄</span> <span class='Number'>∞</span> <span class='Bracket'>⟩</span> <span class='Comment'># A list of numbers +</span>⟨ ¯3.141592653589793 0.5 0.5 1500 ∞ ⟩ +</pre> +<h3 id="names"><a class="header" href="#names">Names</a></h3> +<p>A variable name starts with a letter but otherwise can contain anything, including characters like <code><span class='Number'>∞</span></code> and <code><span class='Number'>¯</span></code>. Names represent identifiers according to the rules of <a href="lexical.html">lexical scoping</a>. A somewhat unusual feature of BQN is that identifiers are case- and underscore-insensitive, so that <code><span class='Value'>abc</span></code> is treated as the same name as <code><span class='Modifier'>_a_B_c</span></code>. This works with the <a href="expression.html#role-spellings">role spelling</a> system so that changing the case or adding underscores allows the same variable to be used in different roles.</p> +<p>The system dot <code><span class='Value'>•</span></code> can only start a word, and must be followed by a name. This accesses a system value such as the debugging display function <code><span class='Function'>•Show</span></code>.</p> +<h2 id="separators"><a class="header" href="#separators">Separators</a></h2> +<p>The characters <code><span class='Separator'>⋄</span></code> and <code><span class='Separator'>,</span></code> and newline are completely interchangeable and are used to separate expressions. An expression might be an element in a list or a line in a block. Empty sections—those that consist only of whitespace—are ignored. This means that any number of separators can be used between expressions, and that leading and trailing separators are also allowed. The expressions are evaluated in text order: left to right and top to bottom.</p> +<p>Both LF and CR are allowed as newline characters, and CRLF functions as a separator too because of the way multiple separators work.</p> diff --git a/docs/help/character.html b/docs/help/character.html index 7a29a0f5..4675c644 100644 --- a/docs/help/character.html +++ b/docs/help/character.html @@ -6,7 +6,7 @@ <div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">help</a></div> <h1 id="single-quote-"><a class="header" href="#single-quote-">Single Quote (<code><span class='String'>'</span></code>)</a></h1> <h2 id="c-character"><a class="header" href="#c-character"><code><span class='String'>'c'</span></code>: Character</a></h2> -<p><a class="fulldoc" href="../doc/syntax.html#constants">→full documentation</a></p> +<p><a class="fulldoc" href="../doc/token.html#characters-and-strings">→full documentation</a></p> <p>A character literal whose value is the character between quotes. Any character can be used, even <code><span class='String'>'</span></code> and newline.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=J2En4oC/J2In">↗️</a><pre> <span class='String'>'a'</span><span class='Ligature'>‿</span><span class='String'>'b'</span> "ab" diff --git a/docs/help/comment.html b/docs/help/comment.html index 70671d81..8b02d745 100644 --- a/docs/help/comment.html +++ b/docs/help/comment.html @@ -6,7 +6,7 @@ <div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">help</a></div> <h1 id="number-sign-"><a class="header" href="#number-sign-">Number Sign (<code><span class='Comment'>#</span></code>)</a></h1> <h2 id="-comment"><a class="header" href="#-comment"><code><span class='Comment'>#</span></code>: Comment</a></h2> -<p><a class="fulldoc" href="../doc/syntax.html#comments">→full documentation</a></p> +<p><a class="fulldoc" href="../doc/token.html#comments">→full documentation</a></p> <p>Create a comment that extends to the end of the line.</p> <p>Anything written in comments is ignored.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MSArIDIgIyArIDMgKyA0CgoiSGVsbG8gd29ybGQhIiAjIHRoaXMgaXMgaWdub3JlZCE=">↗️</a><pre> <span class='Number'>1</span> <span class='Function'>+</span> <span class='Number'>2</span> <span class='Comment'># + 3 + 4 diff --git a/docs/help/infinity.html b/docs/help/infinity.html index c607967e..8771e545 100644 --- a/docs/help/infinity.html +++ b/docs/help/infinity.html @@ -6,7 +6,7 @@ <div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">help</a></div> <h1 id="infinity-"><a class="header" href="#infinity-">Infinity (<code><span class='Number'>∞</span></code>)</a></h1> <h2 id="-infinity"><a class="header" href="#-infinity"><code><span class='Number'>∞</span></code>: Infinity</a></h2> -<p><a class="fulldoc" href="../doc/syntax.html#constants">→full documentation</a></p> +<p><a class="fulldoc" href="../doc/token.html#numbers">→full documentation</a></p> <p>Mathematical constant Infinity, a numeric literal. Can be negative (<code><span class='Number'>¯∞</span></code>).</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oieCgrCr+KIngoKMSviiJ4=">↗️</a><pre> <span class='Number'>∞</span> ∞ diff --git a/docs/help/minus.html b/docs/help/minus.html index c235aa75..ca43170a 100644 --- a/docs/help/minus.html +++ b/docs/help/minus.html @@ -6,7 +6,7 @@ <div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">help</a></div> <h1 id="macron-"><a class="header" href="#macron-">Macron (<code><span class='Number'>¯</span></code>)</a></h1> <h2 id="-minus"><a class="header" href="#-minus"><code><span class='Number'>¯</span></code>: Minus</a></h2> -<p><a class="fulldoc" href="../doc/syntax.html#constants">→full documentation</a></p> +<p><a class="fulldoc" href="../doc/token.html#numbers">→full documentation</a></p> <p>Prefix before numbers to indicate that they are negative.</p> <p>Note that this is not the same as <code><span class='Function'>-</span></code>, since it is part of the number, rather than a primitive that negates its value.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=LTHigL8y4oC/MwoKwq8x4oC/MuKAvzM=">↗️</a><pre> <span class='Function'>-</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span> diff --git a/docs/help/nullcharacter.html b/docs/help/nullcharacter.html index 24bcf67e..491642e8 100644 --- a/docs/help/nullcharacter.html +++ b/docs/help/nullcharacter.html @@ -6,7 +6,7 @@ <div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">help</a></div> <h1 id="commercial-at-"><a class="header" href="#commercial-at-">Commercial At (<code><span class='String'>@</span></code>)</a></h1> <h2 id="-null-character"><a class="header" href="#-null-character"><code><span class='String'>@</span></code>: Null Character</a></h2> -<p><a class="fulldoc" href="../doc/syntax.html#constants">→full documentation</a></p> +<p><a class="fulldoc" href="../doc/token.html#characters-and-strings">→full documentation</a></p> <p>Null character, code point 0 in ASCII. A shortcut character literal.</p> <p>Add to a code point number to get that character.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=QCs1MAoKQAoKQCs2NA==">↗️</a><pre> <span class='String'>@</span><span class='Function'>+</span><span class='Number'>50</span> diff --git a/docs/help/pi.html b/docs/help/pi.html index 3a947cb2..7d677211 100644 --- a/docs/help/pi.html +++ b/docs/help/pi.html @@ -6,7 +6,7 @@ <div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">help</a></div> <h1 id="pi-π"><a class="header" href="#pi-π">Pi (<code><span class='Number'>π</span></code>)</a></h1> <h2 id="π-pi"><a class="header" href="#π-pi"><code><span class='Number'>π</span></code>: Pi</a></h2> -<p><a class="fulldoc" href="../doc/syntax.html#constants">→full documentation</a></p> +<p><a class="fulldoc" href="../doc/token.html#numbers">→full documentation</a></p> <p>The mathematical constant pi, a numeric literal. Can be negative (<code><span class='Number'>¯π</span></code>).</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=z4AKCsKvz4A=">↗️</a><pre> <span class='Number'>π</span> 3.141592653589793 diff --git a/docs/help/separator.html b/docs/help/separator.html index 3c104dbe..931d635e 100644 --- a/docs/help/separator.html +++ b/docs/help/separator.html @@ -6,7 +6,7 @@ <div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">help</a></div> <h1 id="comma--and-diamond-"><a class="header" href="#comma--and-diamond-">Comma (<code><span class='Separator'>,</span></code>) and Diamond (<code><span class='Separator'>⋄</span></code>)</a></h1> <h2 id="-or--separator"><a class="header" href="#-or--separator"><code><span class='Separator'>,</span></code> or <code><span class='Separator'>⋄</span></code>: Separator</a></h2> -<p><a class="fulldoc" href="../doc/syntax.html#separators">→full documentation</a></p> +<p><a class="fulldoc" href="../doc/token.html#separators">→full documentation</a></p> <p>Separates statements in blocks, programs, and arrays. Characters <code><span class='Separator'>,</span></code> and <code><span class='Separator'>⋄</span></code> are interchangeable with each other and with newline.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YSDihpAgMyAsIOKKoiBiIOKGkCAyCgoxIOKLhCAyICwgMwoK4p+oMSAsIDIg4ouEIDPin6kKCnsxIOKLhCAyIOKLhCAzfQ==">↗️</a><pre> <span class='Value'>a</span> <span class='Gets'>←</span> <span class='Number'>3</span> <span class='Separator'>,</span> <span class='Function'>⊢</span> <span class='Value'>b</span> <span class='Gets'>←</span> <span class='Number'>2</span> 2 diff --git a/docs/help/string.html b/docs/help/string.html index d7d1e74a..18a6db4f 100644 --- a/docs/help/string.html +++ b/docs/help/string.html @@ -6,7 +6,7 @@ <div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">help</a></div> <h1 id="double-quote-"><a class="header" href="#double-quote-">Double Quote (<code><span class='String'>"</span></code>)</a></h1> <h2 id="str-string"><a class="header" href="#str-string"><code><span class='String'>"str"</span></code>: String</a></h2> -<p><a class="fulldoc" href="../doc/syntax.html#constants">→full documentation</a></p> +<p><a class="fulldoc" href="../doc/token.html#characters-and-strings">→full documentation</a></p> <p>Literal notation for a string, or list of characters. Double quotes must be escaped by writing them twice. Any other characters can be included directly.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MiDiipEgInN0cmluZyIKCjIg4oqRICJhYiIiY2Qi">↗️</a><pre> <span class='Number'>2</span> <span class='Function'>⊑</span> <span class='String'>"string"</span> 'r' |
