1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 | -- --
-- package Copyright (c) Dmitry A. Kazakov --
-- Test_Association_Expressions Luebeck --
-- Test package implementation Winter, 2004 --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public License as --
-- published by the Free Software Foundation; either version 2 of --
-- the License, or (at your option) any later version. This library --
-- is distributed in the hope that it will be useful, but WITHOUT --
-- ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from --
-- this unit, or you link this unit with other files to produce an --
-- executable, this unit does not by itself cause the resulting --
-- executable to be covered by the GNU General Public License. This --
-- exception does not however invalidate any other reasons why the --
-- executable file might be covered by the GNU Public License. --
--____________________________________________________________________--
with Ada.Characters.Handling; use Ada.Characters.Handling;
package body Test_Association_Expressions is
function "and" (Left, Right : Operations) return Boolean is
begin
return True;
end "and";
function Is_Commutative (Left, Right : Operations) return Boolean is
begin
case Left is
when Add | Sub =>
return Right = Add or Right = Sub;
when Mul | Div =>
return Right = Mul or Right = Div;
when others =>
return False;
end case;
end Is_Commutative;
function Is_Inverse (Operation : Operations) return Boolean is
begin
return Operation = Sub or else Operation = Div;
end Is_Inverse;
function Group_Inverse (Operation : Operations) return Operations is
begin
case Operation is
when Add | Sub =>
return Minus;
when Mul | Div =>
return Inv;
when others =>
raise Program_Error;
end case;
end Group_Inverse;
procedure Check_Spelling (Name : String) is
begin
null;
end Check_Spelling;
function Check_Matched (Source : String; Pointer : Integer)
return Boolean is
begin
return
( not Is_Alphanumeric (Source (Pointer))
or else
not Is_Alphanumeric (Source (Pointer - 1))
);
end Check_Matched;
function Arg_List (List : Tokens.Arguments.Frame)
return Unbounded_String is
Result : Unbounded_String;
begin
for Argument in List'Range loop
if Length (Result) > 0 then
Append (Result, ", ");
end if;
Append (Result, List (Argument).Value);
end loop;
return "(" & Result & ")";
end Arg_List;
function Call
( Context : access Test_Expression;
Operation : Tokens.Operation_Token;
List : Tokens.Arguments.Frame
) return Tokens.Argument_Token is
begin
return
( Operations'Image (Operation.Operation) & Arg_List (List),
Operation.Location & Link (List)
);
end Call;
function Enclose
( Context : access Test_Expression;
Left : Tokens.Operation_Token;
Right : Tokens.Operation_Token;
List : Tokens.Arguments.Frame
) return Tokens.Argument_Token is
function Img (Bracket : Operations) return String is
begin
case Bracket is
when Left_Bracket => return "";
when Right_Bracket => return "";
when others => return Operations'Image (Bracket);
end case;
end Img;
begin
return
( Img (Left.Operation) & Arg_List (List) & Img (Right.Operation),
Left.Location & Right.Location & Link (List)
);
end Enclose;
procedure Get_Operand
( Context : in out Test_Expression;
Code : in out Source'Class;
Argument : out Tokens.Argument_Token;
Got_It : out Boolean
) is
Line : String renames Get_Line (Code);
Pointer : Integer := Get_Pointer (Code);
Value : Unbounded_String;
begin
while ( Pointer <= Line'Last
and then
Is_Alphanumeric (Line (Pointer))
)
loop
Append (Value, Line (Pointer));
Pointer := Pointer + 1;
end loop;
if Length (Value) > 0 then
Set_Pointer (Code, Pointer);
Argument := (Value, Link (Code));
Got_It := True;
else
Got_It := False;
end if;
end Get_Operand;
begin
Add_Operator (Prefixes, "abs", Abs_Value, 10, 9);
Add_Operator (Prefixes, "++", Preinc, 10, 9);
Add_Operator (Prefixes, "--", Predec, 10, 9);
Add_Operator (Prefixes, "+", Plus, 10, 9);
Add_Operator (Prefixes, "-", Minus, 10, 9);
Add_Bracket (Prefixes, "(", Left_Bracket);
Add_Operator (Prefixes, "?", Pre_Query, 1, 2);
Add_Operator (Infixes, "+", Add, 1, 2);
Add_Operator (Infixes, "-", Sub, 1, 3);
Add_Operator (Infixes, "*", Mul, 3, 4);
Add_Operator (Infixes, "/", Div, 3, 4);
Add_Operator (Infixes, "**", Pow, 11, 5);
Add_Index (Infixes, "(", Left_Index, 4);
Add_Comma (Infixes, ",", Comma);
Add_Bracket (Postfixes, ")", Right_Bracket);
Add_Operator (Postfixes, "++", Postinc, 7, 8);
Add_Operator (Postfixes, "--", Postdec, 7, 8);
Add_Operator (Postfixes, "@", Post_at, 2, 1);
Add_Semicolon (Infixes, "|", Bar, Parsers.Sublist_Separator, 1);
Add_Semicolon (Infixes, ":", Colon, Parsers.Sublist_Separator, 2);
Add_Semicolon (Infixes, "#", Sharp, Parsers.Sublist_Separator, 3);
Add_Semicolon (Infixes, "$", Dollar, Parsers.Sublist_Separator, 1);
Add_Semicolon (Infixes, "with", Extension, Parsers.Sublist_Open, 0);
Add_Semicolon (Infixes, "out", Closure, Parsers.Sublist_Close, 0);
Add_Semicolon (Infixes, "<:", Colon_Open, Parsers.Sublist_Open, 2);
Add_Semicolon (Infixes, ":>", Colon_Close, Parsers.Sublist_Close, 2);
end Test_Association_Expressions;
|