refactored transmute rule and added bracketed expressions

This commit is contained in:
Sven Vogel 2024-05-26 14:09:53 +02:00
parent fc80e23917
commit 8c17749923
2 changed files with 7 additions and 4 deletions

View File

@ -52,6 +52,7 @@
"float" {DEBUG("\"%s\" tokenized with \'KeyFloat\'", yytext); return(KeyFloat);};
"self" {DEBUG("\"%s\" tokenized with \'KeySelf\'", yytext); return(KeySelf);};
"as" {DEBUG("\"%s\" tokenized with \'KeyAs'", yytext); return (KeyAs);};
"to" {DEBUG("\"%s\" tokenized with \'KeyTo'", yytext); return (KeyTo);};
"short" {DEBUG("\"%s\" tokenized with \'KeyShort\'", yytext); return(KeyShort);};
"long" {DEBUG("\"%s\" tokenized with \'KeyLong\'", yytext); return(KeyLong);};
"half" {DEBUG("\"%s\" tokenized with \'KeyHalf\'", yytext); return(KeyHalf);};

View File

@ -72,6 +72,7 @@
%token KeyFloat
%token KeySelf
%token KeyAs
%token KeyTo
%token <string> ValInt
%token <string> Ident
%token <string> ValFloat
@ -128,7 +129,7 @@
%left '+' '-'
%left '*' '/'
%left OpNot OpBitnot
%left KeyAs
%left KeyAs KeyTo
%left '(' ')'
%%
@ -154,6 +155,7 @@ expr: ValFloat {$$ = AST_new_node(AST_Float, $1);}
| boxselfaccess{$$ = $1;}
| typecast{$$ = $1;}
| reinterpretcast{$$ = $1;}
| '(' expr ')' {$$=$2;}
exprlist: expr ',' exprlist {AST_push_node($3, $1);
$$ = $3;}
@ -289,9 +291,9 @@ typecast: expr KeyAs type %prec KeyAs {AST_NODE_PTR cast = AST_new_node(AST_Typ
$$ = cast;
DEBUG("Type-Cast"); };
reinterpretcast: '(' type ')' expr { AST_NODE_PTR cast = AST_new_node(AST_Transmute, NULL);
AST_push_node(cast, $4);
AST_push_node(cast, $2);
reinterpretcast: expr KeyTo type %prec KeyTo { AST_NODE_PTR cast = AST_new_node(AST_Transmute, NULL);
AST_push_node(cast, $1);
AST_push_node(cast, $3);
$$ = cast;
DEBUG("Reinterpret-Cast"); };