more structural parsing

This commit is contained in:
2021-11-16 13:34:32 +00:00
parent 5e40282416
commit 50c6b243f9
3 changed files with 205 additions and 87 deletions

View File

@ -1,5 +1,6 @@
with H3.Runes;
with H3.Strings;
with Ada.Finalization;
with Ada.Text_IO;
generic
@ -10,11 +11,15 @@ package H3.Compilers is
Syntax_Error: exception;
type Compiler is tagged limited private;
--type Compiler is tagged limited private;
type Compiler is new Ada.Finalization.Limited_Controlled with private;
procedure Feed (C: in out Compiler; Data: in S.Rune_Array);
procedure End_Feed (C: in out Compiler);
overriding procedure Initialize (C: in out Compiler);
overriding procedure Finalize (C: in out Compiler);
private
type Lexer_State is (
LX_START,
@ -24,8 +29,12 @@ private
LX_DIRECTIVE,
LX_IDENT,
LX_NUMBER,
LX_OP_DIV,
LX_OP_GREATER,
LX_OP_LESS
LX_OP_LESS,
LX_OP_MINUS,
LX_OP_MUL,
LX_OP_PLUS
);
type Lexer is record
State: Lexer_State := LX_START;
@ -37,6 +46,8 @@ private
TK_CHAR,
TK_CSTR,
TK_DIRECTIVE,
TK_DIV,
TK_DIVDIV,
TK_EOF,
TK_EOL,
TK_IDENT,
@ -44,6 +55,12 @@ private
TK_GT,
TK_LE,
TK_LT,
TK_MINUS,
TK_MINUSMINUS,
TK_MUL,
TK_MULMUL,
TK_PLUS,
TK_PLUSPLUS,
TK_SEMICOLON
);
type Token is record
@ -51,37 +68,46 @@ private
Buf: S.Elastic_String;
end record;
type Parser_State is (
-- ------------------------------------------------------------------
type Parse_State_Code is (
PS_START,
PS_INCLUDE_TARGET,
PS_INCLUDE_TERMINATOR
);
type Parser is record
State: Parser_State := PS_START;
Prev_State: Parser_State := PS_START;
Level: System_Index := 1;
type Parse_State is record
Current: Parse_State_Code := PS_START;
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
end record;
-- ------------------------------------------------------------------
type Stream is record
Handle: Ada.Text_IO.File_Type;
--Handle: System_Size;
Initial_Level: System_Index; -- the block level where this inclusion is entered
Initial_Parser_State: Parser_State; -- the parser state before the #include has been seen?
Next_Parser_State: Parser_State;
Prs_Level: System_Index;
end record;
type Stream_Array is array(System_Index range <>) of Stream;
type Include_Stack(Capa: System_Index) is record
Streams: Stream_Array(System_Index'First .. Capa);
Top: System_Size := 0;
Top: System_Size := System_Size'First; -- 0
end record;
-- ------------------------------------------------------------------
type Compiler is tagged limited record
--type Compiler is tagged limited record
type Compiler is new Ada.Finalization.Limited_Controlled with record
Lx: Lexer;
Tk: Token;
Ps: Parser;
Inc: Include_Stack(32);
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
end record;
end H3.Compilers;