PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/manifest_notation.e

http://github.com/tybor/Liberty
Specman e | 459 lines | 308 code | 66 blank | 85 comment | 3 complexity | dfcdb4db9767c4836c180b105379bc13 MD5 | raw file
  1class MANIFEST_NOTATION
  2   --
  3   -- To know more or to discover manifest notation syntax and semantic, you
  4   -- can just read this file, or even better, run this code under our debugger:
  5   --
  6   --           se c -sedb manifest_notation -o manifest_notation
  7   --           ./manifest_notation
  8
  9create {ANY}
 10   make
 11
 12feature {}
 13   boolean_examples
 14         -- Examples of notations for the BOOLEAN type.
 15      local
 16         boolean: BOOLEAN
 17      do
 18         -- Simply True or False:
 19         boolean := True
 20
 21         boolean := False
 22
 23         check
 24            True -- Is always correct.
 25         end
 26      end
 27
 28   character_examples
 29         -- Examples of notations for the CHARACTER type.
 30      local
 31         character: CHARACTER
 32      do
 33         -- The ordinary notation:
 34         character := 'a'
 35         character := 'b'
 36         character := 'c'
 37         character := 'A'
 38         character := 'B'
 39         character := 'C'
 40         character := '.'
 41         character := '+'
 42         character := '-'
 43         -- The new_line character:
 44
 45         character := '%N'
 46         -- The tab character:
 47
 48         character := '%T'
 49         -- The default initialization value:
 50
 51         character := '%U'
 52         -- The percent itself:
 53
 54         character := '%%'
 55         -- The simple quote:
 56
 57         character := '%''
 58         -- The double quote:
 59
 60         character := '%"'
 61
 62         check
 63         -- The At-sign  (just in case you have a strange keyboard ;-)
 64            '@' = '%A'
 65         end
 66         -- The Backspace:
 67         character := '%B'
 68
 69         check
 70         -- Circumflex (just in case you have a strange keyboard ;-)
 71            '^' = '%C'
 72         end
 73         check
 74         -- The dollar sign (just in case you have a strange keyboard ;-)
 75            '$' = '%D'
 76         end
 77         -- The Form feed:
 78         character := '%F'
 79
 80         check
 81         -- The backslasH (just in case you have a strange keyboard ;-)
 82            '\' = '%H'
 83         end
 84         check
 85         -- The tiLda (just in case you have a strange keyboard ;-)
 86            '~' = '%L'
 87         end
 88         check
 89         -- The back Quote
 90            '`' = '%Q'
 91         end
 92         -- The carriage Return
 93         character := '%R'
 94
 95         check
 96         -- The Sharp (just in case you have a strange keyboard ;-)
 97            '#' = '%S'
 98         end
 99         check
100         -- The Vertical bar (just in case you have a strange keyboard ;-)
101            '|' = '%V'
102         end
103         check
104         -- The opening bracket (just in case you have a strange keyboard ;-)
105            '[' = '%('
106         end
107         check
108         -- The closing bracket (just in case you have a strange keyboard ;-)
109            ']' = '%)'
110         end
111         check
112         -- The opening brace (just in case you have a strange keyboard ;-)
113            '{' = '%<'
114         end
115         check
116         -- The closing brace (just in case you have a strange keyboard ;-)
117            '}' = '%>'
118         end
119         -- The decimal ascii notation:
120         character := '%/97/' -- is equivalent to 'a'
121         character := '%/32/' -- is equivalent to ' '
122         character := '%/0/'
123         -- is equivalent to '%U' (which is the default initialization value)
124         -- The hexadecimal notation:
125
126         character := '%/0x30/' -- is equivalent to '0'
127         character := '%/0x31/' -- is equivalent to '1'
128         character := '%/0x32/' -- is equivalent to '2'
129         character := '%/0x00/' -- is equivalent to '%U'
130      end
131
132   string_examples
133         -- Examples of notations for the STRING type.
134      local
135         string: STRING
136      do
137         string := "Hello!"
138         string := "The escape percent for new-line %N (try to print it).%N"
139
140         string := "The escape percent for tab: %T <- its a tab%N"
141
142         string := "As you may guess %% <- its a percent"
143
144         string := "As you may guess %" <- its a double quote !"
145
146         string := "When the string is too long you%
147                   %can continue on more than one line"
148
149         string := "{
150         Look this verbatim two lines string using
151         our debugger !
152
153         }"
154
155         string := "[
156         Look left-aligned verbatim string using
157         our debugger !
158
159         ]"
160
161         string := "{
162         No escape percent in %T verbatim
163         %N strings !
164         ... cool.
165         }"
166         -- Hexadecimal notation is available too:
167
168         string := "One %/0x43414645/ pl%/0x65/ase"
169         sedb_breakpoint
170         -- Use the -sedb option to view the string !
171         -- Finally, keep in mind that "once" can precede the STRING
172         -- notation to avoid multiple allocations:
173
174         string := once "I am allocated once even when used inside a loop !"
175      end
176
177   unicode_string_examples
178         -- Examples of notations for the UNICODE_STRING type.
179      local
180         unicode_string: UNICODE_STRING
181      do
182         unicode_string := U"I am not a STRING, but a UNICODE_STRING !"
183         unicode_string := U"<- the big U indicates that."
184
185         unicode_string := U"{
186         As for STRING, you can write UNICODE_STRING on
187         more
188         than
189         one
190         line with the verbatim notation.
191
192         }"
193         -- Inside UNICODE_STRING only, you have the Ux notation to denote
194         -- any character you want (http://www.unicode.org):
195
196         unicode_string := U"The EURO sign is %/Ux20AC/!%N"
197      end
198
199   integer_examples
200      local
201         integer_8: INTEGER_8; integer_16: INTEGER_16; integer_32: INTEGER_32; integer_64: INTEGER_64
202         integer: INTEGER
203      do
204         -- 0 is of type INTEGER_8:
205         integer_8 := 0
206         -- The minimum value for INTEGER_8:
207
208         integer_8 := -128
209         -- The maximum value for INTEGER_8:
210
211         integer_8 := 127
212
213         inspect
214            integer_8
215         when -128 .. 127 then
216            -- The INTEGER_8 range
217            -- We should always go here...
218         else
219            check
220               False -- ... and never here !
221            end
222         end
223         -- The INTEGER_16 range:
224         integer_16 := -32768
225         integer_16 := 32767
226         -- The INTEGER_32 range:
227
228         integer_32 := -2147483648
229         integer_32 := 2147483647
230         -- INTEGER is, at time being, equivalent to INTEGER_32:
231
232         integer := integer_32
233         integer := 0
234         integer_32 := integer
235         -- INTEGER_64 range:
236
237         integer_64 := -9223372036854775808
238         integer_64 := 9223372036854775807
239         -- Now using the hexadecimal notation to denote INTEGER.
240         -- A 2 hexadecimal digit denote an INTEGER_8.
241         -- Setting all bits of an INTEGER_8 is achieved with:
242
243         integer_8 := 0xFF
244         check
245            integer_8 = -1
246         end
247         -- A 4 hexadecimal digit denote an INTEGER_16.
248         -- As an example, the greater positive value for an INTEGER_16 is:
249
250         integer_16 := 0x7FFF
251         check
252            integer_16 = 32767
253         end
254         -- A 8 hexadecimal digit denote an INTEGER_32.
255         -- As an example, the smallest negative value for an INTEGER_32 is:
256
257         integer_32 := 0x80000000
258         check
259            integer_32 = -2147483648
260         end
261         -- A 16 hexadecimal digit denote an INTEGER_64.
262         -- The `Maximum_integer_64':
263
264         integer_64 := 0x7FFFFFFFFFFFFFFF
265         check
266            integer_64 = 9223372036854775807
267         end
268         -- The `Minimum_integer_64':
269         integer_64 := 0x8000000000000000
270         check
271            integer_64 = -9223372036854775808
272         end
273         -- When you need to do so, the complete type notation can also be used for all kinds
274         -- of INTEGERs:
275
276         integer_32 := {INTEGER_32 1}
277         check
278            integer_32 = 1
279         end
280         integer_16 := {INTEGER_16 0xFFFF}
281         check
282            integer_16 = -1
283         end
284      end
285
286   real_examples
287      local
288         real_32: REAL_32; real_64: REAL_64; real: REAL; real_extended: REAL_EXTENDED
289      do
290         -- At time being, REAL is equivalent of REAL_64. The classic notation always
291         -- denote a REAL (i.e. a REAL_64):
292         real := 0.0
293         real_64 := 0.0
294         check
295            real = real_64
296         end
297         real_64 := 35.5
298         -- The scientific notation is possible too:
299
300         real_64 := 3.55e+1
301         check
302            real_64 = 35.5
303         end
304         -- You can omit the fractional part when using scientific notation:
305         check
306            3E2 = 300.0
307         end
308         -- In order to denote a REAL_32, you must always rely on the explicit following notation:
309         real_32 := {REAL_32 1.5}
310         real_32 := {REAL_32 156.5E-2}
311         -- You can as well denote REAL_80, REAL_128 or REAL_EXTENDED:
312
313         real_extended := {REAL_EXTENDED 156.5E-287}
314      end
315
316   array_examples
317      local
318         array_of_character: ARRAY[CHARACTER]; array_of_integer: ARRAY[INTEGER]
319      do
320         -- A four elements ARRAY[CHARACTER] with the lower bound set to 1:
321         array_of_character := {ARRAY[CHARACTER] 1, << 'a', 'b', 'c', 'd', 'e' >> }
322         -- A three elements ARRAY[INTEGER] with the lower bound set to -1:
323
324         array_of_integer := {ARRAY[INTEGER] -1, << 1, 2, 3 >> }
325      end
326
327   fast_array_examples
328      local
329         fast_array_of_character: FAST_ARRAY[CHARACTER]; fast_array_of_integer: FAST_ARRAY[INTEGER]
330      do
331         -- A four elements FAST_ARRAY[CHARACTER]:
332         fast_array_of_character := {FAST_ARRAY[CHARACTER] << 'a', 'b', 'c', 'd', 'e' >> }
333         -- A three elements FAST_ARRAY[INTEGER]:
334
335         fast_array_of_integer := {FAST_ARRAY[INTEGER] << 1, 2, 3 >> }
336      end
337
338   linked_list_examples
339      local
340         linked_list_of_character: LINKED_LIST[CHARACTER]; linked_list_of_integer: LINKED_LIST[INTEGER]
341      do
342         -- A four elements LINKED_LIST[CHARACTER]:
343         linked_list_of_character := {LINKED_LIST[CHARACTER] << 'a', 'b', 'c', 'd', 'e' >> }
344         -- A three elements LINKED_LIST[INTEGER]:
345
346         linked_list_of_integer := {LINKED_LIST[INTEGER] << 1, 2, 3 >> }
347      end
348
349   two_way_linked_list_examples
350      local
351         two_way_linked_list_of_character: TWO_WAY_LINKED_LIST[CHARACTER]
352         two_way_linked_list_of_integer: TWO_WAY_LINKED_LIST[INTEGER]
353      do
354         -- A four elements TWO_WAY_LINKED_LIST[CHARACTER]:
355         two_way_linked_list_of_character := {TWO_WAY_LINKED_LIST[CHARACTER] << 'a', 'b', 'c', 'd', 'e' >> }
356         -- A three elements TWO_WAY_LINKED_LIST[INTEGER]:
357
358         two_way_linked_list_of_integer := {TWO_WAY_LINKED_LIST[INTEGER] << 1, 2, 3 >> }
359      end
360
361   ring_array_examples
362      local
363         ring_array_of_character: RING_ARRAY[CHARACTER]; ring_array_of_integer: RING_ARRAY[INTEGER]
364      do
365         -- A four elements RING_ARRAY[CHARACTER]:
366         ring_array_of_character := {RING_ARRAY[CHARACTER] 1, << 'a', 'b', 'c', 'd', 'e' >> }
367         -- A three elements RING_ARRAY[INTEGER]:
368
369         ring_array_of_integer := {RING_ARRAY[INTEGER] 1, << 1, 2, 3 >> }
370      end
371
372   set_examples
373      local
374         set_of_character: SET[CHARACTER]; set_of_integer: SET[INTEGER]
375      do
376         -- A four elements HASHED_SET[CHARACTER]:
377         set_of_character := {HASHED_SET[CHARACTER] << 'a', 'b', 'c', 'd', 'e', 'f' >> }
378         -- A three elements HASHED_SET[INTEGER]:
379
380         set_of_integer := {AVL_SET[INTEGER] << 1, 2, 3 >> }
381      end
382
383   dictionary_examples
384      local
385         dictionary: DICTIONARY[CHARACTER, STRING]
386      do
387         -- You can as well denote a DICTIONARY creation like this:
388         dictionary := {HASHED_DICTIONARY[CHARACTER, STRING] << 'a', "key #1";
389                                                                'z', "key #2";
390                                                                'z', "key #3";
391                                                                'a', "key #4" >> }
392         -- Note that the ; (semicolon) is here to separate pairs.
393      end
394
395   bijective_dictionary_examples
396      local
397         bijective_dictionary: BIJECTIVE_DICTIONARY[STRING, STRING]
398      do
399         -- You can as well denote a DICTIONARY creation like this:
400         bijective_dictionary := {HASHED_BIJECTIVE_DICTIONARY[STRING, STRING] << "value #1", "key #1";
401                                                                                 "value #2", "key #2";
402                                                                                 "value #3", "key #3" >> }
403         -- Note that the ; (semicolon) is here to separate pairs.
404      end
405
406   array2_examples
407      local
408         collection2: COLLECTION2[CHARACTER]
409      do
410         collection2 := {ARRAY2[CHARACTER] 1, 4, 1, 6, << 'a', 'b', 'c', 'd', 'e', 'f';
411                                                          'a', 'b', 'c', 'd', 'e', 'f';
412                                                          'a', 'b', 'c', 'd', 'e', 'f';
413                                                          'a', 'b', 'c', 'd', 'e', 'f' >> }
414      end
415
416   fast_array2_examples
417      local
418         collection2: COLLECTION2[CHARACTER]
419      do
420         collection2 := {FAST_ARRAY2[CHARACTER] 4, 6, << 'a', 'b', 'c', 'd', 'e', 'f';
421                                                         'a', 'b', 'c', 'd', 'e', 'f';
422                                                         'a', 'b', 'c', 'd', 'e', 'f';
423                                                         'a', 'b', 'c', 'd', 'e', 'f' >> }
424      end
425
426   native_array_examples
427      local
428         native_array_character: NATIVE_ARRAY[CHARACTER]; native_array_integer_8: NATIVE_ARRAY[INTEGER_8]
429      do
430         native_array_character := {NATIVE_ARRAY[CHARACTER] << 'a', 'b', 'c', 'd', 'e', 'f' >> }
431         check
432            native_array_character.item(0) = 'a'
433            native_array_character.item(5) = 'f'
434         end
435         native_array_integer_8 := {NATIVE_ARRAY[INTEGER_8] << 0, 1, 2, 3, 4, 5, 6, 7, 8 >> }
436      end
437
438   make
439      do
440         boolean_examples
441         character_examples
442         string_examples
443         unicode_string_examples
444         integer_examples
445         real_examples
446         array_examples
447         fast_array_examples
448         linked_list_examples
449         two_way_linked_list_examples
450         ring_array_examples
451         set_examples
452         dictionary_examples
453         bijective_dictionary_examples
454         array2_examples
455         fast_array2_examples
456         native_array_examples
457      end
458
459end -- class MANIFEST_NOTATION