-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathird.sprut
418 lines (336 loc) · 13.8 KB
/
ird.sprut
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/*
FILE NAME: ird.sprut
Copyright (C) 1997-2016 Vladimir Makarov.
Written by Vladimir Makarov <[email protected]>
This file is part of the tool NONA.
This is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
TITLE: Internal representation description for NONA (code
selector description translator)
DESCRIPTION: This file describes internal representation
description for NONA (code selector description
translator). SPRUT generates standard procedural
interface of NONA internal representation,
i.e. definitions of types, macros, variables,
functions for work with internal representation of
NONA.
*/
%import {
#include "objstack.h"
#include "position.h"
/* Definitions of predefined types: */
typedef int integer_t;
typedef int bool_t;
typedef char *string_t;
}
%export {
/* These macros for storage management of NONA internal representation: */
/* Start work with the storage manager -- see NONA documentation. */
#define IR_START_ALLOC() OS_CREATE (irp, 0)
/* Finish work with the storage manager -- see NONA documentation. */
#define IR_STOP_ALLOC() OS_DELETE (irp)
/* Allocate storage for internal representation of given size
-- see NONA documentation. */
#define IR_ALLOC(ptr, size, ptr_type)\
do {\
OS_TOP_EXPAND (irp, size); ptr = (ptr_type) OS_TOP_BEGIN (irp);\
OS_TOP_FINISH (irp);\
} while (0);
/* Free storage of internal representation of given size -- see NONA
documentation. */
#define IR_FREE(ptr, size)
/* These macros are analogous to ones of package `object-stack'
worked with storage of NONA internal representation: */
/* Start new internal representation object -- see also package
`object-stack'. */
#define IR_TOP_FINISH() OS_TOP_FINISH (irp)
/* Nullify current internal representation object -- see also package
`object-stack'. */
#define IR_TOP_NULLIFY() OS_TOP_NULLIFY (irp)
/* Shorten current internal representation object on given number bytes -- see
also package `object-stack'. */
#define IR_TOP_SHORTEN(length) OS_TOP_SHORTEN (irp, length)
/* Return start address of current internal representation object -- see also
package `object-stack'. */
#define IR_TOP_BEGIN() OS_TOP_BEGIN (irp)
/* Return length of current internal representation object in bytes -- see
also package `object-stack'. */
#define IR_TOP_LENGTH() OS_TOP_LENGTH (irp)
/* Add byte to the end of current internal representation object -- see also
package `object-stack'. */
#define IR_TOP_ADD_BYTE(b) OS_TOP_ADD_BYTE (irp, b)
/* Add string to the end of current internal representation object -- see also
package `object-stack'. */
#define IR_TOP_ADD_STRING(str) OS_TOP_ADD_STRING (irp, str)
/* Add memory of given length to the end of current internal representation
object -- see also package `object-stack'. */
#define IR_TOP_ADD_MEMORY(mem, length) OS_TOP_ADD_MEMORY (irp, mem, length)
extern os_t irp;
}
%local {
/* All internal representation storage is implemented by object stack. See
package `object-stack'. */
os_t irp;
}
%type integer_t bool_t string_t position_t
%%
%abstract
node :: %root
%skeleton
/* Start source position of object represented by given node. */
position : position_t
;
/****** All fields of the following fields are defined by NONA scanner. ******/
/* It describes any identifier occurrence. */
identifier :: node
%skeleton
identifier_itself : string_t
/* The following field forms various list of identifier:
in terminal declaration
in commutative declaration
in type declaration */
next_identifier : identifier
;
/* It describes code insertion, i.e. C code in `{' and `}'. */
code_insertion :: node
%skeleton
/* Surrounding '{' and '}' are absent here. Remember that
constructions `$...' will be changed only during code selector
description generation. */
code_insertion_itself : string_t
;
/* It describes expression, i.e. C code in `[' and `]'. */
expression :: node
%skeleton
/* Surrounding '[' and ']' are absent here. Remember that constructions
`$' & `$$' will be changed only during code selector description
generation. */
expression_itself : string_t
;
/****** All fields of the following fields are defined by NONA parser. ******/
%abstract
declaration :: node
%skeleton
/* Arc to node representing next textually declaration. */
next_declaration : declaration
;
%abstract
identifier_declaration :: declaration
%skeleton
identifier_list : identifier
/* The following field can not be NULL for type declaration. */
type : identifier
;
term_declaration :: identifier_declaration
/* Field `position' of given node type is defined by position of
corresponding keyword `%term'. */
;
commutative_declaration :: identifier_declaration
/* Field `position' of given node type is defined by position of
corresponding keyword `%commutative'. */
;
type_declaration :: identifier_declaration
/* Field `position' of given node type is defined by position of
corresponding keyword `%term'. */
%skeleton
[!IS_NULL ($)] /* constraint for field `type'. */
;
%abstract
code :: declaration
/* Field `position' of given node type is defined by position of
corresponding code insertion. */
%skeleton
/* Arc to node which represents corresponding code insertion. */
code_itself : code_insertion
;
/* It describes local code, i.e. construction `%local {...}'. All
fields are defined before semantic analysis of NONA. */
local_code :: code
/* Field `position' of given node type is defined by position of
corresponding keyword `%local'. */
;
/* It describes import code, i.e. construction `%import {...}'. All
fields are defined before semantic analysis of NONA. */
import_code :: code
/* Field `position' of given node type is defined by position of
corresponding keyword `%import'. */
;
/* It describes export code, i.e. construction `%export {...}'. All
fields are defined before semantic analysis of NONA. */
export_code :: code
/* Field `position' of given node type is defined by position of
corresponding keyword `%export'. */
;
/* It describes union code, i.e. construction `%union {...}'. All
fields are defined before semantic analysis of NONA. */
union_code :: code
/* Field `position' of given node type is defined by position of
corresponding keyword `%union'. */
;
rule :: node
/* Field `position' of given node type is defined by position of
the nonterminal identifier in the left hand side of the rule. */
%skeleton
nonterm_identifier : identifier [!IS_NULL ($)]
pattern : pattern [!IS_NULL ($)]
optional_cost : expression
optional_constraint : expression
optional_action : code_insertion
/* The following field forms list of all code selector description
rules. */
next_rule : rule
;
/* It describes pattern. All fields are defined by NONA parser. */
pattern :: node
/* Field `position' of given node type is defined by position of
the first terminal or nonterminal identifier. */
%skeleton
/* Terminal or nonterminal. */
identifier : identifier [!IS_NULL ($)]
/* NULL if pattern only consists of terminal or
nonterminal (chain rule). */
pattern_list : pattern
/* The following field forms list of patterns in tree pattern. */
next_pattern : pattern
;
/* It describes additional code. All fields are defined by NONA scanner. */
additional_code :: node
%skeleton
additional_code_itself : string_t
;
description :: node
/* Field `position' of given node type is defined by position of
the first description token. */
%skeleton
declaration_list : declaration
/* May be NULL because of syntax errors. */
rule_list : rule
additional_code : additional_code [!IS_NULL ($)]
;
/****** All fields of the following fields are defined by NONA analyzer. *****/
%abstract
single_declaration :: node
%skeleton
/* The first terminal (or nonterminal) identifier occurence which declared
the identifier (in constructions `%term', `%commutative', or in
left hand side of a rule. */
identifier : identifier [!IS_NULL ($)]
next_single_declaration : single_declaration
type : identifier
;
single_term_declaration :: single_declaration
/* Field `position' of given node type is defined by position of
the first terminal identifier occurence which declared the terminal
(in construction `%term' or `%commutative'. */
%skeleton
/* Flag of that the operation designated by the terminal is commutative. */
commutative_flag : bool_t
/* The position of the first occurence of the terminal in rules.
If the terminal is not used the value is `no_position'. */
first_position_in_rules : position_t
/* All rules in which the first terminal in the right hand side is
given terminal. The value of the following field is the last such rule.
The list of such rules is cyclic. */
term_rule_list : rule
/* Arity of the terminal. Undefined value is -1 (when the terminal
is not used). */
arity : integer_t
;
single_nonterm_declaration :: single_declaration
%skeleton
/* The following field value is length of the nonterminal rule list. */
number_of_nonterminal_rules : integer_t
/* All rules in which the nonterminal is in the left hand side.
The value of the following field is the last such rule.
The list of such rules is cyclic. */
nonterm_rule_list : rule [!IS_NULL ($)]
/* All rules in which only the nonterminal is in the right hand side.
The value of the following field is the last such rule.
The list of such rules is cyclic. */
chain_rule_list : rule
/* The value of the following field is TRUE if the nonterminal can
derive tree with only terminal leaves. The initial value is to
be FALSE. */
derivability_flag : bool_t
/* The following field is used to implement traversing or rules.
The value is number of the most recent traversing rules with
given nonterminal in the left hand side. The initial value is to
be 0. */
traverse_number : integer_t
;
rule
%other
/* Flag of that this rule is new because of commutative operators in the
rule. */
new_commutative_rule_flag : bool_t
/* The number of given rule in all description (1, 2, ...). */
rule_number : integer_t
/* The number (1, 2, ... ) of given rule in rules of nonterminal which
is in the left hand side. */
nonterm_rule_number : integer_t
/* The next rule in which the nonterminal of given rule is
in the left hand side. */
next_nonterm_rule : rule [!IS_NULL ($)]
/* The next rule in which only the nonterminal is in the right
hand side. */
next_chain_rule : rule
/* All patterns of the rule in textual order. The value of the following
field is the last such pattern. The list of such patterns is cyclic.
The identifier of the first pattern of the list corresponds to `$1',
the one of the second -- `$2' and so on. */
textual_pattern_list : pattern [!IS_NULL ($)]
/* Declaration corresponding to nonterminal in the left hand side.
The value may be NULL iff terminal is in the left hand side. */
single_nonterm_declaration : single_nonterm_declaration
/* The next rule in which the first terminal of given rule is the same. */
next_term_rule : rule
;
pattern
%other
/* The number of given pattern in rule (1, 2, ...). This number is
number after `$' for given pattern. The ordinal number in the textual
pattern list is the same as ordinal number iff corresponding number is
not created because of commutativity of an operator. */
original_number : integer_t
/* Flag of that given commutative operator has been processed. The field
is used during creation new rules because of commuatative operator. */
commutative_process_flag : bool_t
/* Declaration corresponding to identifier in the pattern.
The following field value may be NULL for undeclared identifier. */
single_declaration : single_declaration
/* See comments for field `textual_pattern_list' in node type `rule'. */
next_textual_pattern : pattern [!IS_NULL ($)]
/* Number of given nonterminal pattern (1, 2, ...)
in textual pattern list. Defined only if identifier of given
pattern is nonterminal.*/
textual_nonterminal_pattern_number : integer_t
/* Pattern in which given pattern is immediately placed.
NULL for uppest pattern in a rule. */
father : pattern
;
description
%other
/* The value of the following field is the last single declaration.
The single declaration list is cyclic. */
single_declaration_list : single_declaration
/* Number of nonterminals in given description (more correctly number
of nonterminals in the single declaration list). */
number_of_nonterminals : integer_t
/* Max number of nonterminals in patterns of rules. */
max_number_of_rule_nonterminals : integer_t
;
/*
Local Variables:
mode:c
End:
*/