1 | with Ada.Text_IO; use Ada.Text_IO; |
---|
2 | -- with Ada.Standard; use Ada.Standard; |
---|
3 | procedure test is |
---|
4 | type RGB is ( Red, Green, Blue ); |
---|
5 | for RGB use ( Red => 10, Green => 20, Blue => 30 ); |
---|
6 | Colour : RGB := Red; |
---|
7 | |
---|
8 | type ABC is ('A', 'B', 'C'); |
---|
9 | Chars : ABC := 'C'; |
---|
10 | |
---|
11 | type Operator is ( '+', '-', '*', '/' ); |
---|
12 | for Operator use ( '+' => 10, '-' => 20, '*' => 30, '/' => 40 ); |
---|
13 | op : Operator := '+'; |
---|
14 | Ops : array( 0..3) of Operator; |
---|
15 | |
---|
16 | type Week is ( Mon, Tue, Wed, Thu, Fri, Sat, Sun ); |
---|
17 | for Week use ( Mon => 0, Tue => 1, Wed => 2, Thu => 10, Fri => 11, Sat => 14, Sun => 15 ); |
---|
18 | subtype Weekday is Week range Mon .. Fri; |
---|
19 | subtype Weekend is Week range Sat .. Sun; |
---|
20 | Day : Week; |
---|
21 | Lunch : array( Week ) of Integer; |
---|
22 | |
---|
23 | -- type Boolean is ( False, True ); |
---|
24 | B : Boolean := True; |
---|
25 | begin |
---|
26 | Put_Line( Integer'Image( RGB'Pos( Colour ) ) & " " & RGB'Image( RGB'Val(0) ) ); |
---|
27 | Put_Line( Integer'Image( RGB'Enum_Rep( Colour ) ) & " " & RGB'Image( RGB'Enum_Val( 10 ) ) ); |
---|
28 | Put_Line( """" & RGB'Image( Colour ) & """ " & RGB'Image( RGB'Value( "Red" ) ) ); |
---|
29 | |
---|
30 | |
---|
31 | Put_Line( RGB'Image( Colour ) & Integer'Image( RGB'Pos( Colour ) ) & Integer'Image( RGB'Enum_Rep( Colour ) ) ); |
---|
32 | Put_Line( RGB'Image( Colour ) & Integer'Image( RGB'Pos( Colour ) ) & Integer'Image( RGB'Enum_Rep( Colour ) ) ); |
---|
33 | |
---|
34 | for op in RGB loop |
---|
35 | Put( "(" & Integer'Image( RGB'Pos( op ) ) & Integer'Image( RGB'Enum_Rep( op ) ) & ' ' & RGB'Image( op ) & ") " ); |
---|
36 | end loop; |
---|
37 | Put_Line( "" ); |
---|
38 | |
---|
39 | Put_Line( ABC'Image( Chars ) ); |
---|
40 | Put_Line( Integer'Image( ABC'Pos( Chars ) ) ); |
---|
41 | |
---|
42 | Op := '+'; |
---|
43 | if Op = '+' or else Op = '-' then null; |
---|
44 | elsif Op = '*' or else Op = '/' then null; end if; |
---|
45 | |
---|
46 | case Op is |
---|
47 | when '+' => null; |
---|
48 | when '-' => null; |
---|
49 | when '*' => null; |
---|
50 | -- when '/' => null; |
---|
51 | when others => null; |
---|
52 | end case; |
---|
53 | for op in Operator loop |
---|
54 | Put( "(" & Integer'Image( Operator'Pos( op ) ) & Integer'Image( Operator'Enum_Rep( op ) ) & ' ' & Operator'Image( op ) & ") " ); |
---|
55 | end loop; |
---|
56 | Put_Line( "" ); |
---|
57 | |
---|
58 | Ops := "+-*/"; |
---|
59 | Ops := "+-" & "*/"; |
---|
60 | for Op of Ops loop |
---|
61 | Put_Line( Operator'Image( Op ) ); |
---|
62 | end loop; |
---|
63 | Day := Wed; |
---|
64 | case Day is |
---|
65 | when Mon .. Fri => null; |
---|
66 | when Sat .. Sun => null; |
---|
67 | end case; |
---|
68 | case Day is |
---|
69 | when Weekday => null; |
---|
70 | when Weekend => null; |
---|
71 | end case; |
---|
72 | for Day in Mon .. Sun loop |
---|
73 | Put( Week'Image( Day ) & " " ); |
---|
74 | end loop; |
---|
75 | Put_Line( "" ); |
---|
76 | for Day in Week loop |
---|
77 | Put( Week'Image( Day ) & " " ); |
---|
78 | end loop; |
---|
79 | Put_Line( "" ); |
---|
80 | for Day in Weekday loop |
---|
81 | Put( Week'Image( Day ) & " " ); |
---|
82 | end loop; |
---|
83 | Put_Line( "" ); |
---|
84 | for Day in Weekend loop |
---|
85 | Put( Week'Image( Day ) & " " ); |
---|
86 | end loop; |
---|
87 | Put_Line( "" ); |
---|
88 | |
---|
89 | for Day in Week loop |
---|
90 | Lunch( Day ) := 3; |
---|
91 | end loop; |
---|
92 | for Day in Week loop |
---|
93 | Put( Integer'Image( Lunch(Day ) ) & " " ); |
---|
94 | end loop; |
---|
95 | |
---|
96 | if B then null; end if; |
---|
97 | end test; |
---|
98 | |
---|
99 | -- Local Variables: -- |
---|
100 | -- tab-width: 4 -- |
---|
101 | -- compile-command: "gnatmake test.adb" -- |
---|
102 | -- End: -- |
---|