hcl/lib2/h3-compilers.ads

158 lines
3.1 KiB
Ada
Raw 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;
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 (<>);
package H3.Compilers is
2021-10-30 05:32:16 +00:00
package R is new H3.Runes(Rune_Type);
2021-10-30 01:57:19 +00:00
package S is new H3.Strings(Rune_Type);
Syntax_Error: exception;
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 Lexer_State is (
LX_START,
2021-11-12 23:31:25 +00:00
2021-12-01 17:06:30 +00:00
LX_COLON,
2021-10-30 01:57:19 +00:00
LX_COMMENT,
2021-11-12 23:31:25 +00:00
LX_CSTR,
LX_DIRECTIVE,
2021-11-28 17:00:17 +00:00
LX_DOLLARED,
LX_HASHED,
2021-10-30 01:57:19 +00:00
LX_IDENT,
LX_NUMBER,
2021-11-16 13:34:32 +00:00
LX_OP_DIV,
2021-10-30 01:57:19 +00:00
LX_OP_GREATER,
2021-11-16 13:34:32 +00:00
LX_OP_LESS,
LX_OP_MINUS,
LX_OP_MUL,
LX_OP_PLUS
2021-10-30 01:57:19 +00:00
);
type Lexer is record
State: Lexer_State := LX_START;
end record;
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;
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 =>
Cmd_Name: S.Elastic_String;
when PD_ASSIGNMENT =>
Var_Name: S.Elastic_String;
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
2021-10-30 01:57:19 +00:00
Lx: Lexer;
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
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;