Skip to content

Commit 12856e6

Browse files
committed
Add formal language grammar in BNF
1 parent 4d7950d commit 12856e6

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

BITSY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The BitsySwift repository has some
5252

5353
While the hope of this repo is to codify the definition of Bitsy in a series of
5454
runnable tests, it is also useful to define the language informally using words
55-
and examples.
55+
and examples. For a formal definition of the Bitsy grammar, see [GRAMMAR.txt](GRAMMAR.txt)
5656

5757
### Program Definition
5858

GRAMMAR.txt

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<program> ::= BEGIN <block> END
2+
3+
<block> ::= { <if-statement> | <loop> | <break> | <print> | <read> | <assignment> }
4+
5+
<if-statement> ::= <if-keyword> <expression> <block> [ ELSE <block> ] END
6+
7+
<if-keyword> ::= IFZ | IFP | IFN
8+
9+
<loop> ::= LOOP <block> END
10+
11+
<break> ::= BREAK
12+
13+
<print> ::= PRINT <expression>
14+
15+
<read> ::= READ <var-name>
16+
17+
<assignment> ::= <var-nam> "=" <expression>
18+
19+
<expression> ::= <term> { <add-op> <term> }
20+
21+
<term> ::= <signed-factor> { <mul-op> <factor> }
22+
23+
<signed-factor> ::= [ add-op ] <factor>
24+
25+
<factor> ::= <integer> | <var-name> | "(" <expression> ")"
26+
27+
<var-name> ::= <ident-char> { <ident-char> }
28+
29+
<integer> ::= <digit> { <digit> }
30+
31+
<add-op> ::= "+" | "-"
32+
33+
<mul-op> ::= "*" | "/" | "%"
34+
35+
<ident-char> ::= "_" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
36+
37+
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ language design.
77
* Read more about the Bitsy language: [BITSY.md](BITSY.md)
88
* See the canonical implementation: [BitsySwift](https://github.com/apbendi/bitsy-swift)
99
* Read more about why Bitsy exists: [Introducing Bitsy](http://www.scopelift.co/blog/introducing-bitsy-the-first-language-youll-implement-yourself)
10+
* See the formal language grammar in [BNF](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form) notation: [GRAMMAR](GRAMMAR.txt)
1011

1112
# BitsySpec
1213

0 commit comments

Comments
 (0)