The Ada Program: parse.adb
1 -- parse.adb: categorized characters of a file
2
3 with Ada.Text_IO;
4 use Ada;
5
6 procedure Parse is
7
8 type Character_Class_Type is (Alphabetic, Numeric, Operator, Invalid);
9 Class : Character_Class_Type;
10 File_Name: constant String := "parse.adb";
11 File: Text_IO.File_Type;
12 Char: Character;
13
14 begin
15
16 Text_IO.Open (File=>File, Mode=>Text_IO.In_File, Name=>File_Name);
17 while not Text_IO.End_Of_File (File) loop
18 while not Text_IO.End_Of_Line (File) loop
19 Text_IO.Get (File=>File, Item=>Char);
20
21 case Char is
22 when 'A' .. 'Z' | 'a' .. 'z' =>
23 Class := Alphabetic;
24 when '0' .. '9' =>
25 Class := Numeric;
26 when '*' | '+' | '-' | '/' | '<' .. '>' =>
27 Class := Operator;
28 when others =>
29 Class := Invalid;
30 end case;
31
32 end loop;
33 Text_IO.Skip_Line (File); -- Move pointer in input buffer past EOL
34 end loop;
35
36 end Parse;