-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexdata.ads
250 lines (218 loc) · 8.14 KB
/
lexdata.ads
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
--<****D* LexData
-- NAME
-- lexdata.ads - Holds all information related to parser and lexemes
-- AUTHOR
-- Stephen Magrowski
-- DESCRIPTION
-- Holds the symbol table, lexemes and their required information
-->****
with Text_IO; use Text_IO;
with OpenFile; use OpenFile;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Containers.Vectors; use Ada.Containers;
with lex; use lex;
--<****c* LexData/LexData
-- SYNOPSIS
-- Lexicographical analysis of an input file and outputs to another file
-->****
--<****h* LexData/LexData/LexData.Header
-- SYNOPSIS
-- The package containing the LexData information and functions/procedures.
-- Holds The symbol table, the lexemes, and their required information
-->****
package LexData is
--<****v* LexData/LexData/MaxIDConst
-- DESCRIPTION
-- This is the default amount of ID's the symbol table is able to hold.
-- User may change this if more ID's are needed to be stored.
-->****
MaxID : constant Integer := 100;
--<****t* LexData/LexData/Class_IOEnumType
-- DESCRIPTION
-- Allows Enumeration types to be declared. Used for proccessing Lexemes.
-->****
package Class_IO is new Ada.Text_IO.Enumeration_IO(Char_Type);
use Class_IO;
--<****t* LexData/LexData/Lexeme_Vectors
-- DESCRIPTION
-- Vector that holds all of the lexemes in the order they were proccesed.
-->****
package Lexeme_Vectors is new Vectors(Natural, Char_Type);
--<****t* LexData/LexData/LexLineNum_Vectors
-- DESCRIPTION
-- Vector that hold all line numbers of the Lexemes that were proccessed.
-->****
package LexLineNum_Vectors is new Vectors(Natural, Integer);
--<****g* LexData/LexData/Array.Functions
-- DESCRIPTION
-- Array operations
-->****
--<****f* LexData/LexData/Array.Functions/Array.Add_ID
-- DESCRIPTION
-- Attempts to add the Identifier into the ID_holder array
-- MEMBER FUNCTION TYPE
-- Mutator
-- PARAMETERS
-- Unbounded_String InputID: The input identifier - Input
-->****
procedure Add_ID(InputID: in Unbounded_String);
--<****f* LexData/LexData/Array.Functions/Array.Find_ID
-- DESCRIPTION
-- Tries to find the InputID in the IDHolder array
-- MEMBER FUNCTION TYPE
-- Mutator
-- PARAMETERS
-- Unbounded_String InputID: The input identifier - Input
-- RETURNS
-- Boolean: True if found, False if not
-->****
function Find_ID(InputID: in Unbounded_String) return Boolean;
--<****f* LexData/LexData/Array.Functions/Array.Output_ID
-- DESCRIPTION
-- Sends the symbol table into an output file.
-- MEMBER FUNCTION TYPE
-- Mutator
-- PARAMETERS
-- File_Type SpecialOutputFile: The output file - Input Output
-->****
procedure Output_ID(SpecialOutputFile: in out File_Type);
--<****g* LexData/LexData/LexData.Functions
-- DESCRIPTION
-- Lexdata operations
-->****
--<****f* LexData/LexData.Functions/LexData.Set_PastBegin
-- DESCRIPTION
-- Sets boolean value to indicate the Lexeme Proccessor is past the Begin.
-- MEMBER FUNCTION TYPE
-- Mutator
-->****
procedure Set_PastBegin;
--<****f* LexData/LexData/LexData.Functions/LexData.Get_PastBegin
-- DESCRIPTION
-- Returns a boolean value to see if lexeme proccessor is past the Begin.
-- MEMBER FUNCTION TYPE
-- Getter
-- RETURNS
-- Boolean: True if past, otherwise false
-->****
function Get_PastBegin return Boolean;
--<****f* LexData/LexData/LexData.Functions/LexData.Add_LineNumber
-- DESCRIPTION
-- Adds line number into the LexemeLineNum Vector.
-- MEMBER FUNCTION TYPE
-- Mutator
-->****
procedure Add_LineNumber;
--<****f* LexData/LexData/LexData.Functions/LexData.Get_LineNumber
-- DESCRIPTION
-- Returns a boolean value to see if Lexeme Proccessor is past the Begin.
-- MEMBER FUNCTION TYPE
-- Getter
-- RETURNS
-- Boolean: The line number of the lexeme in the symbol table
-->****
function Get_LineNumber return Integer;
--<****f* LexData/LexData/LexData.Functions/LexData.Increase_LineCount
-- DESCRIPTION
-- Adds 1 to the LineCount variable
-- MEMBER FUNCTION TYPE
-- Mutator
-->****
procedure Increase_LineCount;
--<****g* LexData/LexData/LexemeVector.Functions
-- DESCRIPTION
-- Array operations
-->****
--<****f* LexData/LexData/LexemeVector.Functions/LexemeVector.Output_Lexemes
-- DESCRIPTION
-- Sends the proccessed lexemes into an output file.
-- MEMBER FUNCTION TYPE
-- Mutator
-- PARAMETERS
-- File_Type SpecialOutputFile: The output File - Input Output
-->****
procedure Output_Lexemes(SpecialOutputFile: in out File_Type);
--<****f* LexData/LexData/LexemeVector.Functions/LexemeVector.Add_Lexeme
-- DESCRIPTION
-- Adds a lexeme to the Lexeme Vector as well as the line number.
-- MEMBER FUNCTION TYPE
-- Setter
-- PARAMETERS
-- Char_Type Lexeme: The lexeme that needs to be added - Input
-->****
procedure Add_Lexeme(Lexeme: in Char_Type);
--<****f* LexData/LexData/LexemeVector.Functions/LexemeVector.Get_Lexeme
-- DESCRIPTION
-- Returns the current lexeme at the CurrentVectorIdx
-- MEMBER FUNCTION TYPE
-- Getter
-- RETURNS
-- Char_Type : The lexeme that is at the current index
-->****
function Get_Lexeme return Char_Type;
--<****f* LexData/LexData/LexemeVector.Functions/LexemeVector.CheckNext_Lexeme
-- DESCRIPTION
-- Returns the current lexeme at the (CurrentVectorIdx + 1)
-- MEMBER FUNCTION TYPE
-- Inspector
-- RETURNS
-- Char_Type : The lexeme that is at the current index + 1
-->****
function CheckNext_Lexeme return Char_Type;
--<****f* LexData/LexData/LexemeVector.Functions/LexemeVector.MoveNext_Lexeme
-- DESCRIPTION
-- Moves pointer to the next lexeme in the Vector
-- MEMBER FUNCTION TYPE
-- Mutator
-->****
procedure MoveNext_Lexeme;
private
--<****v* LexData/LexData/Array.IDHolder
-- DESCRIPTION
-- Holds ID's in the symbol table
-->****
IDHolder: array(1..MaxID) of Ada.Strings.Unbounded.Unbounded_String;
--<****v* LexData/LexData/Array.IDLineNum
-- DESCRIPTION
-- Holds ID's line numbers in the symbol table
-->****
IDLineNum: array(1..MaxID) of Integer;
--<****v* LexData/LexData/LexData.LineCount
-- DESCRIPTION
-- Keeps track of what line the parser is on
-->****
LineCount: Integer := 0;
--<****v* LexData/LexData/LexData.IDCount
-- DESCRIPTION
-- Keeps track of how many ID's are in the symbol table
-->****
IDCount: Integer := 1;
--<****v* LexData/LexData/LexemeVector.LexemeVector
-- DESCRIPTION
-- Vector that holds all the Lexemes
-->****
LexemeVector: Lexeme_Vectors.Vector;
--<****v* LexData/LexData/LexemeVector.LexemeLineNum
-- DESCRIPTION
-- Vector that holds all the Lexemes line numbers
-->****
LexemeLineNum: LexLineNum_Vectors.Vector;
--<****v* LexData/LexData/LexemeVector.VectorCounter
-- DESCRIPTION
-- Keep track of how many Lexemes are in the vector
-->****
VectorCounter: Integer := 0;
--<****v* LexData/LexData/LexemeVector.CurrentVectorIdx
-- DESCRIPTION
-- Ponter for what lexeme is being proccessed in the parser
-->****
CurrentVectorIdx: Integer := 0;
--<****v* LexData/LexData/LexData.PastBegin
-- DESCRIPTION
-- If the lexeme reader has made it past the begin symbol or not
-->****
PastBegin: Boolean := False;
end LexData;