diff --git a/docs/grammar.ebnf b/docs/grammar.ebnf new file mode 100644 index 0000000..0c1f97c --- /dev/null +++ b/docs/grammar.ebnf @@ -0,0 +1,208 @@ +/** + * This is a pseudo description of the grammar of Kuroko in + * EBNF form. It is not necessarily a complete and accurate + * grammar and should not be used to develop parsers, but + * instead as an overview of how the existing Pratt parser + * handles precedence and recursion. + * + * , , and are special token + * types from the scanner. has special rules + * regarding width that must remain consistent throughout + * a block which can not be easily represented in an EBNF + * grammar like this. Python opts for using an "indent" and + * "dedent" symbol... + */ + ::= | | | "True" | "False" | "None" + + ::= | | | | + + ::= "0" ("o" | "o") [0-7]+ + + ::= "0" ("x" | "X") ([0-9] | [a-f] | [A-F])+ + + ::= "0" ("b" | "B") ("0" | "1")+ + + ::= [0-9]+ + + ::= [0-9]+ "." [0-9]+ + + ::= + + ::= + ( ("=" ) + | ("|=" ) + | ("^=" ) + | ("&=" ) + | ("<<=" ) + | (">>=" ) + | ("+=" ) + | ("-=" ) + | ("*=" ) + | ("**=" ) + | ("/=" ) + | ("%=" ) + | ("++") + | ("--") )? + + ::= ("if" "else" )? + + ::= ("or" )? + + ::= ("and" )? + + ::= + ( ("<" ) + | (">" ) + | ("<=" ) + | (">=" ) + | ("in" ) + | ("not" "in" ) + | ("!=" ) + | ("==" ) + | ("is" ) + )? + + ::= ("|" )? + + ::= ("^" )? + + ::= ("&" )? + + ::= + ( ("<<" ) + | (">>" ) )? + + ::= + ( ("+" ) + | ("-" ) )? + + ::= + ( ("*" ) + | ("/" ) + | ("%" ) )? + + ::= + | ("!" ) + | ("-" ) + | ("not" ) + | + | + | + | + | + | + | + + ::= "lambda" ( ("," )* )? ":" + + ::= ("**" )? + + ::= + ( ("." ) + | ("(" ")") + | ("[" "]") + | ("[" ()? ":" ()? "]") )? + + ::= ("," )* + + ::= ( "=" ) + | + | ("*" ) + | ("**" ) + + ::= "(" ")" + + ::= "in" ("if" )? + + ::= ("," )* + + ::= "()" + | ( "(" "," ")" ) + | ( "(" "," ("," )* (",")? ")" ) + | ( "(" "for" ")" ) + + ::= "[]" + | ( "[" ("," )* (",")? "]" ) + | ( "[" "for" "]" ) + + ::= "{}" + | ( "{" ":" ("," ":" )* (",")? "}" ) + | ( "{" ":" "for" "}" ) + + ::= ("{" ("," )* "}") + | ("{" "for" "}") + + ::= | | | | | "\n" + + ::= "def" + + ::= "(" ")" ":" + + ::= ("," )? + + ::= ( ("," )*) + | ( ( ("," )* ",")? "=" ("," "=" )* ) + + ::= ("*" ) + | ("**" ) + | ("*" "," "**" ) + + ::= "let" ("," )* ("=" ("," )*)? + + ::= "class" "(" ()? ")" ":" + + ::= "\n" ( )* + + ::= "\n" + | + | ( "=" "\n") + | ("pass" "\n") + | + + ::= "@" "\n" ( | | ) + + ::= + | + | + | + | + | ( "\n") + + ::= ( ";" ) + | ("raise" ) + | ( ()?) + | + | + | "break" + | "continue" + | "pass" + | + | + + ::= "if" + + ::= ":" ()? + + ::= ("else" "if" ) + | ("elif" ) + | ("else" ":" ) + + ::= "while" ":" + + ::= ("for" ("," )* "in" ":" ) + | ("for" ("=" )? ("," ("=" )?)* ";" (";" ("," )*)? ":" + + ::= "try" ":" ("except" ()? ("as" )? ":" )? + + ::= "with" ("as" )? ":" + + ::= "import" ("as" )? ("," ("as" )?)* + + ::= "from" "import" ("as" )? ("," ("as" )?)* + + ::= ("." )* + + ::= "del" ("," )* + + ::= ("\n" ( )*) | +