-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgrammar.bnf
103 lines (103 loc) · 5.67 KB
/
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<module> ::= "module" <id> {<declaration>};
<declaration> ::= <open>
| <include>
| <algebraic-type>
| <function>
| <let>
| <alias>
| "#" <inline-cpp> "#";
<include> ::= "include" "(" "\"" <cpp-header> "\"" [{"," "\"" <cpp-header> "\""}] ")"
<open> ::= "open" "(" [<id> {"," <id>}] ")";
<ty-var-dec> ::= <id> ":" "int"
| <id> [":" "*"];
<template-dec> ::= "<" <ty-var-dec> {"," <ty-var-dec>} ">";
<algebraic-type> ::= "type" <id> [<template-dec>] "=" <value-constructor> {"|" <value-constructor>};
<alias> ::= "alias" <id> [<template-dec>] "=" <ty-expr>;
<value-constructor> ::= <id> "(" [<ty-expr> {"," <ty-expr>}] ")";
<let> ::= "let" ["mut"] <id> [":" <ty-expr>] "=" <expr>;
<function> ::= "fun" <id> "(" [["inout"] <id> [":" <ty-expr>] {"," ["inout"] <id> [":" <ty-expr>]}] ")" [":" <ty-expr>] ["where" <ty-expr> ":" <constraint> {"," <ty-expr> ":" <constraint>}] "=" <expr>;
<constraint> ::= "num"
| "int"
| "real"
| "packed"
| "{" [<id> ":" <ty-expr> {"," <id> ":" <ty-expr>}] "}";
<capacity-op> ::= "+" | "-" | "*" | "/";
<declaration-ref> ::= <id> | <module-qualifier>;
<ty-expr> ::= <integer>
| "-" <ty-expr>
| <ty-expr> <capacity-op> <ty-expr>
| <declaration-ref> ["<" <ty-expr> {"," <ty-expr>} ">"]
| ["(" <ty-expr> ")"] "(" [<ty-expr> {"," <ty-expr>}] ")" "->" <ty-expr>
| <ty-expr> "[" <capacity-expr> "]"
| <ty-expr> "ref"
| "inout" <ty-expr>
| "(" <ty-expr> "," <ty-expr> [{"," <ty-expr>}] ")"
| "(" <ty-expr> ")"
| "|" [<id> ":" <ty-expr> {"," <id> ":" <ty-expr>}] "|"
| ["packed"] "{" [<id> ":" <ty-expr> {"," <id> ":" <ty-expr>}] "}"
| "uint8" | "uint16" | "uint32" | "uint64" | "int8" | "int16"
| "int32" | "int64" | "bool" | "unit" | "float" | "double"
| "ptr" | "string" | "rcptr" | "_";
<module-qualifier> ::= <id> ":" <id>;
<expr-list> ::= <expr> {"," <expr>};
<callarg> ::= "inout" <left-assign>
| <expr>;
<callarg-list> ::= <callarg> {"," <callarg>};
<field-assign-list> ::= <id> ":=" <expr> {"," <id> ":=" <expr>};
<assign-op> ::= "=" | "+=" | "-=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=";
<expr> ::= "()" | "true" | "false" | "null" | <integer> | <real> | <float>"f" | <double>"d"
| <integer>"i8" | <unsigned-integer>"u8" | <integer>"i16"
| <unsigned-integer>"u16" | <integer>"i32" | <unsigned-integer>"u32"
| <integer>"i64" | <unsigned-integer>"u64"
| "{" <expr> {<expr>} "}"
| "(" <expr> "," <expr> [{"," <expr>}] ")"
| <expr> "(" [<callarg-list>] ")"
| <declaration-ref>
| <expr> "[" <expr> "]"
| <expr> <binary-op> <expr>
| "if" <expr> <expr> ["else" <expr>]
| "let" <pattern> "=" <expr>
| "var" <id> [":" <ty-expr>]
| <left-assign> <assign-op> <expr>
| "for" <id> [":" <ty-expr>] "in" <expr> ".." <expr> <expr>
| "for" <expr> ";" <expr> ";" <expr> <expr>
| "do" <expr> "while" <expr>
| "while" <expr> <expr>
| <module-qualifier>
| <id>
| <unary-op> <expr>
| <expr> "." <id>
| "(" [<id> [":" <ty-expr>] {"," <id> [":" <ty-expr>]}] ")" [":" <ty-expr>] "=>" <expr>
| "match" <expr> "{" <case-clause> {<case-clause>} "}"
| ["packed"] "{" [<field-assign-list>] "}"
| "[" <expr-list> "]"
| "ref" <expr>
| "#" <inline-cpp> "#"
| <expr> ":" <ty-expr>
| "sizeof" "(" <ty-expr> ")"
| "quit" ["<" <ty-expr> ">"] "(" ")"
| "'" <extended-ascii-string> "'"
| "\"" <extended-ascii-string> "\""
| "(==)" | "(!=)" | "(>=)" | "(>)" | "<=" | "<"
| "(!)" | "(&&)" | "(||)" | "(+)" | "(-)" | "(*)" | "(/)"
<binary-op> ::= "+" | "-" | "*" | "/" | "%" | "&&" | "||" | "&"
| "|" | ">=" | "<=" | ">" | "<" | "==" | "!=" | "<<"
| ">>" | "|>";
<unary-op> ::= "-" | "~" | "!" | "*";
<left-assign> ::= <id>
| <module-qualifier>
| <left-assign> "[" <expr> "]"
| <left-assign> "." <id>
| "*" <expr>;
<case-clause> ::= <pattern> "=>" <expr>;
<pattern> ::= ["mut"] <id> [":" <ty-expr>]
| <integer>
| <real>
| "true"
| "false"
| "_"
| "()"
| "(" <pattern> ")"
| <declaration-ref> "(" [<pattern> {"," <pattern>}] ")"
| "{" [<id> ":=" <pattern> {"," <id> ":=" <pattern>}] "}"
| "(" <pattern> "," <pattern> {"," <pattern>} ")";