source: doc/theses/jiada_liang_MMath/test.cfa @ b12e4ad

Last change on this file since b12e4ad was 1725989, checked in by Peter A. Buhr <pabuhr@…>, 5 months ago

add enumeration test programs for different programming languages

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[1725989]1enum Alphabet {
2        A = 'A', B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
3        a = 'a', b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
4};
5
6
7forall( istype & | istream( istype ) | { istype & ?|?( istype &, E & ); } )
8istype & ?|?( istype & is, E & e ) {
9        choose ( e ) {
10          case A: is | label( A ); e = A;
11          case B: is | label( B ); e = B;
12          case C: is | label( C ); e = C;
13        } // choose
14        return is;
15}
16
17forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, E ); } )
18        ostype & ?|?( ostype & os, E e ) {
19        choose ( e ) {
20          case A: os | label( A );
21          case B: os | label( B );
22          case C: os | label( C );
23        } // choose
24        return os;
25}
26
27enum( char * ) Friends { Fred = "FRED", Mary = "MARY", Jane = "Jane" };
28
29forall( istype & | istream( istype ) | { istype & ?|?( istype &, Friends & ); } )
30istype & ?|?( istype & is, Friends & friend ) {
31        choose ( friend ) {
32          case Fred: is | label( A ); friend = A;
33          case Mary: is | label( B ); friend = B;
34          case Jane: is | label( C ); friend = C;
35        } // choose
36        return is;
37}
38
39forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, Friends ); } )
40        ostype & ?|?( ostype & os, Friends friend ) {
41        choose ( friend ) {
42          case Fred: os | value( Fred );
43          case Mary: os | value( Mary );
44          case Jane: os | value( Jane );
45        } // choose
46        return os;
47}
48
49
50int main() {
51        E e = A;
52        sin | e;
53        sout | e;
54        Friends friend = Mary;
55        sin | friend;
56        sout | friend;
57}
Note: See TracBrowser for help on using the repository browser.