blob: 3369c15fdb4958a56e62206be79e20f064487a68 (
plain)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
comments
'#
end comments
tokens
union "\[[(\\\c)#\]]*\]"
end tokens
compounds
'%% '%%{ '}%% '== ':= '-> '<> '>= '<= '=>
'|* '*|
'>! '<! '$! '%! '@! '<>!
'>/ '</ '$/ '%/ '@/ '<>/
end compounds
keys
'int 'bool 'true 'false 'char 'ptr
'if 'else 'printi 'prints 'printb 'print_token
'fc 'fpc 'fbreak 'fgoto 'fcall 'fret 'fhold 'fexec
'machine 'alphtype 'action
'first_token_char
end keys
define lang_indep
[al_statements]
'%% [NL]
[al_statements]
[ragel_def]
end define
define ragel_def
'%%{ [NL] [IN]
[ragel_program]
[EX] '}%% [NL]
end define
define ragel_program
[repeat statement]
end define
define statement
[machine_stmt]
| [alphtype_stmt]
| [action_stmt]
| [cond_action_stmt]
| [machine_def]
| [machine_inst]
end define
define machine_stmt
'machine [id] '; [NL]
end define
define alphtype_stmt
'alphtype [repeat id] '; [NL]
end define
define action_stmt
'action [id] [al_host_block]
end define
define cond_action_stmt
'action [id] '{ [al_expr] '} [NL]
end define
define al_statements
[repeat action_lang_stmt]
end define
define action_lang_stmt
[al_ragel_stmt]
| [al_variable_decl]
| [al_expr_stmt]
| [al_if_stmt]
| [al_print_stmt]
| '{ [al_statements] '}
end define
define al_print_stmt
[print_cmd] [al_expr] '; [NL]
| 'print_token '; [NL]
end define
define print_cmd
'printi | 'prints | 'printb
end define
define al_variable_decl
[al_type_decl] [id] [opt union] '; [NL]
end define
define al_array_decl
'[ [number] ']
end define
define al_type_decl
'int | 'bool | 'char | 'ptr
end define
define al_expr_stmt
[al_expr] '; [NL]
end define
define al_expr
[al_term] [repeat al_expr_extend]
end define
define al_expr_extend
[al_expr_op] [al_term]
end define
define al_expr_op
'= | '+ | '- | '* | '/ | '== | '<= | '>= | '< | '>
end define
define al_term
[al_term_base] [opt union]
end define
define al_term_base
[id]
| [SPOFF] [id] '( [SPON] [al_expr] ')
| [opt al_sign] [number]
| [stringlit]
| [charlit]
| 'fc
| 'true
| 'false
| '( [al_expr] ')
| 'first_token_char
end define
define al_sign
'- | '+
end define
define al_if_stmt
'if '( [al_expr] ') [NL] [IN]
[action_lang_stmt] [EX]
[opt al_else]
end define
define al_else
'else [NL] [IN]
[action_lang_stmt] [EX]
end define
define al_ragel_stmt
'fbreak '; [NL]
| 'fhold '; [NL]
| 'fexec [repeat al_expr] '; [NL]
| 'fnext [id] '; [NL]
| 'fgoto [id] '; [NL]
| 'fcall [id] '; [NL]
| 'fnext '* [repeat al_expr] '; [NL]
| 'fgoto '* [repeat al_expr] '; [NL]
| 'fcall '* [repeat al_expr] '; [NL]
| 'fret '; [NL]
end define
define machine_def
[id] '= [machine_expr] '; [NL]
end define
define machine_inst
[id] ':= [machine_expr] '; [NL]
end define
define machine_expr
[repeat machine_expr_item]
end define
define scanner_item
[repeat machine_expr_item] '; [NL]
end define
define machine_expr_item
[action_embed] [al_host_block]
| '|* [repeat scanner_item] '*|
| [not ';] [not '*|] [token]
end define
define al_host_block
'{ [NL] [IN] [al_statements] [EX] '} [NL]
end define
define action_embed
'> | '$ | '@ | '% |
'$! | '=>
end define
|