Merge pull request #102 from Servostar/92-implement-parenthesis-in-expressions

refactored transmute rule and added bracketed expressions
This commit is contained in:
servostar 2024-05-28 19:18:26 +02:00 committed by GitHub
commit 90bb76a37b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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"); };