-
Notifications
You must be signed in to change notification settings - Fork 0
/
part_1.vhd
55 lines (52 loc) · 1.41 KB
/
part_1.vhd
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
-- VHDL 1076-2002, tested on Active-HDL 15
library ieee;
use ieee.NUMERIC_STD.all;
use ieee.std_logic_1164.all;
library std;
use std.TEXTIO.all;
entity Part1 is end;
architecture Driver of Part1 is
begin
process
file f: Text;
variable l: Line;
variable c: Character;
variable good: Boolean;
variable op1, op2: Integer;
variable total: Integer := 0;
begin
file_open(f, "input.txt", read_mode);
while not endfile(f) loop
readline(f, l);
good := True;
while l'Length > 0 and good loop
read(l, c, good);
next when not good or c /= 'm';
read(l, c, good);
next when not good or c /= 'u';
read(l, c, good);
next when not good or c /= 'l';
read(l, c, good);
next when not good or c /= '(';
op1 := 0;
read(l, c, good);
while good and c >= '0' and c <= '9' loop
op1 := op1*10 + integer'value("" & c);
read(l, c, good);
end loop;
next when not good or op1 = 0 or c /= ',';
op2 := 0;
read(l, c, good);
while good and c >= '0' and c <= '9' loop
op2 := op2*10 + integer'value("" & c);
read(l, c, good);
end loop;
next when not good or op2 = 0 or c /= ')';
total := total + op1*op2;
end loop;
end loop;
report "Total = " & integer'image(total);
file_close(f);
wait;
end process;
end;