69 lines
1.7 KiB
Ada
69 lines
1.7 KiB
Ada
with Ada.Text_IO; use Ada.Text_IO;
|
|
with Ada.Strings.Unbounded;
|
|
with Ada.Containers.Vectors;
|
|
|
|
procedure Day_7 is
|
|
|
|
package Ustr renames Ada.Strings.Unbounded;
|
|
|
|
type Instruction_Operator is (
|
|
OP_INVALID,
|
|
OP_STORE,
|
|
OP_AND,
|
|
OP_OR,
|
|
OP_NOT,
|
|
OP_LEFTSHIFT,
|
|
OP_RIGHTSHIFT
|
|
);
|
|
|
|
type Instruction( Op : Instruction_Operator := OP_STORE) is
|
|
record
|
|
Dest : Ustr.Unbounded_String;
|
|
case Op is
|
|
when OP_STORE =>
|
|
Data : Natural;
|
|
when OP_AND | OP_OR =>
|
|
Left_Op, Right_Op : Ustr.Unbounded_String;
|
|
when OP_NOT =>
|
|
Uni_Op : Ustr.Unbounded_String;
|
|
when OP_LEFTSHIFT | OP_RIGHTSHIFT =>
|
|
Shift_Op : Ustr.Unbounded_String;
|
|
Shift : Natural;
|
|
when others =>
|
|
null;
|
|
end case;
|
|
end record;
|
|
|
|
type Instructions is array (Natural range <>) of Instruction;
|
|
|
|
function Read_File( File_Name : String ) return Instructions is
|
|
package vec is new Ada.Containers.Vectors(
|
|
Natural, Instruction);
|
|
|
|
DVec : vec.Vector;
|
|
|
|
File : File_Type;
|
|
begin
|
|
open(File, In_File, File_Name);
|
|
|
|
while not End_Of_File(File) loop
|
|
Put_Line(Get_Line(File));
|
|
end loop;
|
|
|
|
close(File);
|
|
|
|
return Instrs : Instructions( 0 .. Natural(DVec.Length) - 1) do
|
|
for I in Instrs'range loop
|
|
Instrs(I) := DVec(I);
|
|
end loop;
|
|
end return;
|
|
end Read_File;
|
|
|
|
File_Name : String := "input_day_7.txt";
|
|
|
|
begin
|
|
|
|
Put_Line(Read_File(File_Name)'Image);
|
|
|
|
end Day_7;
|