-
Notifications
You must be signed in to change notification settings - Fork 1
/
FACT_grammar.txt
167 lines (135 loc) · 3.21 KB
/
FACT_grammar.txt
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
FACT_grammar.txt
The following is FACT's formal grammar, written out and transcribed.
Terminals are enclosed by quotation marks. C escape characters apply.
The 'e' character stands for the empty set.
Obviously this grammar is unfit for a recursive descent parser (it uses
left recursion), but that is beside the point.
/* Lowest precedence. */
assignment -> lor "=" assignment
| lor "+=" assignment
| lor "-=" assignment
| lor "*=" assignment
| lor "/=" assignment
| lor "%=" assignment
| lor
;
lor -> lor "||" land
| land
;
land -> land "&&" equality
| equality
;
equality -> equality "==" comparison
| equality "!=" comparison
| comparison
;
comparison -> comparison "<" E
| comparison ">" E
| comparison "<=" E
| comparison ">=" E
| E
;
E -> E "+" T
| E "-" T
| T
;
T -> T "*" A
| T "/" A
| T "%" A
| A
;
A -> A "(" opt_arg_list ")"
| A "[" assignment "]"
| A ":" unary
| A e
| unary
;
unary -> "-" F
| "+" F
| F
;
F -> "(" paren ")"
| "$" threaded_expression
| VAR opt_def_check
| NUM
| STR
| array_dec
| defin
;
threaded_expression -> "{" stmt_list "}"
| assignment
;
opt_def_check -> "?"
| "??"
| e
;
paren -> func_dec
| "{" stmt_list "}" /* Lambda scopes. */
| assignment
;
opt_arg_list -> "num" VAR arg_list
| "scope" VAR arg_list
| e
;
arg_list -> "," "num" VAR arg_list
| "," "scope" VAR arg_list
| e
;
array_dec -> "[" assignment opt_array_dec "]"
;
opt_array_dec -> "," assignment opt_array_dec
| e
;
defin -> "num" opt_array VAR
| "scope" opt_array VAR
;
opt_array -> opt_array "[" assignment "]"
| e
;
func_dec -> assignment "@" "(" func_opt_arg_dec ")" "{" stmt_list "}"
| "defunc" VAR "(" func_opt_arg_dec ")" "{" stmt_list "}"
;
func_opt_arg_dec -> "scope" VAR func_arg_dec
| "num" VAR func_arg_dec
| VAR "?" func_arg_dec
| e
;
func_arg_dec -> "," "scope" VAR func_arg_dec
| "," "num" VAR func_arg_dec
| "," VAR "?" func_arg_dec
| e
;
stmt -> "{" stmt_list "}"
| assignment ";"
| if_stmt
| while_loop
| for_loop
| sprout_stmt
| func_dec
| "return" assignment ";"
| del VAR ";"
| VAR ":=" assignment ";"
;
stmt_list -> stmt opt_stmt_list
;
opt_stmt_list -> stmt opt_stmt_list
| e
;
if_stmt -> "if" "(" assignment ")" stmt else_clause
;
else_clause -> "else" stmt
| e
;
catch_stmt -> "catch" stmt "handle" stmt
;
const_dec -> "const" VAR "=" assignment
| "const" VAR "(" func_opt_arg_dec ")" "{" stmt_list "}"
;
VAR -> [a-zA-Z_]([a-zA-Z_]|[0-9])*
;
NUM -> 0[xX][a-fA-F0-9]+
| 0[0-9]+
| [0-9]+
| [0-9]*"."[0-9]+
| [0-9]+"."[0-9]*
;