Spaces:
Runtime error
Runtime error
Upload 7 files
Browse files- grammars/arithmetic.gbnf +6 -0
- grammars/c.gbnf +42 -0
- grammars/chess.gbnf +13 -0
- grammars/json.gbnf +14 -0
- grammars/json_w_trailing_space.gbnf +14 -0
- grammars/list.gbnf +2 -0
- grammars/simple_arithmetic.gbnf +7 -0
grammars/arithmetic.gbnf
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
root ::= (expr "=" ws term "\n")+
|
2 |
+
expr ::= term ([-+*/] term)*
|
3 |
+
term ::= ident | num | "(" ws expr ")" ws
|
4 |
+
ident ::= [a-z] [a-z0-9_]* ws
|
5 |
+
num ::= [0-9]+ ws
|
6 |
+
ws ::= [ \t\n]*
|
grammars/c.gbnf
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
root ::= (declaration)*
|
2 |
+
|
3 |
+
declaration ::= dataType identifier "(" parameter? ")" "{" statement* "}"
|
4 |
+
|
5 |
+
dataType ::= "int" ws | "float" ws | "char" ws
|
6 |
+
identifier ::= [a-zA-Z_] [a-zA-Z_0-9]*
|
7 |
+
|
8 |
+
parameter ::= dataType identifier
|
9 |
+
|
10 |
+
statement ::=
|
11 |
+
( dataType identifier ws "=" ws expression ";" ) |
|
12 |
+
( identifier ws "=" ws expression ";" ) |
|
13 |
+
( identifier ws "(" argList? ")" ";" ) |
|
14 |
+
( "return" ws expression ";" ) |
|
15 |
+
( "while" "(" condition ")" "{" statement* "}" ) |
|
16 |
+
( "for" "(" forInit ";" ws condition ";" ws forUpdate ")" "{" statement* "}" ) |
|
17 |
+
( "if" "(" condition ")" "{" statement* "}" ("else" "{" statement* "}")? ) |
|
18 |
+
( singleLineComment ) |
|
19 |
+
( multiLineComment )
|
20 |
+
|
21 |
+
forInit ::= dataType identifier ws "=" ws expression | identifier ws "=" ws expression
|
22 |
+
forUpdate ::= identifier ws "=" ws expression
|
23 |
+
|
24 |
+
condition ::= expression relationOperator expression
|
25 |
+
relationOperator ::= ("<=" | "<" | "==" | "!=" | ">=" | ">")
|
26 |
+
|
27 |
+
expression ::= term (("+" | "-") term)*
|
28 |
+
term ::= factor(("*" | "/") factor)*
|
29 |
+
|
30 |
+
factor ::= identifier | number | unaryTerm | funcCall | parenExpression
|
31 |
+
unaryTerm ::= "-" factor
|
32 |
+
funcCall ::= identifier "(" argList? ")"
|
33 |
+
parenExpression ::= "(" ws expression ws ")"
|
34 |
+
|
35 |
+
argList ::= expression ("," ws expression)*
|
36 |
+
|
37 |
+
number ::= [0-9]+
|
38 |
+
|
39 |
+
singleLineComment ::= "//" [^\n]* "\n"
|
40 |
+
multiLineComment ::= "/*" ( [^*] | ("*" [^/]) )* "*/"
|
41 |
+
|
42 |
+
ws ::= ([ \t\n]+)
|
grammars/chess.gbnf
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Specifies chess moves as a list in algebraic notation, using PGN conventions
|
2 |
+
|
3 |
+
# Force first move to "1. ", then any 1-2 digit number after, relying on model to follow the pattern
|
4 |
+
root ::= "1. " move " " move "\n" ([1-9] [0-9]? ". " move " " move "\n")+
|
5 |
+
move ::= (pawn | nonpawn | castle) [+#]?
|
6 |
+
|
7 |
+
# piece type, optional file/rank, optional capture, dest file & rank
|
8 |
+
nonpawn ::= [NBKQR] [a-h]? [1-8]? "x"? [a-h] [1-8]
|
9 |
+
|
10 |
+
# optional file & capture, dest file & rank, optional promotion
|
11 |
+
pawn ::= ([a-h] "x")? [a-h] [1-8] ("=" [NBKQR])?
|
12 |
+
|
13 |
+
castle ::= "O-O" "-O"?
|
grammars/json.gbnf
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
root ::= object
|
2 |
+
|
3 |
+
object ::= "{" ws ( string ":" ws value ("," ws string ":" ws value)* )? "}"
|
4 |
+
|
5 |
+
value ::= object | array | string | number | ("true" | "false" | "null") ws
|
6 |
+
|
7 |
+
array ::= "[" ws ( value ("," ws value)* )? "]" ws
|
8 |
+
|
9 |
+
string ::= "\"" ( [a-zA-Z0-9] )* "\"" ws
|
10 |
+
|
11 |
+
number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? ws
|
12 |
+
|
13 |
+
|
14 |
+
ws ::= ([ \t\n] ws)?
|
grammars/json_w_trailing_space.gbnf
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
root ::= object
|
2 |
+
|
3 |
+
object ::= "{" ws ( string ":" ws value ("," ws string ":" ws value)* )? "}" ws
|
4 |
+
|
5 |
+
value ::= object | array | string | number | ("true" | "false" | "null") ws
|
6 |
+
|
7 |
+
array ::= "[" ws ( value ("," ws value)* )? "]" ws
|
8 |
+
|
9 |
+
string ::= "\"" ( [a-zA-Z0-9] )* "\"" ws
|
10 |
+
|
11 |
+
number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? ws
|
12 |
+
|
13 |
+
|
14 |
+
ws ::= ([ \t\n] ws)?
|
grammars/list.gbnf
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
root ::= "1. " paragraph "\n" ([0-9] [0-9]? ". " paragraph "\n")+
|
2 |
+
paragraph ::= [a-zA-Z'.,; ]+
|
grammars/simple_arithmetic.gbnf
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
root ::= (expr "=" ws term "\n")+
|
2 |
+
expr ::= term ([-+*/] term)*
|
3 |
+
term ::= num | "(" ws expr ")" ws
|
4 |
+
num ::= [0-9]+ ws
|
5 |
+
ws ::= [ \t\n]*
|
6 |
+
# this is a comment
|
7 |
+
|