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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338 | with Ada.Characters.Handling;
with Ada.Directories;
with Ada.Strings.Unbounded;
with String_Pkg;
package body Ayacc_File_Names is
use Ada.Characters.Handling;
use Ada.Strings.Unbounded;
function "+" (Item : String) return Unbounded_String
renames To_Unbounded_String;
function "+" (Item : Unbounded_String) return String
renames To_String;
Source_File_Name : Unbounded_String;
Out_File_Name : Unbounded_String;
Verbose_File_Name : Unbounded_String;
Template_File_Name : Unbounded_String;
Actions_File_Name : Unbounded_String;
Shift_Reduce_File_Name : Unbounded_String;
Goto_File_Name : Unbounded_String;
Tokens_File_Name : Unbounded_String;
-- UMASS CODES :
Error_Report_File_Name : Unbounded_String;
Listing_File_Name : Unbounded_String;
-- END OF UMASS CODES.
C_Lex_File_Name : Unbounded_String;
Include_File_Name : Unbounded_String;
--RJS ==========================================
function End_of_Unit_Name (Name : in String) return Natural is
Dot_Position : Natural := Name'Last;
begin
while Dot_Position >= Name'First and then
Name (Dot_Position) /= '.'
loop
Dot_Position := Dot_Position - 1;
end loop;
return Dot_Position - 1;
end End_of_Unit_Name;
function Get_Unit_Name (Filename : in String) return String is
-- modified to check for valid Ada identifiers. 11/28/88 kn
Filename_Without_Extension : String :=
Filename (Filename'First .. End_of_Unit_Name (Filename));
End_of_Directory : Natural := Filename_Without_Extension'Last + 1;
function Is_Alphabetic (Ch : in Character) return Boolean is
begin
return Ch in 'A' .. 'Z' or else
Ch in 'a' .. 'z';
end Is_Alphabetic;
function Is_AlphaNum_or_Underscore (Ch : in Character) return Boolean is
begin
return Is_Alphabetic(Ch) or else
Ch in '0' .. '9' or else
Ch = '_' or else Ch = '-';
end Is_AlphaNum_or_Underscore;
use String_Pkg;
begin
-- find end of directory
for Pos in reverse Filename_Without_Extension'FIRST..
Filename_Without_Extension'LAST loop
exit when Filename_Without_Extension(Pos) = '/';
End_Of_Directory := Pos;
end loop;
if End_Of_Directory <= Filename_Without_Extension'LAST and then
Is_Alphabetic (Filename_Without_Extension (End_of_Directory)) then
Check_Remaining_Characters :
for i in End_Of_Directory + 1 .. Filename_Without_Extension'LAST
loop
if not Is_AlphaNum_or_Underscore (Filename_Without_Extension(i)) then
return "";
elsif Filename_Without_Extension(i) = '-' then
Filename_Without_Extension(i) := '.';
end if;
end loop Check_Remaining_Characters;
return Value (Mixed (Filename_Without_Extension (End_of_Directory ..
Filename_Without_Extension'Last)));
else
return "";
end if;
end Get_Unit_Name;
---------------------
-- C_Lex_Unit_Name --
---------------------
function C_Lex_Unit_Name return String is
Filename : constant String := To_Upper (+C_Lex_File_Name);
begin
return Get_Unit_Name (Filename);
end C_Lex_Unit_Name;
---------------------------
-- Goto_Tables_Unit_Name --
---------------------------
function Goto_Tables_Unit_Name return String is
Filename : constant String := To_Upper (+Goto_File_Name);
begin
return Get_Unit_Name (Filename);
end Goto_Tables_Unit_Name;
-----------------------------------
-- Shift_Reduce_Tables_Unit_Name --
-----------------------------------
function Shift_Reduce_Tables_Unit_Name return String is
Filename : constant String := To_Upper (+Shift_Reduce_File_Name);
begin
return Get_Unit_Name (Filename);
end Shift_Reduce_Tables_Unit_Name;
----------------------
-- Tokens_Unit_Name --
----------------------
function Tokens_Unit_Name return String is
Filename : constant String := To_Upper (+Tokens_File_Name);
begin
return Get_Unit_Name (Filename);
end Tokens_Unit_Name;
--------------------
-- Main_Unit_Name --
--------------------
function Main_Unit_Name return String is
Filename : constant String := To_Upper (+Out_File_Name);
begin
return Get_Unit_Name (Filename);
end Main_Unit_Name;
-- UMASS CODES :
----------------------------
-- Error_Report_Unit_Name --
----------------------------
function Error_Report_Unit_Name return String is
Filename : constant String := To_Upper (+Error_Report_File_Name);
begin
return Get_Unit_Name (Filename);
end Error_Report_Unit_Name;
-- END OF UMASS CODES.
--RJS ==========================================
--------------------------
-- Get_Source_File_Name --
--------------------------
function Get_Source_File_Name return String is
begin
return +Source_File_Name;
end;
-----------------------
-- Get_Out_File_Name --
-----------------------
function Get_Out_File_Name return String is
begin
return +Out_File_Name;
end;
---------------------------
-- Get_Verbose_File_Name --
---------------------------
function Get_Verbose_File_Name return String is
begin
return +Verbose_File_Name;
end;
----------------------------
-- Get_Template_File_Name --
----------------------------
function Get_Template_File_Name return String is
begin
return +Template_File_Name;
end;
---------------------------
-- Get_Actions_File_Name --
---------------------------
function Get_Actions_File_Name return String is
begin
return +Actions_File_Name;
end;
--------------------------------
-- Get_Shift_Reduce_File_Name --
--------------------------------
function Get_Shift_Reduce_File_Name return String is
begin
return +Shift_Reduce_File_Name;
end;
------------------------
-- Get_Goto_File_Name --
------------------------
function Get_Goto_File_Name return String is
begin
return +Goto_File_Name;
end;
--------------------------
-- Get_Tokens_File_Name --
--------------------------
function Get_Tokens_File_Name return String is
begin
return +Tokens_File_Name;
end;
-- UMASS CODES :
--------------------------------
-- Get_Error_Report_File_Name --
--------------------------------
function Get_Error_Report_File_Name return String is
begin
return +Error_Report_File_Name;
end Get_Error_Report_File_Name;
---------------------------
-- Get_Listing_File_Name --
---------------------------
function Get_Listing_File_Name return String is
begin
return +Listing_File_Name;
end;
-- END OF UMASS CODES.
-------------------------
-- Get_C_Lex_File_Name --
-------------------------
function Get_C_Lex_File_Name return String is
begin
return +C_Lex_File_Name;
end;
---------------------------
-- Get_Include_File_Name --
---------------------------
function Get_Include_File_Name return String is
begin
return +Include_File_Name;
end;
--------------------
-- Set_File_Names --
--------------------
procedure Set_File_Names(Input_File, Extension: in String) is
Base_Name : constant String := Ada.Directories.Base_Name (Input_File);
begin
if Input_File'Length < 3
or else (Input_File(Input_File'Last) /= 'y'
and then Input_File(Input_File'Last) /= 'Y')
or else Input_File(Input_File'Last - 1) /= '.' then
raise Illegal_File_Name;
end if;
Source_File_Name := +Input_File;
Out_File_Name := +Base_Name;
Append (Out_File_Name, Extension);
Verbose_File_Name := +Base_Name;
Append (Verbose_File_Name, ".verbose");
Tokens_File_Name := +Base_Name;
Append (Tokens_File_Name, "_tokens" & Extension & "ds");
-- UMASS CODES :
Error_Report_File_Name := +Base_Name;
Append (Error_Report_File_Name, "-error_report" & Extension);
Listing_File_Name := +Base_Name;
Append (Listing_File_Name, ".lis");
-- END OF UMASS CODES.
Template_File_Name := +"yyparse.template";
Actions_File_Name := +Base_Name;
Append (Actions_File_Name, ".accs");
Shift_Reduce_File_Name := +Base_Name;
Append (Shift_Reduce_File_Name, "-shift_reduce" & Extension & "ds");
Goto_File_Name := +Base_Name;
Append (Goto_File_Name, "-goto_table" & Extension & "ds");
C_Lex_File_Name := +Base_Name;
Append (C_Lex_File_Name, "-c_lex" & Extension);
Include_File_Name := +Base_Name;
Append (Include_File_Name, ".h");
end Set_File_Names;
end Ayacc_File_Names;
|