-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.ebnf
123 lines (91 loc) · 2.65 KB
/
grammar.ebnf
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
constant = unit
| integer-constant
;
unit = "()"
;
integer-constant = digit-excluding-zero, { digit }
;
digit = "0" | digit-excluding-zero
;
digit-excluding-zero = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
;
identifier = letter, { letter | digit }
;
letter = ? All ASCII alphabetic characters ?
| "_"
;
primary-expr = identifier
| constant
| break-expr
| continue-expr
| "(", expr, ")"
;
postfix-expr = primary-expr
| function-call-expr
;
function-call-expr = identifier, "(", [ expr, { ",", expr }, [","] ], ")" ;
prefix-expr = postfix-expr
| "-", prefix-expr
| "!", prefix-expr
;
product-expr = prefix-expr
| product-expr, "*", prefix-expr
| product-expr, "/", prefix-expr
;
factor-expr = product-expr
| factor-expr, "+", product-expr
| factor-expr, "-", product-expr
;
shift-expr = factor-expr
| shift-expr, "<<", factor-expr
| shift-expr, ">>", factor-expr
;
relational-expr = shift-expr
| relational-expr, "<", shift-expr
| relational-expr, ">", shift-expr
| relational-expr, "<=", shift-expr
| relational-expr, ">=", shift-expr
;
equality-expr = relational-expr
| equality-expr, "==", relational-expr
| equality-expr, "!=", relational-expr
;
assignment-expr = equality-expr
| identifier, "=", assignment-expr
;
statement-expr = equality-expr
| bind-expr
| if-expr
| for-expr
| function-expr
| declaration-expr
;
expr = statement-expr
| expr, ";"
;
bind-expr = identifier, ":=", expr
;
if-expr = "if", expr, "{", expr, "}", [ "else", else-clause ]
;
else-clause = if-expr
| "{", expr, "}"
;
for-expr = "for", expr, "{", { expr }, "}"
;
break-expr = "break", [ expr ]
;
continue-expr = "continue"
;
function-expr = "(", function-parameters, ")", [ "->", type ], "{", { expr }, "}"
;
function-parameters = [ function-parameter, { ",", function-parameter }, [","] ]
;
function-parameter = identifier, ":", type
;
type = "i32"
| "()"
;
declaration = identifier, "::", statement-expr
;
program = declaration, { declaration }
;