-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathebnf.txt
22 lines (22 loc) · 1.09 KB
/
ebnf.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// https://bnfplayground.pauliankline.com/
<top_decl> ::= "pub"? ("const" | "let") <ident> "=" <fn> | <struct> | <or>
<fn> ::= "fn" "(" <args>? ")" <block>
<struct> ::= "struct" "{" <declarators>? "}"
<declarators> ::= (<declarator> ("," <declarator>)*)?
<declarator> ::= "pub"? <ident>
<args> ::= (<arg> ("," <arg>)*)?
<arg> ::= ("self" | <ident>) (":" ("*" | "&" | "let" | "const")? <type>)?
<inner_decl> ::= ( "const" | "let") <ident> "=" <or> ";"
<block> ::= "{" <inner_decl>* <return> "}"
<return> ::= "return" <or> ";"
<or> ::= <and> ("||" <and>)*
<and> ::= <equality> ("&&" <equality>)*
<equality> ::= <cmp> (("!=" | "==") <cmp>)*
<cmp> ::= <low_bin> ((">" | ">=" | "<" | "<=") <low_bin>)*
<low_bin> ::= <high_bin> (("+" | "-") <high_bin>)*
<high_bin> ::= <unary> (("*" | "/") <unary>)*
<unary> ::= (("!" | "-") <unary>) | <terminal>
<terminal> ::= "true" | "false" | "undefined" | "self" | "never" | <num> | <ident>
<ident> ::= ([a-z] | [A-Z] | "_") ([A-Z] | [a-z] | [0-9] | "_")*
<num> ::= ([1-9] [0-9]* "."? ([0-9])+) | [0-9] "." [1-9]+ | [0-9]
<type> ::= ("num" | "u64" | "any" | <ident>) ("+" "," <type>)*