From a1436dd7cafb1a480153971d3473476f0dc0ef04 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 12 Dec 2024 22:27:07 +0800 Subject: [PATCH] mini spec: Notation --- doc/spec-mini.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/doc/spec-mini.md b/doc/spec-mini.md index 385b53fd1..e4701d327 100644 --- a/doc/spec-mini.md +++ b/doc/spec-mini.md @@ -1,6 +1,35 @@ Go+ Specification for STEM Education ===== +## Notation + +The syntax is specified using a [variant](https://en.wikipedia.org/wiki/Wirth_syntax_notation) of Extended Backus-Naur Form (EBNF): + +```go +Syntax = { Production } . +Production = production_name "=" [ Expression ] "." . +Expression = Term { "|" Term } . +Term = Factor { Factor } . +Factor = production_name | token [ "…" token ] | Group | Option | Repetition . +Group = "(" Expression ")" . +Option = "[" Expression "]" . +Repetition = "{" Expression "}" . +``` + +Productions are expressions constructed from terms and the following operators, in increasing precedence: + +```go +| alternation +() grouping +[] option (0 or 1 times) +{} repetition (0 to n times) +``` + +Lowercase production names are used to identify lexical (terminal) tokens. Non-terminals are in CamelCase. Lexical tokens are enclosed in double quotes `""` or back quotes ``. + +The form `a … b` represents the set of characters from a through b as alternatives. The horizontal ellipsis `…` is also used elsewhere in the spec to informally denote various enumerations or code snippets that are not further specified. The character … (as opposed to the three characters `...`) is not a token of the Go+ language. + + ## Comments Comments serve as program documentation. There are three forms: