hcl/lib2/h3-compilers.ads

203 lines
4.5 KiB
Ada
Raw Permalink Normal View History

2021-10-30 05:32:16 +00:00
with H3.Runes;
2021-10-30 01:57:19 +00:00
with H3.Strings;
2022-08-23 10:13:02 +00:00
with H3.Storage;
2021-12-08 15:43:33 +00:00
with H3.Trees;
2021-11-16 13:34:32 +00:00
with Ada.Finalization;
2021-11-07 17:32:50 +00:00
with Ada.Text_IO;
2021-10-30 01:57:19 +00:00
generic
type Rune_Type is (<>);
2022-08-23 10:13:02 +00:00
with package Storage_Pool_box is new H3.Storage.Pool_Box(<>);
2021-10-30 01:57:19 +00:00
package H3.Compilers is
2021-10-30 05:32:16 +00:00
package R is new H3.Runes(Rune_Type);
2022-08-23 10:13:02 +00:00
package S is new H3.Strings(Rune_Type, Storage_Pool_Box);
2021-10-30 01:57:19 +00:00
Syntax_Error: exception;
2022-08-23 10:13:02 +00:00
Internal_Error: exception;
2021-10-30 01:57:19 +00:00
2021-11-16 13:34:32 +00:00
--type Compiler is tagged limited private;
type Compiler is new Ada.Finalization.Limited_Controlled with private;
2021-10-30 01:57:19 +00:00
procedure Feed (C: in out Compiler; Data: in S.Rune_Array);
procedure End_Feed (C: in out Compiler);
2021-11-16 13:34:32 +00:00
overriding procedure Initialize (C: in out Compiler);
overriding procedure Finalize (C: in out Compiler);
2021-10-30 01:57:19 +00:00
private
type Token_Id is (
2021-12-01 17:06:30 +00:00
TK_ASSIGN,
2021-10-30 01:57:19 +00:00
TK_BSTR,
TK_BYTE,
TK_CHAR,
2021-12-01 17:06:30 +00:00
TK_COLON,
2021-10-30 01:57:19 +00:00
TK_CSTR,
TK_DIRECTIVE,
2021-11-16 13:34:32 +00:00
TK_DIV,
TK_DIVDIV,
2021-11-28 17:00:17 +00:00
TK_DOLLARED_LBRACE,
TK_DOLLARED_LBRACK,
TK_DOLLARED_LPAREN,
2021-10-30 01:57:19 +00:00
TK_EOF,
TK_EOL,
2021-11-28 17:00:17 +00:00
TK_HASHED_LBRACE,
TK_HASHED_LBRACK,
TK_HASHED_LPAREN,
2021-10-30 01:57:19 +00:00
TK_IDENT,
TK_GE,
TK_GT,
2021-11-28 17:00:17 +00:00
TK_LBRACE,
TK_LBRACK,
2021-10-30 01:57:19 +00:00
TK_LE,
2021-11-28 17:00:17 +00:00
TK_LPAREN,
2021-10-30 01:57:19 +00:00
TK_LT,
2021-11-16 13:34:32 +00:00
TK_MINUS,
TK_MINUSMINUS,
TK_MUL,
TK_MULMUL,
TK_PLUS,
TK_PLUSPLUS,
2021-11-28 17:00:17 +00:00
TK_RBRACE,
TK_RBRACK,
TK_RPAREN,
2021-10-30 01:57:19 +00:00
TK_SEMICOLON
);
type Token is record
Id: Token_Id := TK_EOF;
Buf: S.Elastic_String;
end record;
2022-08-23 10:13:02 +00:00
-- ------------------------------------------------------------------
type Location is record
line: System_Size := 0;
colm: System_Size := 0;
-- file: S.Bounded_String_Pointer := null;
end record;
package Feeder is
type Lex_State_Code is (LX_START, LX_COMMENT, LX_DT, LX_HC);
type Lex_Data(State: Lex_State_Code := LX_START) is record
case State is
when LX_START =>
null;
when LX_COMMENT =>
null;
when LX_DT =>
Row_Start: Integer;
Row_End: Integer;
Col_NexT: Integer;
when LX_HC =>
Char_Count: System_Size;
end case;
end record;
type Lex is record
loc: Location;
oloc: Location;
data: Lex_Data;
end record;
type Read is record
level: Integer;
flagv: Integer;
expect_include_file: Boolean;
expect_vlist_item: Boolean;
do_include_file: Boolean;
-- TODO: obj: Cnode;
end record;
type Feed is record
lx: Lex;
rd: Read;
end record;
procedure Start (C: in out Compiler; Code: in R.Code; Consumed: out Boolean);
procedure Comment (C: in out Compiler; Code: in R.Code; Consumed: out Boolean);
procedure Delim_Token (C: in out Compiler; Code: in R.Code; Consumed: out Boolean);
procedure Hmarked_Token (C: in out Compiler; Code: in R.Code; Consumed: out Boolean);
procedure Update_Location (C: in out Compiler; Code: in R.Code);
procedure Begin_Include (C: in out Compiler);
procedure Feed_From_Includee (C: in out Compiler);
end Feeder;
-- ------------------------------------------------------------------
package Parser is
-- move parser types here.
end Parser;
2021-11-16 13:34:32 +00:00
-- ------------------------------------------------------------------
type Parse_State_Code is (
2021-11-07 17:32:50 +00:00
PS_START,
2021-12-01 17:06:30 +00:00
2021-11-14 15:07:41 +00:00
PS_INCLUDE_TARGET,
2021-12-01 17:06:30 +00:00
PS_INCLUDE_TERMINATOR,
PS_CLASS_1,
2021-12-03 06:38:20 +00:00
PS_CLASS_2,
PS_FUN_1,
PS_FUN_2,
PS_PLAIN_STATEMENT_START
);
type Parse_Data_Code is (
PD_VOID,
PD_STATEMENT,
PD_ASSIGNMENT
2021-11-07 17:32:50 +00:00
);
2021-11-16 13:34:32 +00:00
2021-12-03 06:38:20 +00:00
type Parse_Data(Code: Parse_Data_Code := PD_VOID) is record
case Code is
when PD_VOID =>
null;
when PD_STATEMENT =>
2021-12-05 16:13:36 +00:00
Stmt_Starter: S.Elastic_String;
2021-12-03 06:38:20 +00:00
when PD_ASSIGNMENT =>
2021-12-05 16:13:36 +00:00
Assign_Starter: S.Elastic_String;
2021-12-03 06:38:20 +00:00
end case;
end record;
2021-11-16 13:34:32 +00:00
type Parse_State is record
Current: Parse_State_Code := PS_START;
2021-12-03 06:38:20 +00:00
Data: Parse_Data;
2021-11-16 13:34:32 +00:00
end record;
type Parse_State_Array is array(System_Index range<>) of Parse_State;
type Parse_State_Stack(Capa: System_Index) is record
States: Parse_State_Array(System_Index'First .. Capa);
Top: System_Size := System_Size'First; -- 0
2021-11-14 15:07:41 +00:00
end record;
2021-11-16 13:34:32 +00:00
-- ------------------------------------------------------------------
2021-11-14 15:07:41 +00:00
type Stream is record
Handle: Ada.Text_IO.File_Type;
2021-11-16 13:34:32 +00:00
Prs_Level: System_Index;
2021-11-14 15:07:41 +00:00
end record;
type Stream_Array is array(System_Index range <>) of Stream;
2021-11-16 13:34:32 +00:00
2021-11-14 15:07:41 +00:00
type Include_Stack(Capa: System_Index) is record
Streams: Stream_Array(System_Index'First .. Capa);
2021-11-16 13:34:32 +00:00
Top: System_Size := System_Size'First; -- 0
2021-10-30 01:57:19 +00:00
end record;
2021-11-16 13:34:32 +00:00
-- ------------------------------------------------------------------
2021-10-30 01:57:19 +00:00
2021-11-16 13:34:32 +00:00
--type Compiler is tagged limited record
type Compiler is new Ada.Finalization.Limited_Controlled with record
2022-08-23 10:13:02 +00:00
F: Feeder.Feed;
2021-10-30 01:57:19 +00:00
Tk: Token;
2021-11-16 13:34:32 +00:00
Prs: Parse_State_Stack(128); -- TODO: make this dynamic. single access type. dynamic allocation
Inc: Include_Stack(32); -- TODO: make this dynamic. single access type. dynamic allocation
2022-08-23 10:13:02 +00:00
2021-10-30 01:57:19 +00:00
end record;
2021-11-16 13:34:32 +00:00
2021-10-30 05:32:16 +00:00
end H3.Compilers;