common.anubis
6.96 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
*Project* Anubis
*Title* Common Stuff for the Anubis Parser Generator.
*Copyright* Copyright (c) Alain Proute' 2006.
*Author* Alain Proute'
*Created* March 2006
*Revised* March 2006
*Overview*
This file contains the public types and definitions which are common to the several
parts of the Anubis Parser Generator (APG).
*Public*
*Name* APG_Error
*Description*
This type gathers all the sorts of errors which may occur during execution of the
Anubis parser Generator.
public type APG_Error:
unexpected_end_of_input (Int32 line),
no_parser_name (Int32 line),
keyword_was_expected (Int32 line),
unknown_declaration_keyword (Int32 line, String keyword),
type_description_expected (Int32 line),
incorrect_symbol_value (Int32 line),
symbol_expected (Int32 line),
colon_expected (Int32 line),
incorrect_rule_precedence (Int32 line),
misclosed_rule_precedence (Int32 line),
incorrect_end_of_rule (Int32 line),
bad_end_of_precedence_declaration (Int32 line),
bad_end_of_type_declaration (Int32 line).
*Name* en_print
*Description* The function `en_print` prints in English a message of type `APG_Error`
on the standard output.
public define One
en_print
(
APG_Error e
).
*Name* APG_Grammar
*Description*
This is the type of (abstract) grammars. An object of this type is produced by the
function `read_APG_grammar` (see `read_grammar.anubis`), and given as an argument to
the function `make_APG_automaton` (see `make_automaton.anubis`). This type is opaque.
public type APG_Grammar:...
*Name* print_grammar
*Description*
This function prints a grammar (of type `APG_Grammar`) on the standard output. The
preambule and postambule are not printed.
public define One
print_grammar
(
APG_Grammar g
).
*Name* APG_Automaton:
This type represents abstract automatons as they are constructed by the function
`make_APG_automaton` (see `make_automaton.anubis`). This is an opaque type.
public type APG_Automaton:...
*Private*
read tools/basis.anubis
public type APG_Precedence_Dec:
left (List(String) symbol_names),
right (List(String) symbol_names),
non_assoc (List(String) symbol_names).
public type APG_Type_Dec:
type_dec (String type,
List(String) symbol_names).
public type APG_Symbol_Value:
symbol_value (String name,
Maybe(String) value).
public type APG_Grammar_Rule:
grammar_rule (Int32 id, // the grammar reader generates numbers
APG_Symbol_Value head,
List(APG_Symbol_Value) body,
Maybe(String) precedence).
public type APG_Grammar:
grammar (String preambule,
String parser_name,
List(APG_Precedence_Dec) precedence_declarations,
List(APG_Type_Dec) type_declarations,
List(APG_Grammar_Rule) grammar_rules,
String postambule).
public type APG_Automaton:
.
public define One
en_print
(
APG_Error e
) =
if e is
{
unexpected_end_of_input(Int32 line) then
print(integer_to_string(line)+": Unexpected end of input.\n"),
no_parser_name(Int32 line) then
print(integer_to_string(line)+": No parser name.\n"),
keyword_was_expected(Int32 line) then
print(integer_to_string(line)+": Keyword was expected.\n"),
unknown_declaration_keyword(Int32 line,String keyword) then
print(integer_to_string(line)+": Unknown declaration keyword '"+keyword+"'.\n"),
type_description_expected(Int32 line) then
print(integer_to_string(line)+": Type description expected.\n"),
incorrect_symbol_value(Int32 line) then
print(integer_to_string(line)+": Incorrect symbol value.\n"),
symbol_expected(Int32 line) then
print(integer_to_string(line)+": Symbol expected.\n"),
colon_expected(Int32 line) then
print(integer_to_string(line)+": Colon expected.\n"),
incorrect_rule_precedence(Int32 line) then
print(integer_to_string(line)+": Incorrect rule precedence.\n"),
misclosed_rule_precedence(Int32 line) then
print(integer_to_string(line)+": Misclosed rule precedence.\n"),
incorrect_end_of_rule(Int32 line) then
print(integer_to_string(line)+": Incorrect end of rule.\n"),
bad_end_of_precedence_declaration(line) then
print(integer_to_string(line)+": Incorrect end of precedence declaration.\n"),
bad_end_of_type_declaration(line) then
print(integer_to_string(line)+": Incorrect end of type declaration.\n"),
}.
define One
print
(
APG_Precedence_Dec d
) =
if d is
{
left(names) then map_forget((String s) |-> print("left "+s+"\n"),names),
right(names) then map_forget((String s) |-> print("right "+s+"\n"),names),
non_assoc(names) then map_forget((String s) |-> print("non_assoc "+s+"\n"),names)
}.
define One
print
(
APG_Type_Dec d
) =
if d is type_dec(type,names) then
map_forget((String s) |-> print(type+" "+s+"\n"),names).
define One
print
(
APG_Symbol_Value sv
) =
if sv is symbol_value(name,mb_value)
then print(name+" "+ if mb_value is
{
failure then "",
success(value) then "{"+value+"} "
}).
define One
print
(
APG_Grammar_Rule r
) =
if r is grammar_rule(id,head,body,prec) then
print("["+id+"] ");
print(head);
print(": ");
map_forget(print,body);
print("\n").
public define One
print_grammar
(
APG_Grammar g
) =
if g is grammar(preambule,
parser_name,
precedence_declarations,
type_declarations,
grammar_rules,
postambule) then
print("Parser name: "+parser_name+"\n");
map_forget(print,precedence_declarations);
map_forget(print,type_declarations);
map_forget(print,grammar_rules).