Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/tendra5-amd64/src/utilities/lexi/syntax.act – Rev 5

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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 unit.
13
*/
14
 
15
unit -> read_lex ;
16
 
17
 
18
/*
19
    TYPE MAPPINGS
20
 
21
    These mappings give the correspondences between syntax types and
22
    C types.
23
*/
24
 
25
BOOL -> int ;
26
CHARACTERS -> SID_CHARS ;
27
IDENTIFIER -> SID_STRING ;
28
STRING -> SID_STRING ;
29
 
30
%header% @{
31
/*
32
    		 Crown Copyright (c) 1997
33
 
34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
49
 
50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
53
 
54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
#include "config.h"
62
#include "char.h"
63
#include "error.h"
64
#include "lex.h"
65
#include "syntax.h"
66
#include "xalloc.h"
67
 
68
 
69
/*
70
    PARSER TYPES
71
 
72
    These types give the implementation of the types used in the syntax.
73
*/
74
 
75
typedef letter *SID_CHARS ;
76
typedef char *SID_STRING ;
77
 
78
 
79
/*
80
    SID IDENTIFIER PREFIX
81
 
82
    This string is added to the start of each sid identifier.
83
*/
84
 
85
char *sid_prefix = "lex_" ;
86
 
87
 
88
/*
89
    CURRENT CONDITIONAL
90
 
91
    This variable is used to record the current conditional.
92
*/
93
 
94
static char *crt_cond = NULL ;
95
 
96
 
97
/*
98
    COMPILATION MODE
99
 
100
    We allow unreached code in the automatically generated sections.
101
*/
102
 
103
#if FS_TENDRA
104
#pragma TenDRA begin
105
#ifndef OLD_PRODUCER
106
#pragma TenDRA unreachable code allow
107
#endif
108
#endif
109
 
110
 
111
@}, @{
112
/*
113
    		 Crown Copyright (c) 1997
114
 
115
    This TenDRA(r) Computer Program is subject to Copyright
116
    owned by the United Kingdom Secretary of State for Defence
117
    acting through the Defence Evaluation and Research Agency
118
    (DERA).  It is made available to Recipients with a
119
    royalty-free licence for its use, reproduction, transfer
120
    to other parties and amendment for any purpose not excluding
121
    product development provided that any such use et cetera
122
    shall be deemed to be acceptance of the following conditions:-
123
 
124
        (1) Its Recipients shall ensure that this Notice is
125
        reproduced upon any copies or amended versions of it;
126
 
127
        (2) Any amended version of it shall be clearly marked to
128
        show both the nature of and the organisation responsible
129
        for the relevant amendment or amendments;
130
 
131
        (3) Its onward transfer from a recipient to another
132
        party shall be deemed to be that party's acceptance of
133
        these conditions;
134
 
135
        (4) DERA gives no warranty or assurance as to its
136
        quality or suitability for any purpose and DERA accepts
137
        no liability whatsoever in relation to any use to which
138
        it may be put.
139
*/
140
 
141
 
142
#ifndef SYNTAX_INCLUDED
143
#define SYNTAX_INCLUDED
144
 
145
extern char *sid_prefix ;
146
 
147
@};
148
 
149
 
150
%terminals%
151
 
152
 
153
/*
154
    IDENTIFIER TERMINAL
155
 
156
    This action gives the terminal for identifiers.  The identifier text
157
    is built up in token_buff by the lexical routines.
158
*/
159
 
160
identifier : () -> ( i : IDENTIFIER ) = @{
161
    @i = xstrcpy ( token_buff ) ;
162
@} ;
163
 
164
 
165
/*
166
    SID IDENTIFIER TERMINAL
167
 
168
    This action gives the terminal for sid-style identifiers.  The
169
    identifier text is built up in token_buff by the lexical routines.
170
*/
171
 
172
sid-identifier : () -> ( i : IDENTIFIER ) = @{
173
    int n ;
174
    char *s ;
175
    char buff [1000] ;
176
    strcpy_v ( buff, sid_prefix ) ;
177
    n = ( int ) strlen ( buff ) ;
178
    for ( s = token_buff ; *s ; s++ ) {
179
	if ( *s == '-' ) {
180
	    buff [ n++ ] = '_' ;
181
	    buff [ n++ ] = 'H' ;
182
	} else if ( *s == '_' ) {
183
	    buff [ n++ ] = '_' ;
184
	    buff [ n++ ] = '_' ;
185
	} else {
186
	    buff [ n++ ] = *s ;
187
	}
188
	if ( n >= 900 ) {
189
	    error ( ERROR_SERIOUS, "Identifier too long" ) ;
190
	    break ;
191
	}
192
    }
193
    buff [n] = 0 ;
194
    @i = xstrcpy ( buff ) ;
195
@} ;
196
 
197
 
198
/*
199
    STRING TERMINAL
200
 
201
    This action gives the terminal for strings.  The string text is built
202
    up in token_buff by the lexical routines.
203
*/
204
 
205
string : () -> ( s : STRING ) = @{
206
    @s = xstrcpy ( token_buff ) ;
207
@} ;
208
 
209
 
210
/*
211
    SPECIAL STRING TERMINALS
212
 
213
    These actions give a number of special strings.
214
*/
215
 
216
upper : () -> ( s : STRING ) =	@{ @s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; @} ;
217
lower : () -> ( s : STRING ) =	@{ @s = "abcdefghijklmnopqrstuvwxyz" ; @} ;
218
digit : () -> ( s : STRING ) =	@{ @s = "0123456789" ; @} ;
219
 
220
 
221
%actions%
222
 
223
 
224
/*
225
    CONCATENATE TWO STRINGS
226
 
227
    This action concatenates two strings.
228
*/
229
 
230
<string-concat> : ( a : STRING, b : STRING ) -> ( s : STRING ) = @{
231
    @s = xstrcat ( @a, @b ) ;
232
@} ;
233
 
234
 
235
/*
236
    CREATE A CHARACTER STRING
237
 
238
    This action maps an input string into its internal representation
239
    as an array of character codes.
240
*/
241
 
242
<make-chars> : ( s : STRING ) -> ( c : CHARACTERS ) = @{
243
    @c = make_string ( @s ) ;
244
@} ;
245
 
246
 
247
/*
248
    SET WHITE SPACE VARIABLE
249
 
250
    This action sets the white space variable to the given array of
251
    characters.  There is a check to make sure that it has not already
252
    been set.
253
*/
254
 
255
<make-white> : ( s : CHARACTERS ) -> () = @{
256
    if ( white_space ) {
257
	error ( ERROR_SERIOUS, "White space group already defined" ) ;
258
    }
259
    white_space = @s ;
260
@} ;
261
 
262
 
263
/*
264
    CREATE A CHARACTER GROUP
265
 
266
    This action defines the character group i to be s.
267
*/
268
 
269
<make-group> : ( i : IDENTIFIER, s : CHARACTERS ) -> () = @{
270
    make_group ( @i, @s ) ;
271
@} ;
272
 
273
 
274
/*
275
    CREATE A PRE-PASS MAPPING
276
 
277
    This action creates a pre-pass mapping from s to t.
278
*/
279
 
280
<make-trigraph> : ( s : CHARACTERS, t : STRING ) -> () = @{
281
    char *data [3] ;
282
    data [0] = @t ;
283
    data [1] = NULL ;
284
    data [2] = crt_cond ;
285
    add_char ( pre_pass, @s, data ) ;
286
@} ;
287
 
288
 
289
/*
290
    CREATE A MAIN-PASS MAPPING
291
 
292
    This action creates a main-pass mapping from s to the lexical token i.
293
*/
294
 
295
<make-token> : ( s : CHARACTERS, i : IDENTIFIER, b : BOOL ) -> () = @{
296
    char *data [3] ;
297
    data [0] = @i ;
298
    data [1] = ( @b ? "()" : NULL ) ;
299
    data [2] = crt_cond ;
300
    add_char ( main_pass, @s, data ) ;
301
@} ;
302
 
303
 
304
/*
305
    CREATE A KEYWORD
306
 
307
    This action creates a keyword called s.
308
*/
309
 
310
<make-keyword> : ( s : STRING, i : IDENTIFIER, b : BOOL ) -> () = @{
311
    char *data [3] ;
312
    data [0] = @i ;
313
    data [1] = ( @b ? "()" : NULL ) ;
314
    data [2] = crt_cond ;
315
    add_keyword ( @s, data ) ;
316
@} ;
317
 
318
 
319
/*
320
    ADD A CONDITION
321
 
322
    This action adds i to the current condition.
323
*/
324
 
325
<add-condition> : ( i : IDENTIFIER ) -> () = @{
326
    if ( crt_cond ) {
327
	crt_cond = xstrcat ( crt_cond, xstrcat ( " && ", @i ) ) ;
328
    } else {
329
	crt_cond = @i ;
330
    }
331
@} ;
332
 
333
 
334
/*
335
    COMPLEMENT CONDITION
336
 
337
    This action complements the current condition.
338
*/
339
 
340
<compl-condition> : () -> () = @{
341
    if ( crt_cond ) {
342
	if ( strchr ( crt_cond, '&' ) ) {
343
	    crt_cond = xstrcat ( xstrcat ( "!( ", crt_cond ), " )" ) ;
344
	} else {
345
	    crt_cond = xstrcat ( "!", crt_cond ) ;
346
	}
347
    }
348
@} ;
349
 
350
 
351
/*
352
    GET CONDITION
353
 
354
    This action gets the current condition.
355
*/
356
 
357
<get-condition> : () -> ( i : IDENTIFIER ) = @{
358
    @i = crt_cond ;
359
@} ;
360
 
361
 
362
/*
363
    SET CONDITION
364
 
365
    This action sets the current condition.
366
*/
367
 
368
<set-condition> : ( i : IDENTIFIER ) -> () = @{
369
    crt_cond = @i ;
370
@} ;
371
 
372
 
373
/*
374
    BOOLEANS
375
 
376
    These actions give the booleans true and false.
377
*/
378
 
379
<true> : () -> ( b : BOOL ) =	@{ @b = 1 ; @} ;
380
<false> : () -> ( b : BOOL ) =	@{ @b = 0 ; @} ;
381
 
382
 
383
/*
384
    SYNTAX ERROR
385
 
386
    This action reports a syntax error.
387
*/
388
 
389
<syntax-error> : () -> () = @{
390
    error ( ERROR_SERIOUS, "Syntax error" ) ;
391
@} ;
392
 
393
 
394
%trailer% @{
395
@}, @{
396
#endif
397
@} ;