added reference type definition

added reference access (array)
This commit is contained in:
Sven Vogel 2024-06-03 15:58:41 +02:00
parent dda040c996
commit 8f3bef3b95
4 changed files with 19 additions and 3 deletions

View File

@ -84,6 +84,9 @@ void AST_init() {
lookup_table[AST_Negate] = "-"; lookup_table[AST_Negate] = "-";
lookup_table[AST_Parameter] = "parameter"; lookup_table[AST_Parameter] = "parameter";
lookup_table[AST_ParamDecl] = "parameter-declaration"; lookup_table[AST_ParamDecl] = "parameter-declaration";
lookup_table[AST_AddressOf] = "address of";
lookup_table[AST_Dereference] = "deref";
lookup_table[AST_Reference] = "ref";
} }
const char* AST_node_to_string(const struct AST_Node_t* node) { const char* AST_node_to_string(const struct AST_Node_t* node) {

View File

@ -76,6 +76,9 @@ enum AST_SyntaxElement_t {
AST_Parameter, AST_Parameter,
AST_Qualifyier, AST_Qualifyier,
AST_ParamDecl, AST_ParamDecl,
AST_AddressOf,
AST_Dereference,
AST_Reference,
AST_ELEMENT_COUNT AST_ELEMENT_COUNT
}; };

View File

@ -98,7 +98,7 @@
yytext[yyleng - 2] = 0; yytext[yyleng - 2] = 0;
DEBUG("\"%s\" tokenized with \'ValStr\'", yytext); yylval.string = strdup(yytext); return(ValStr);}; DEBUG("\"%s\" tokenized with \'ValStr\'", yytext); yylval.string = strdup(yytext); return(ValStr);};
\"\"\"([^\"\n]|\\\n)*\"\"\" { \"\"\"[^\"]*\"\"\" {
yytext = yytext +3; yytext = yytext +3;
yytext[yyleng - 4] = 0; yytext[yyleng - 4] = 0;

View File

@ -132,7 +132,7 @@
%left '*' '/' %left '*' '/'
%left OpNot OpBitnot %left OpNot OpBitnot
%left KeyAs KeyTo %left KeyAs KeyTo
%left '(' ')' %left '(' ')' '[' ']'
%% %%
program: program programbody {AST_push_node(root, $2);} program: program programbody {AST_push_node(root, $2);}
@ -158,6 +158,13 @@ expr: ValFloat {$$ = AST_new_node(new_loc(), AST_Float, $1);}
| typecast{$$ = $1;} | typecast{$$ = $1;}
| reinterpretcast{$$ = $1;} | reinterpretcast{$$ = $1;}
| '(' expr ')' {$$=$2;} | '(' expr ')' {$$=$2;}
| KeyRef Ident {AST_NODE_PTR addrof = AST_new_node(new_loc(), AST_AddressOf, NULL);
AST_push_node(addrof, AST_new_node(new_loc(), AST_Ident, $2));
$$ = addrof;}
| expr '[' expr ']' {AST_NODE_PTR deref = AST_new_node(new_loc(), AST_Dereference, NULL);
AST_push_node(deref, $1);
AST_push_node(deref, $3);
$$ = deref;};
exprlist: expr ',' exprlist {AST_push_node($3, $1); exprlist: expr ',' exprlist {AST_push_node($3, $1);
$$ = $3;} $$ = $3;}
@ -449,7 +456,10 @@ type: typekind {AST_NODE_PTR type = AST_new_node(new_loc(), AST_Type, NULL);
AST_push_node(type, $1); AST_push_node(type, $1);
AST_push_node(type, $2); AST_push_node(type, $2);
AST_push_node(type, $3); AST_push_node(type, $3);
$$ = type;}; $$ = type;}
| KeyRef type {AST_NODE_PTR reftype = AST_new_node(new_loc(), AST_Reference, NULL);
AST_push_node(reftype, $2);
$$ = reftype; };
operation: oparith {$$ = $1;} operation: oparith {$$ = $1;}
| oplogic {$$ = $1;} | oplogic {$$ = $1;}