Changeset 5ca5263 for doc/theses/jiada_liang_MMath
- Timestamp:
- Aug 9, 2024, 8:28:43 AM (4 months ago)
- Branches:
- master
- Children:
- 16915b1, 6abb6dc
- Parents:
- f125e96
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/test1.cfa
rf125e96 r5ca5263 1 1 #include <fstream.hfa> // sout 2 2 #include <stdlib.hfa> // ato 3 #include <enum.hfa> 3 4 4 5 // integral … … 9 10 enum( Letter ) Greek { Alph = A, Beta = B, Gamma = G, /* more enums */ Zeta = Z }; // alphabet intersection 10 11 12 // integral 11 13 enum( char ) Currency { Dollar = '$', Cent = '¢', Yen = '¥', Pound = '£', Euro = 'E' }; // iso-latin-1 12 14 enum( Currency ) Europe { Euro = Currency.Euro, Pound = Currency.Pound }; … … 33 35 34 36 enum() Mode { O_RDONLY, O_WRONLY, O_CREAT, O_TRUNC, O_APPEND }; 35 Mode iomode = O_RDONLY; 36 //bool b = iomode == O_RDONLY || iomode < O_APPEND; // disallowed 37 //int www = iomode; // disallowed 37 Mode mode = O_RDONLY; 38 void opaque() { 39 bool b = mode == O_RDONLY || mode < O_APPEND; // disallowed 40 //int www = mode; // disallowed 41 } 38 42 39 43 enum( char * ) Colour { Red = "red", Green = "green", Blue = "blue" }; 44 45 enum E1 { A1, B1, C1 = A1, D1 = B1 }; 46 enum(float) E2 { A2 = 3.5, B2 = 4.5, C2 = A, D2 = B }; 40 47 41 48 void fred() { … … 45 52 //greek = A; // disallowed 46 53 47 for ( Greek l = Alph; posn(l) < =posn(Gamma); l = succ( l ) ) {54 for ( Greek l = Alph; posn(l) < posn(Gamma); l = succ( l ) ) { 48 55 printf( "%s %c %d\n", label( l ), value( l ), posn( l ) ); 49 56 } 50 for ( Currency c = Dollar; posn(c) < =posn(Currency.Euro); c = succ( c ) ) {57 for ( Currency c = Dollar; posn(c) < posn(Currency.Euro); c = succ( c ) ) { 51 58 printf( "%s %c %d\n", label( c ), value( c ), posn( c ) ); 52 59 } 53 60 } 54 61 55 56 enum( char * ) Names { Fred = "FRED", Mary = "MARY", Jane = "JANE" }; 57 enum( char * ) Names2 { inline Names, Jack = "JACK", Jill = "JILL" }; 58 enum( char * ) Names3 { inline Names2, Sue = "SUE", Tom = "TOM" }; 59 62 enum( const char * ) Names { Fred = "FRED", Mary = "MARY", Jane = "JANE" }; 63 enum( const char * ) Names2 { inline Names, Jack = "JACK", Jill = "JILL" }; 64 enum( const char * ) Names3 { inline Names2, Sue = "SUE", Tom = "TOM" }; 65 void bar() { 66 Names fred = Names.Fred; 67 (Names2)fred; (Names3)fred; (Names3)Names2.Jack; // cast to super type 68 Names2 fred2 = fred; Names3 fred3 = fred2; // assign to super type 69 const char * name = fred; 70 Names name = Fred; 71 sout | name | label( name ) | posn( name ) | value( name ); 72 } 60 73 void f( Names n ) { sout | "Name" | posn( n ); } 61 74 void g( Names2 ); … … 63 76 void j( char * ); 64 77 65 enum color { red, blue, green }; 66 //color c = 0; 67 //color c = 1; 68 color c = 2; 69 int w = red; 78 enum CColour { Red, Blue, Green }; 79 CColour c0 = 0; 80 CColour c1 = 1; 81 CColour c = 2; 82 int w = Red; 83 84 void coo() { 85 enum(int) Color { Red, Blue, Green }; 86 Colour c = Red; 87 sout | countof( Colour ) | Countof( c ); 88 // sout | Countof( Colour ); 89 sout | countof( c ); 90 } 70 91 71 92 // enum(int) Week ! { Mon, Tue, Wed, Thu = 10, Fri, Sat, Sun }; … … 79 100 // } 80 101 102 void baz() { 103 enum(int) Count { First, Second, Third/* = First*/, Fourth/* = Second*/ }; 104 enum CCount { First, Second, Third/* = First*/, Fourth/* = Second*/ }; 105 Count cnt = Second; 106 CCount ccnt = Second; 107 if ( cnt < Third ) sout | "less than Third"; 108 if ( cnt ) sout | "XXX"; 109 if ( ccnt ) sout | "YYY"; 110 enum(float) F {WWW = 0.0}; 111 F f; 112 if ( f ) sout | "FFF"; 113 bool ?!=?( Name n, zero_t ) { sout | "DDD"; return n != Fred; } 114 Name n = Mary; 115 if ( n ) sout | "NAME"; 116 choose( cnt ) { 117 case First: sout | "First"; 118 case Second: sout | "Second"; 119 case Third: sout | "Third"; 120 case Fourth: sout | "Fourth"; 121 } 122 // for (d; Week) { sout | d; } 123 // for (p; +~=Planet) { sout | p; } 124 for ( cx; Count ) { sout | cx | nonl; } sout | nl; 125 for ( cx; +~= Count ) { sout | cx | nonl; } sout | nl; 126 for ( cx; -~= Count ) { sout | cx | nonl; } sout | nl; 127 for ( Count cx = lowerBound();; ) { 128 sout | cx | nonl; 129 if ( cx == upperBound() ) break; 130 cx = succ( cx ); 131 } 132 sout | nl; 133 } 134 81 135 int main() { 82 136 fred(); 83 Names name = Fred;137 Names name = Names.Fred; 84 138 // f( name ); 85 139 86 140 int jane_pos = posn( Names.Jane ); 87 c har * jane_value = value( Names.Jane );88 c har * jane_label = label( Names.Jane );141 const char * jane_value = value( Names.Jane ); 142 const char * jane_label = label( Names.Jane ); 89 143 sout | Names.Jane | posn( Names.Jane) | label( Names.Jane ) | value( Names.Jane ); 144 145 bar(); 146 baz(); 147 coo(); 148 149 enum Ex { Ax, Bx, Cx, Nx }; 150 float H1[Nx] = { [Ax] : 3.4, [Bx] : 7.1, [Cx] : 0.01 }; // C 151 // float H2[Ex] = { [Ax] : 3.4, [Bx] : 7.1, [Cx] : 0.01 }; // CFA 152 153 enum(int) E { A = 3 } e = A; 154 sout | A | label( A ) | posn( A ) | value( A ); 155 sout | e | label( e ) | posn( e ) | value( e ); 90 156 }
Note: See TracChangeset
for help on using the changeset viewer.