aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-06-19 23:08:38 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-06-19 23:08:38 -0400
commitf08b43887ce862a173efa18c4a2554408ac9356c (patch)
tree67c4fc0f29f3d5cf4b64b61927a17f43790aca74
parentc24bb47929e2e82b742310a20216a72df5aac893 (diff)
Add explicit definition syntax
-rw-r--r--spec/grammar.md13
1 files changed, 11 insertions, 2 deletions
diff --git a/spec/grammar.md b/spec/grammar.md
index 1f863a1b..7154e706 100644
--- a/spec/grammar.md
+++ b/spec/grammar.md
@@ -2,10 +2,10 @@ BQN's grammar is given below. All terms except `BraceFunc` `_braceMod` `_braceCo
The symbols `v`, `F`, `_m`, and `_c_` are identifier tokens with value, function, modifier, and composition classes respectively. Similarly, `vl`, `Fl`, `_ml`, and `_cl_` refer to value literals (numeric and character literals, or primitives) of those classes. While names in the BNF here follow the identifier naming scheme, this is informative only: syntactic classes are no longer used after parsing and cannot be inspected in a running program.
-A program is a list of statements. Almost all statements are expressions. However, valueless results stemming from `ยท`, or `๐•จ` in a monadic brace function, can be used as statements but not expressions.
+A program is a list of statements. Almost all statements are expressions. However, explicit definitions and valueless results stemming from `ยท`, or `๐•จ` in a monadic brace function, can be used as statements but not expressions.
PROGRAM = โ‹„? ( ( STMT โ‹„ )* STMT โ‹„? )?
- STMT = EXPR | nothing
+ STMT = EXPR | DEF | nothing
โ‹„ = ( "โ‹„" | "," | \n )+
EXPR = valExpr | FuncExpr | _modExpr | _cmpExp_
@@ -60,6 +60,15 @@ Value expressions are complicated by the possibility of list assignment. We also
| v ASGN valExpr
| v Derv "โ†ฉ" valExpr โ Modified assignment
+In an explicit definition, the left hand side looks like application of a function, modifier, or combinator. As with assignment, it is restricted to a simple form with no extra parentheses. The full list syntax is allowed for arguments.
+
+ DEF = VALDEF | FUNCDEF
+ VALDEF = valLHS "โ‡" valExpr
+ FUNCDEF = FuncLHS "โ‡" FuncExpr
+ FuncLHS = F _m
+ | F _c_ F
+ valLHS = lhs? ( F | FuncLHS ) lhs
+
One aspect of BQN grammar is not context-free: determining the syntactic class of a brace definition. The terms `braceVal`, `BraceFunc` `_braceMod` `_braceComp_` all obey the syntax for `BRACED` given below. Then the class is determined by the presence of `๐•จ`, `๐•ฉ`, `๐•—`, and `๐•˜` (including alternate class spellings) at the top level, that is, not contained within further pairs of braces. If `๐•˜` is present, it is a `_braceCmp_`; otherwise, if `๐•—` is present it is a `_braceMod`; otherwise is is a `BraceFunc` if `๐•จ` or `๐•ฉ` are present and a `braceVal` if no special names appear.
BRACED = "{" โ‹„? ( STMT โ‹„ )* EXPR โ‹„? "}"