2 |
7u83 |
1 |
%prefixes%
|
|
|
2 |
|
|
|
3 |
terminal = lex_ ;
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
%maps%
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
/*
|
|
|
10 |
ENTRY POINT
|
|
|
11 |
|
|
|
12 |
The main entry point for the grammar is given by specification.
|
|
|
13 |
*/
|
|
|
14 |
|
|
|
15 |
specification -> read_spec ;
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
/*
|
|
|
19 |
TYPE MAPPINGS
|
|
|
20 |
|
|
|
21 |
These mappings give the correspondences between syntax types and
|
|
|
22 |
C types.
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
NAME -> string ;
|
|
|
26 |
NUMBER -> unsigned ;
|
|
|
27 |
CONS -> CONSTRUCT ;
|
|
|
28 |
LINK -> LINKAGE ;
|
|
|
29 |
PARAM -> PARAMETER ;
|
|
|
30 |
SORT -> SORT ;
|
|
|
31 |
SPEC -> SPECIFICATION ;
|
|
|
32 |
CONS-LIST -> SID_CONS_LIST ;
|
|
|
33 |
LINK-LIST -> SID_LINK_LIST ;
|
|
|
34 |
PARAM-LIST -> SID_PARAM_LIST ;
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
%header% @{
|
|
|
38 |
/*
|
|
|
39 |
Crown Copyright (c) 1997
|
|
|
40 |
|
|
|
41 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
42 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
43 |
acting through the Defence Evaluation and Research Agency
|
|
|
44 |
(DERA). It is made available to Recipients with a
|
|
|
45 |
royalty-free licence for its use, reproduction, transfer
|
|
|
46 |
to other parties and amendment for any purpose not excluding
|
|
|
47 |
product development provided that any such use et cetera
|
|
|
48 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
49 |
|
|
|
50 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
51 |
reproduced upon any copies or amended versions of it;
|
|
|
52 |
|
|
|
53 |
(2) Any amended version of it shall be clearly marked to
|
|
|
54 |
show both the nature of and the organisation responsible
|
|
|
55 |
for the relevant amendment or amendments;
|
|
|
56 |
|
|
|
57 |
(3) Its onward transfer from a recipient to another
|
|
|
58 |
party shall be deemed to be that party's acceptance of
|
|
|
59 |
these conditions;
|
|
|
60 |
|
|
|
61 |
(4) DERA gives no warranty or assurance as to its
|
|
|
62 |
quality or suitability for any purpose and DERA accepts
|
|
|
63 |
no liability whatsoever in relation to any use to which
|
|
|
64 |
it may be put.
|
|
|
65 |
*/
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
#include "config.h"
|
|
|
69 |
#include "tdf.h"
|
|
|
70 |
#include "cmd_ops.h"
|
|
|
71 |
#include "cons_ops.h"
|
|
|
72 |
#include "info_ops.h"
|
|
|
73 |
#include "link_ops.h"
|
|
|
74 |
#include "par_ops.h"
|
|
|
75 |
#include "sort_ops.h"
|
|
|
76 |
#include "spec_ops.h"
|
|
|
77 |
#include "error.h"
|
|
|
78 |
#include "input.h"
|
|
|
79 |
#include "lex.h"
|
|
|
80 |
#include "syntax.h"
|
|
|
81 |
#include "xalloc.h"
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
/*
|
|
|
85 |
LOCAL TYPE ALIASES
|
|
|
86 |
|
|
|
87 |
These definitions give the aliases used for compound types within the
|
|
|
88 |
grammar.
|
|
|
89 |
*/
|
|
|
90 |
|
|
|
91 |
typedef LIST ( CONSTRUCT ) SID_CONS_LIST ;
|
|
|
92 |
typedef LIST ( LINKAGE ) SID_LINK_LIST ;
|
|
|
93 |
typedef LIST ( PARAMETER ) SID_PARAM_LIST ;
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
/*
|
|
|
97 |
COMPILATION MODE
|
|
|
98 |
|
|
|
99 |
We allow unreached code and switch off the variable analysis in the
|
|
|
100 |
automatically generated sections.
|
|
|
101 |
*/
|
|
|
102 |
|
|
|
103 |
#if FS_TENDRA
|
|
|
104 |
#pragma TenDRA begin
|
|
|
105 |
#pragma TenDRA variable analysis off
|
|
|
106 |
#ifndef OLD_PRODUCER
|
|
|
107 |
#pragma TenDRA unreachable code allow
|
|
|
108 |
#endif
|
|
|
109 |
#endif
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
@}, @{
|
|
|
113 |
/*
|
|
|
114 |
Crown Copyright (c) 1997
|
|
|
115 |
|
|
|
116 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
117 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
118 |
acting through the Defence Evaluation and Research Agency
|
|
|
119 |
(DERA). It is made available to Recipients with a
|
|
|
120 |
royalty-free licence for its use, reproduction, transfer
|
|
|
121 |
to other parties and amendment for any purpose not excluding
|
|
|
122 |
product development provided that any such use et cetera
|
|
|
123 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
124 |
|
|
|
125 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
126 |
reproduced upon any copies or amended versions of it;
|
|
|
127 |
|
|
|
128 |
(2) Any amended version of it shall be clearly marked to
|
|
|
129 |
show both the nature of and the organisation responsible
|
|
|
130 |
for the relevant amendment or amendments;
|
|
|
131 |
|
|
|
132 |
(3) Its onward transfer from a recipient to another
|
|
|
133 |
party shall be deemed to be that party's acceptance of
|
|
|
134 |
these conditions;
|
|
|
135 |
|
|
|
136 |
(4) DERA gives no warranty or assurance as to its
|
|
|
137 |
quality or suitability for any purpose and DERA accepts
|
|
|
138 |
no liability whatsoever in relation to any use to which
|
|
|
139 |
it may be put.
|
|
|
140 |
*/
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
#ifndef SYNTAX_INCLUDED
|
|
|
144 |
#define SYNTAX_INCLUDED
|
|
|
145 |
|
|
|
146 |
@};
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
%terminals%
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
/*
|
|
|
153 |
IDENTIFIER TERMINAL
|
|
|
154 |
|
|
|
155 |
This action gives the terminal for identifiers. The identifier text
|
|
|
156 |
is built up in token_buff by the lexical routines.
|
|
|
157 |
*/
|
|
|
158 |
|
|
|
159 |
name : () -> ( n : NAME ) = @{
|
|
|
160 |
@n = xstrcpy ( token_buff ) ;
|
|
|
161 |
@} ;
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
/*
|
|
|
165 |
NUMBER TERMINAL
|
|
|
166 |
|
|
|
167 |
This action gives the terminal for numbers. The number value is built
|
|
|
168 |
up in token_value by the lexical routines.
|
|
|
169 |
*/
|
|
|
170 |
|
|
|
171 |
number : () -> ( n : NUMBER ) = @{
|
|
|
172 |
@n = token_value ;
|
|
|
173 |
@} ;
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
%actions%
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
/*
|
|
|
180 |
KEYWORD NAME
|
|
|
181 |
|
|
|
182 |
This action is used to map a keyword onto an identifier name. At the
|
|
|
183 |
point at which it is called the keyword text is still in token_buff.
|
|
|
184 |
*/
|
|
|
185 |
|
|
|
186 |
<keyword_name> : () -> ( n : NAME ) = @{
|
|
|
187 |
@n = xstrcpy ( token_buff ) ;
|
|
|
188 |
@} ;
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
/*
|
|
|
192 |
PARAMETER ACTIONS
|
|
|
193 |
|
|
|
194 |
These actions are used in the construction of parameters.
|
|
|
195 |
*/
|
|
|
196 |
|
|
|
197 |
<make_param> : ( n : NAME, s : SORT ) -> ( a : PARAM ) = @{
|
|
|
198 |
int intro = 0 ;
|
|
|
199 |
if ( ends_in ( @n, "_intro" ) ) intro = 1 ;
|
|
|
200 |
MAKE_par_basic ( @n, @s, 0, 0, intro, @a ) ;
|
|
|
201 |
@} ;
|
|
|
202 |
|
|
|
203 |
<null_param> : () -> ( p : PARAM-LIST ) = @{
|
|
|
204 |
@p = NULL_list ( PARAMETER ) ;
|
|
|
205 |
@} ;
|
|
|
206 |
|
|
|
207 |
<cons_param> : ( a : PARAM, q : PARAM-LIST ) -> ( p : PARAM-LIST ) = @{
|
|
|
208 |
CONS_par ( @a, @q, @p ) ;
|
|
|
209 |
@} ;
|
|
|
210 |
|
|
|
211 |
<set_break> : ( c : CONS, a : NUMBER ) -> () = @{
|
|
|
212 |
PARAMETER p = find_param ( @c, @a ) ;
|
|
|
213 |
if ( !IS_NULL_par ( p ) ) COPY_int ( par_brk ( p ), 1 ) ;
|
|
|
214 |
@} ;
|
|
|
215 |
|
|
|
216 |
<set_boundary> : ( c : CONS, a : NUMBER ) -> () = @{
|
|
|
217 |
PARAMETER p = find_param ( @c, @a ) ;
|
|
|
218 |
if ( !IS_NULL_par ( p ) ) COPY_int ( par_align ( p ), 1 ) ;
|
|
|
219 |
@} ;
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
/*
|
|
|
223 |
CONSTRUCT ACTIONS
|
|
|
224 |
|
|
|
225 |
These actions are used in the construction of constructs.
|
|
|
226 |
*/
|
|
|
227 |
|
|
|
228 |
<make_cons> : ( n : NAME, e : NUMBER, r : SORT, p : PARAM-LIST, s : SORT ) -> ( c : CONS ) = @{
|
|
|
229 |
if ( !EQ_sort ( @r, @s ) ) {
|
|
|
230 |
error ( ERROR_SERIOUS, "Wrong result sort for '%s'", @n ) ;
|
|
|
231 |
}
|
|
|
232 |
@c = make_construct ( @n, @e, @s, @p ) ;
|
|
|
233 |
@} ;
|
|
|
234 |
|
|
|
235 |
<null_cons> : () -> ( p : CONS-LIST ) = @{
|
|
|
236 |
@p = NULL_list ( CONSTRUCT ) ;
|
|
|
237 |
@} ;
|
|
|
238 |
|
|
|
239 |
<cons_cons> : ( c : CONS, q : CONS-LIST ) -> ( p : CONS-LIST ) = @{
|
|
|
240 |
CONS_cons ( @c, @q, @p ) ;
|
|
|
241 |
@} ;
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
/*
|
|
|
245 |
SORT ACTIONS
|
|
|
246 |
|
|
|
247 |
These actions are used in the construction of sorts.
|
|
|
248 |
*/
|
|
|
249 |
|
|
|
250 |
<find_new_sort> : ( n : NAME ) -> ( s : SORT ) = @{
|
|
|
251 |
@s = find_sort ( @n, 1 ) ;
|
|
|
252 |
@} ;
|
|
|
253 |
|
|
|
254 |
<find_old_sort> : ( n : NAME ) -> ( s : SORT ) = @{
|
|
|
255 |
@s = find_sort ( @n, 0 ) ;
|
|
|
256 |
@} ;
|
|
|
257 |
|
|
|
258 |
<make_sort> : ( s : SORT, b : NUMBER, e : NUMBER, p : CONS-LIST ) -> () = @{
|
|
|
259 |
basic_sort ( @s, @b, @e, @p ) ;
|
|
|
260 |
@} ;
|
|
|
261 |
|
|
|
262 |
<make_clist> : ( s : SORT ) -> () = @{
|
|
|
263 |
compound_sort ( @s, "_list", info_clist_tag, '*' ) ;
|
|
|
264 |
@} ;
|
|
|
265 |
|
|
|
266 |
<make_slist> : ( s : SORT ) -> () = @{
|
|
|
267 |
compound_sort ( @s, "_list", info_slist_tag, '%' ) ;
|
|
|
268 |
@} ;
|
|
|
269 |
|
|
|
270 |
<make_option> : ( s : SORT ) -> () = @{
|
|
|
271 |
compound_sort ( @s, "_option", info_option_tag, '?' ) ;
|
|
|
272 |
@} ;
|
|
|
273 |
|
|
|
274 |
<set_edge> : ( s : SORT, c : NAME ) -> () = @{
|
|
|
275 |
set_special ( @s, @c, KIND_edge ) ;
|
|
|
276 |
COPY_int ( sort_edge ( @s ), 1 ) ;
|
|
|
277 |
@} ;
|
|
|
278 |
|
|
|
279 |
|
|
|
280 |
/*
|
|
|
281 |
LINKAGE ACTIONS
|
|
|
282 |
|
|
|
283 |
These actions are used in the construction of linkage items.
|
|
|
284 |
*/
|
|
|
285 |
|
|
|
286 |
<make_edge_link> : ( s : SORT, n : NAME ) -> ( a : LINK ) = @{
|
|
|
287 |
MAKE_link_basic ( @n, @s, @a ) ;
|
|
|
288 |
COPY_string ( sort_link ( @s ), @n ) ;
|
|
|
289 |
@} ;
|
|
|
290 |
|
|
|
291 |
<make_unit_link> : ( s : SORT, n : NAME ) -> ( a : LINK ) = @{
|
|
|
292 |
MAKE_link_basic ( @n, @s, @a ) ;
|
|
|
293 |
COPY_string ( sort_unit ( @s ), @n ) ;
|
|
|
294 |
@} ;
|
|
|
295 |
|
|
|
296 |
<null_link> : () -> ( p : LINK-LIST ) = @{
|
|
|
297 |
@p = NULL_list ( LINKAGE ) ;
|
|
|
298 |
@} ;
|
|
|
299 |
|
|
|
300 |
<cons_link> : ( a : LINK, q : LINK-LIST ) -> ( p : LINK-LIST ) = @{
|
|
|
301 |
CONS_link ( @a, @q, @p ) ;
|
|
|
302 |
@} ;
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
/*
|
|
|
306 |
SPECIFICATION ACTIONS
|
|
|
307 |
|
|
|
308 |
This action is used to define the overall TDF specification.
|
|
|
309 |
*/
|
|
|
310 |
|
|
|
311 |
<make_spec> : ( v1 : NUMBER, v2 : NUMBER, p1 : LINK-LIST, p2 : LINK-LIST ) -> ( spec : SPEC ) = @{
|
|
|
312 |
LIST ( SORT ) p = check_sorts () ;
|
|
|
313 |
LIST ( LINKAGE ) q = foreign_sorts () ;
|
|
|
314 |
MAKE_spec_basic ( @v1, @v2, p, @p1, @p2, q, @spec ) ;
|
|
|
315 |
@} ;
|
|
|
316 |
|
|
|
317 |
<null_spec> : () -> ( spec : SPEC ) = @{
|
|
|
318 |
@spec = NULL_spec ;
|
|
|
319 |
@} ;
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
/*
|
|
|
323 |
SYNTAX ERROR ACTION
|
|
|
324 |
|
|
|
325 |
This action is used to signal a syntax error.
|
|
|
326 |
*/
|
|
|
327 |
|
|
|
328 |
<syntax_error> : () -> () = @{
|
|
|
329 |
error ( ERROR_SERIOUS, "Syntax error" ) ;
|
|
|
330 |
@} ;
|
|
|
331 |
|
|
|
332 |
|
|
|
333 |
%trailer% @{
|
|
|
334 |
@}, @{
|
|
|
335 |
#endif
|
|
|
336 |
@} ;
|