-
Notifications
You must be signed in to change notification settings - Fork 10
/
theta_grammar.bnf
74 lines (53 loc) · 3.42 KB
/
theta_grammar.bnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
; Backus-Naur Format (BNF)
; ? = 0 or 1 occurrence
; + = 1 or more occurrences
; * = 0 or more occurrences
<function-invocation> ::= <identifier> "(" ((identifier | literal) ","?)* ")" ;
<function-definition> ::= "(" <identifier-declaration>* ")" "->" (<expression> | <block>)
| <identifier-declaration>* "->" (<expression> | <block>) ;
<if-statement> ::= "if" <expression> <block> <else-if-statement>* <else-statement>? ;
<else-if-statement> ::= "else if" <expression> <block> ;
<else-statement> ::= "else" <block> ;
<block> ::= "{" <expression>* "}" ;
<assignment> ::= <identifier-declaration> "=" <expression>
| <identifier-declaration> "=" <function-definition>;
<identifier-declaration> ::= <identifier> <type> ;
<enum> ::= "enum" <identifier> "{" (<symbol> ","?)* "}" ;
<struct> ::= "struct" <identifier> "{" (<identifier> <type> ","?)* "}" ;
<capsule> ::= "capsule" <identifier> "{" <assignment>* <struct>* <enum>* <function-definition>* "}"
<single-line-comment> ::= "//" <string> "\n"
<multi-line-comment> ::= "/-" <string> "\n"* "-/"
<expression> ::= <identifier>
| <literal>
| "!"+ (<identifier> | <boolean> | <comparative-expression>)
| <numeric-expression>
| "-" (<number> | "(" <numeric-expression> ")")
| <string> "+" <string>
| <comparative-expression>
| <function-invocation>
| <pipeline> ;
<pipeline> ::= <expression> ("=>" <function-invocation>)+ ;
<comparative-expression> ::= <expression> <comparitive-operator> <expression> ;
<numeric-expression> ::= <number>
| <number> <arithmetic-operator> <number>
| <numeric-expression> <arithmetic-operator> <numeric-expression> ;
<type> ::= "<" <uppercase-letter>+ <letter>* <type>? ">" ;
<list> ::= "[" <expression>? "]"
| "[" (<expression> ","?)+ "]" ;
<dict> ::= "{" <key-value-pair>* "}" ;
<key-value-pair> ::= <identifier> ":" (<expression> | <function-definition>) ;
<symbol> ::= ":" <identifier> ;
<literal> ::= <string> | <number> | <boolean> ;
<identifier> ::= (<letter> | "_")+ (<letter> | <digit> | "_")* ;
<arithmetic-operator> ::= "+" | "-" | "*" | "/" | "%" ;
<comparitive-operator> ::= "<=" | ">=" | "==" | "!=" | ">" | "<" ;
<string> ::= "'" <string-character>* "'" ;
<string-character> ::= <letter> | <number> | <special-character> | <escape-sequence> ;
<special-character> ::= "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "-" | "_" | "=" | "+" | "[" | "]" | "{" | "}" | "|" | "\"" | ";" | ":" | "?" | "." | "," | "<" | ">" | "`" | "~" ;
<escape-sequence> ::= "\" ("n" | "r" | "\'" | "\") ;
<number> ::= <digit>+ | <digit>+ "." <digit>+ ;
<boolean> ::= "true" | "false" ;
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ;
<letter> ::= <lowercase-letter> | <uppercase-letter> ;
<uppercase-letter> ::= "A" | "B" | ... | "Z" ;
<lowercase-letter> ::= "a" | "b" | ... | "z" ;