Skip to content

Commit 6c12e61

Browse files
authored
Merge pull request #2034 from xushiwei/q
mini spec: Notation
2 parents 84b467d + a1436dd commit 6c12e61

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

doc/spec-mini.md

+29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
Go+ Specification for STEM Education
22
=====
33

4+
## Notation
5+
6+
The syntax is specified using a [variant](https://en.wikipedia.org/wiki/Wirth_syntax_notation) of Extended Backus-Naur Form (EBNF):
7+
8+
```go
9+
Syntax = { Production } .
10+
Production = production_name "=" [ Expression ] "." .
11+
Expression = Term { "|" Term } .
12+
Term = Factor { Factor } .
13+
Factor = production_name | token [ "" token ] | Group | Option | Repetition .
14+
Group = "(" Expression ")" .
15+
Option = "[" Expression "]" .
16+
Repetition = "{" Expression "}" .
17+
```
18+
19+
Productions are expressions constructed from terms and the following operators, in increasing precedence:
20+
21+
```go
22+
| alternation
23+
() grouping
24+
[] option (0 or 1 times)
25+
{} repetition (0 to n times)
26+
```
27+
28+
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 ``.
29+
30+
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.
31+
32+
433
## Comments
534

635
Comments serve as program documentation. There are three forms:

0 commit comments

Comments
 (0)