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.sid – 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
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
%types%
32
 
33
/*
34
    TYPES
35
 
36
    There are four types, representing booleans, identifiers, input strings
37
    and strings of character codes.
38
*/
39
 
40
BOOL ;
41
CHARACTERS ;
42
IDENTIFIER ;
43
STRING ;
44
 
45
 
46
%terminals%
47
 
48
/*
49
    TERMINALS
50
 
51
    These terminals give the various terminals identified by the lexical
52
    analysis routines.
53
*/
54
 
55
identifier : () -> ( :IDENTIFIER ) ;
56
sid-identifier : () -> ( :IDENTIFIER ) ;
57
string : () -> ( :STRING ) ;
58
 
59
upper : () -> ( :STRING ) ;
60
lower : () -> ( :STRING ) ;
61
digit : () -> ( :STRING ) ;
62
 
63
group ;
64
keyword ;
65
mapping ;
66
token ;
67
white ;
68
 
69
if ;
70
else ;
71
 
72
open ;
73
close ;
74
open-brace ;
75
close-brace ;
76
 
77
arrow ;
78
eof ;
79
equal ;
80
plus ;
81
semicolon ;
82
!unknown ;
83
 
84
 
85
%productions%
86
 
87
 
88
/*
89
    ACTION DECLARATIONS
90
 
91
    The actions are described in more detail in the action definition
92
    file.
93
*/
94
 
95
<string-concat> : ( :STRING, :STRING ) -> ( :STRING ) ;
96
<make-chars> : ( :STRING ) -> ( :CHARACTERS ) ;
97
<make-white> : ( :CHARACTERS ) -> () ;
98
<make-group> : ( :IDENTIFIER, :CHARACTERS ) -> () ;
99
<make-trigraph> : ( :CHARACTERS, :STRING ) -> () ;
100
<make-token> : ( :CHARACTERS, :IDENTIFIER, :BOOL ) -> () ;
101
<make-keyword> : ( :STRING, :IDENTIFIER, :BOOL ) -> () ;
102
<add-condition> : ( :IDENTIFIER ) -> () ;
103
<compl-condition> : () -> () ;
104
<get-condition> : () -> ( :IDENTIFIER ) ;
105
<set-condition> : ( :IDENTIFIER ) -> () ;
106
<true> : () -> ( :BOOL ) ;
107
<false> : () -> ( :BOOL ) ;
108
<syntax-error> : () -> () ;
109
 
110
 
111
/*
112
    STRINGS
113
 
114
    This action gives the full definition of a string, including special
115
    strings and string concatenation.
116
*/
117
 
118
string-plus : () -> ( s : STRING ) = {
119
	{
120
		a = string ;
121
	    ||	a = upper ;
122
	    ||	a = lower ;
123
	    ||	a = digit ;
124
	} ;
125
	{
126
		s = a ;
127
	    ||	plus ; b = string-plus ; s = <string-concat> ( a, b ) ;
128
	} ;
129
} ;
130
 
131
 
132
/*
133
    CHARACTER STRING
134
 
135
    This action transforms an input string into the internal representation
136
    of arrays of character codes.
137
*/
138
 
139
chars : () -> ( c : CHARACTERS ) = {
140
	s = string-plus ;
141
	c = <make-chars> ( s ) ;
142
} ;
143
 
144
 
145
/*
146
    WHITE SPACE DEFINITION
147
 
148
    This action defines the set of white space characters.
149
*/
150
 
151
white-defn : () -> () = {
152
	group ; white ; equal ; s = chars ;
153
	<make-white> ( s ) ;
154
} ;
155
 
156
 
157
/*
158
    CHARACTER GROUP DEFINITION
159
 
160
    This action assigns a name to a group of characters.
161
*/
162
 
163
group-defn : () -> () = {
164
	group ; i = identifier ; equal ; s = chars ;
165
	<make-group> ( i, s ) ;
166
} ;
167
 
168
 
169
/*
170
    RETURN ARGUMENTS
171
 
172
    This action deals with the optional arguments which may be used in
173
    a token definition.
174
*/
175
 
176
args : () -> ( a : BOOL ) = {
177
	a = <false> ;
178
    ||	open ; close ; a = <true> ;
179
} ;
180
 
181
 
182
/*
183
    TRIGRAPH DEFINITION
184
 
185
    This action defines a lexical pre-pass mapping (for example, trigraphs
186
    in ANSI C).
187
*/
188
 
189
trigraph-defn : () -> () = {
190
	mapping ; s = chars ; arrow ; t = string-plus ;
191
	<make-trigraph> ( s, t ) ;
192
} ;
193
 
194
 
195
/*
196
    TOKEN DEFINITION
197
 
198
    This action defines a lexical main-pass mapping (for example, operators
199
    and keywords).
200
*/
201
 
202
token-defn : () -> () = {
203
	token ; s = chars ; arrow ;
204
	{
205
		i = identifier ; a = args ;
206
	    ||	i = sid-identifier ; a = <false> ;
207
	} ;
208
	<make-token> ( s, i, a ) ;
209
} ;
210
 
211
 
212
/*
213
    KEYWORD DEFINITION
214
 
215
    This action defines a keyword.
216
*/
217
 
218
keyword-defn : () -> () = {
219
	keyword ; s = string ; arrow ;
220
	{
221
		i = identifier ; a = args ;
222
	    ||	i = sid-identifier ; a = <false> ;
223
	} ;
224
	<make-keyword> ( s, i, a ) ;
225
} ;
226
 
227
 
228
/*
229
    COMMANDS
230
 
231
    These actions define the composite commands derived from the basic
232
    commands above.
233
*/
234
 
235
command : () -> () ;
236
 
237
command-list : () -> () = {
238
	$ ;
239
    ||	command ; command-list ;
240
    ##	<syntax-error> ;
241
} ;
242
 
243
if-command : () -> () = {
244
	if ; open ; i = identifier ; close ;
245
	j = <get-condition> ;
246
	<add-condition> ( i ) ;
247
	command ;
248
	{
249
		else ; <compl-condition> ; command ; <set-condition> ( j ) ;
250
	    ##	<set-condition> ( j ) ;
251
	} ;
252
} ;
253
 
254
command : () -> () = {
255
	semicolon ;
256
    ||	white-defn ; semicolon ;
257
    ||	group-defn ; semicolon ;
258
    ||	trigraph-defn ; semicolon ;
259
    ||	token-defn ; semicolon ;
260
    ||	keyword-defn ; semicolon ;
261
    ||	open-brace ; command-list ; close-brace ;
262
    ||	if-command ;
263
} ;
264
 
265
 
266
/*
267
    COMPLETE UNIT
268
 
269
    This action gives the main entry point for the syntax.  A complete
270
    unit just consists of a list of commands.
271
*/
272
 
273
unit : () -> () = {
274
	command-list ;
275
	{
276
		eof ;
277
	    ##	<syntax-error> ;
278
	} ;
279
}  ;
280
 
281
%entry% unit ;