hcl/lib2/h3-compilers.ads

80 lines
1.4 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-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-07 17:32:50 +00:00
type Compiler is tagged limited 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);
private
type Lexer_State is (
LX_START,
2021-11-12 23:31:25 +00:00
2021-10-30 01:57:19 +00:00
LX_COMMENT,
2021-11-12 23:31:25 +00:00
LX_CSTR,
LX_DIRECTIVE,
2021-10-30 01:57:19 +00:00
LX_IDENT,
LX_NUMBER,
LX_OP_GREATER,
LX_OP_LESS
);
type Lexer is record
State: Lexer_State := LX_START;
end record;
2021-11-07 17:32:50 +00:00
type Stream is record
Handle: Ada.Text_IO.File_Type;
--Handle: System_Size;
end record;
type Stream_Array is array(System_Index range <>) of Stream;
type Stream_Stack(Capa: System_Index) is record
Items: Stream_Array(System_Index'First .. Capa);
Top: System_Size := 0;
end record;
2021-10-30 01:57:19 +00:00
type Token_Id is (
TK_BSTR,
TK_BYTE,
TK_CHAR,
TK_CSTR,
TK_DIRECTIVE,
2021-10-30 01:57:19 +00:00
TK_EOF,
TK_EOL,
TK_IDENT,
TK_GE,
TK_GT,
TK_LE,
TK_LT,
TK_SEMICOLON
);
type Token is record
Id: Token_Id := TK_EOF;
Buf: S.Elastic_String;
end record;
2021-11-07 17:32:50 +00:00
type Parser_State is (
PS_START,
PS_INCLUDE
);
2021-10-30 01:57:19 +00:00
type Parser is record
2021-11-07 17:32:50 +00:00
State: Parser_State := PS_START;
2021-10-30 01:57:19 +00:00
end record;
2021-11-07 17:32:50 +00:00
type Compiler is tagged limited record
2021-10-30 01:57:19 +00:00
Lx: Lexer;
Tk: Token;
2021-11-07 17:32:50 +00:00
Ps: Parser;
St: Stream_Stack(32);
2021-10-30 01:57:19 +00:00
end record;
2021-10-30 05:32:16 +00:00
end H3.Compilers;