added include rule to lexer and parser

This commit is contained in:
Sven Vogel 2024-07-18 18:27:34 +02:00
parent db501b4b9e
commit 938a5c7fdf
3 changed files with 8 additions and 0 deletions

View File

@ -79,6 +79,7 @@ enum AST_SyntaxElement_t {
AST_AddressOf,
AST_Dereference,
AST_Reference,
AST_Include,
AST_ELEMENT_COUNT
};

View File

@ -81,6 +81,7 @@
"!" {DEBUG("\"%s\" tokenized with \'OpBitnot\'", yytext); return(OpBitnot);};
"^" {DEBUG("\"%s\" tokenized with \'OpBitxor\'", yytext); return(OpBitxor);};
"import" {DEBUG("\"%s\" tokenized with \'KeyImport\'", yytext); return(KeyImport);};
"include" {DEBUG("\"%s\" tokenized with \'KeyInclude\'", yytext); return(KeyInclude);};
"silent" {DEBUG("\"%s\" tokenized with \'KeySilent\'", yytext); return(KeySilent);};
"box" {DEBUG("\"%s\" tokenized with \'KeyBox\'", yytext); return(KeyBox);};
"typeof" {DEBUG("\"%s\" tokenized with \'FunTypeof\'", yytext); return(FunTypeof);};

View File

@ -53,6 +53,7 @@
%type <node_ptr> opbool
%type <node_ptr> opbit
%type <node_ptr> moduleimport
%type <node_ptr> moduleinclude
%type <node_ptr> programbody
%type <node_ptr> fundef
%type <node_ptr> fundecl
@ -109,6 +110,7 @@
%token OpBitnot
%token OpBitxor
%token KeyImport
%token KeyInclude
%token KeySilent
%token KeyBox
%token FunTypeof
@ -142,6 +144,7 @@ program: program programbody {AST_push_node(root, $2);
| programbody {AST_push_node(root, $1);};
programbody: moduleimport {$$ = $1;}
| moduleinclude {$$ = $1;}
| fundef{$$ = $1;}
| fundecl{$$ = $1;}
| box{$$ = $1;}
@ -328,6 +331,9 @@ funcall: Ident argumentlist {AST_NODE_PTR funcall = AST_new_node(new_loc(), AST_
moduleimport: KeyImport ValStr {$$ = AST_new_node(new_loc(), AST_Import, $2);
DEBUG("Module-Import"); };
moduleinclude: KeyInclude ValStr {$$ = AST_new_node(new_loc(), AST_Include, $2);
DEBUG("Module-Include"); };
statementlist: statementlist statement {AST_push_node($1, $2);
$$ = $1;}
| statement {AST_NODE_PTR list = AST_new_node(new_loc(), AST_StmtList, NULL);