From eccce505e56e7a182389fab3a1a249379b1a0279 Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Sun, 12 May 2024 22:54:58 +0200 Subject: [PATCH 1/9] -added Type-Cast -added Reinterpret-Cast --- src/yacc/parser.y | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index ddcae10..654e0a8 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -96,6 +96,10 @@ IOqualifyier: KeyIn | KeyOut KeyIn | ; +typecast: expr KeyAs type { DEBUG("Type-Cast"); }; + +reinterpretcast: '(' type ')' expr { DEBUG("Reinterpret-Cast"); }; + paramdecl: type ':' Ident { DEBUG("Param-Declaration"); }; funcall: Ident argumentlist { DEBUG("Function call"); }; @@ -131,7 +135,9 @@ identlist: Ident ',' identlist decl: type ':' identlist; -definition: decl '=' expr { DEBUG("Definition"); }; +definition: decl '=' expr { DEBUG("Definition"); } + | decl '=' typecast { DEBUG("Definition"); }; + | decl '=' reinterpretcast { DEBUG("Definition"); }; assign: Ident '=' expr { DEBUG("Assignment"); }; From 9eba9d1437dda4710e51bece656b7ee981a9a4a9 Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Mon, 13 May 2024 13:45:22 +0200 Subject: [PATCH 2/9] fixed shift-reduce conflict --- src/yacc/parser.y | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 78c2948..c9cd81f 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -62,6 +62,7 @@ %left OpEquals OpNot '<' '>' %left OpAnd OpOr OpXor %left OpBitand OpBitor OpBitxor OpBitnot +%nonassoc KeyAs '(' ')' %% program: program programbody @@ -74,8 +75,6 @@ programbody: moduleimport | decl | typedef; - - expr: ValFloat | ValInt | ValMultistr @@ -83,7 +82,9 @@ expr: ValFloat | Ident | operation | boxaccess - | boxselfaccess; + | boxselfaccess + | typecast + | reinterpretcast; exprlist: expr ',' exprlist | expr; @@ -166,10 +167,7 @@ identlist: Ident ',' identlist decl: type ':' identlist | storagequalifier type ':' identlist - -definition: decl '=' expr { DEBUG("Definition"); } - | decl '=' typecast { DEBUG("Definition"); }; - | decl '=' reinterpretcast { DEBUG("Definition"); }; +definition: decl '=' expr { DEBUG("Definition"); }; storagequalifier: KeyGlobal | KeyStatic From 7da3c9151d669a830a67c91227cfa516412ec635 Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Wed, 15 May 2024 15:50:26 +0200 Subject: [PATCH 3/9] fixed shift reduce conflicts in typecast --- src/yacc/parser.y | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index c9cd81f..f02fad7 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -58,11 +58,18 @@ /* Operator associativity */ %right '=' -%left '+' '-' '*' '/' -%left OpEquals OpNot '<' '>' -%left OpAnd OpOr OpXor -%left OpBitand OpBitor OpBitxor OpBitnot -%nonassoc KeyAs '(' ')' +%left OpOr +%left OpXor +%left OpAnd +%left OpBitor +%left OpBitxor +%left OpBitand +%left OpEquals '<' '>' +%left '+' '-' +%left '*' '/' +%left OpNot OpBitnot +%left KeyAs +%left '(' ')' %% program: program programbody @@ -109,7 +116,7 @@ IOqualifyier: KeyIn | KeyOut KeyIn | ; -typecast: expr KeyAs type { DEBUG("Type-Cast"); }; +typecast: expr KeyAs type %prec KeyAs { DEBUG("Type-Cast"); }; reinterpretcast: '(' type ')' expr { DEBUG("Reinterpret-Cast"); }; From 2757132cf21c916ddbd2980e590b1f9abb909056 Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Thu, 16 May 2024 10:27:44 +0200 Subject: [PATCH 4/9] Fixed Typo --- src/yacc/parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 471948f..3a5c92c 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -283,7 +283,7 @@ boxcall: boxaccess argumentlist {AST_NODE_PTR boxcall = AST_new_node(AST_Call, N $$ = boxcall;}; -typecast: expr KeyAs type %prec KeyAs {{AST_NODE_PTR reinterpretcast = AST_new_node(AST_reinterpretcast, NULL); +typecast: expr KeyAs type %prec KeyAs {AST_NODE_PTR reinterpretcast = AST_new_node(AST_reinterpretcast, NULL); $$ = typecast; DEBUG("Type-Cast"); }; From e57682d717704c807545c2064152636fefe55d8c Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Thu, 16 May 2024 11:34:51 +0200 Subject: [PATCH 5/9] changed node-name according to ast.h --- src/yacc/parser.y | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 3a5c92c..ece2282 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -283,12 +283,10 @@ boxcall: boxaccess argumentlist {AST_NODE_PTR boxcall = AST_new_node(AST_Call, N $$ = boxcall;}; -typecast: expr KeyAs type %prec KeyAs {AST_NODE_PTR reinterpretcast = AST_new_node(AST_reinterpretcast, NULL); - $$ = typecast; +typecast: expr KeyAs type %prec KeyAs {$$ = AST_new_node(AST_Typecast, $1); DEBUG("Type-Cast"); }; -reinterpretcast: '(' type ')' expr {AST_NODE_PTR reinterpretcast = AST_new_node(AST_reinterpretcast, NULL); - $$ = reinterpretcast; +reinterpretcast: '(' type ')' expr {$$ = AST_new_node(AST_Transmute, $4); DEBUG("Reinterpret-Cast"); }; From 8d7c6a4a2b41969423c6e7408fab5666ec1b1a62 Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Thu, 16 May 2024 18:04:02 +0200 Subject: [PATCH 6/9] changed ast implementation for cast --- CMakeLists.txt | 2 +- src/yacc/parser.y | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 213143c..ced5f45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,7 +62,7 @@ set(YACC_GENERATED_SOURCE_FILE ${PROJECT_SOURCE_DIR}/src/yacc/parser.tab.c) add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE} - COMMAND bison + COMMAND yacc ARGS -Wno-yacc -Wcounterexamples -d -o ${YACC_GENERATED_SOURCE_FILE} ${YACC_SOURCE_FILE} COMMENT "generate C source file for parser" diff --git a/src/yacc/parser.y b/src/yacc/parser.y index ece2282..753c7bc 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -283,10 +283,16 @@ boxcall: boxaccess argumentlist {AST_NODE_PTR boxcall = AST_new_node(AST_Call, N $$ = boxcall;}; -typecast: expr KeyAs type %prec KeyAs {$$ = AST_new_node(AST_Typecast, $1); +typecast: expr KeyAs type %prec KeyAs {AST_NODE_PTR cast = AST_new_node(AST_Typecast, NULL); + AST_push_node(cast, $1); + AST_push_node(cast, $3); + $$ = cast; DEBUG("Type-Cast"); }; -reinterpretcast: '(' type ')' expr {$$ = AST_new_node(AST_Transmute, $4); +reinterpretcast: '(' type ')' expr { AST_NODE_PTR cast = AST_new_node(AST_Transmute, NULL); + AST_push_node(cast, $4); + AST_push_node(cast, $2); + $$ = cast; DEBUG("Reinterpret-Cast"); }; From 58f7170df63ec42b4f1dedc3628b1117da3ba362 Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Tue, 21 May 2024 12:20:45 +0200 Subject: [PATCH 7/9] changed lookuptable for casts in ast.c --- src/ast/ast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ast/ast.c b/src/ast/ast.c index e503e1e..892af1f 100644 --- a/src/ast/ast.c +++ b/src/ast/ast.c @@ -70,8 +70,8 @@ void AST_init() { lookup_table[AST_Fun] = "fun"; lookup_table[AST_Call] = "funcall"; - lookup_table[AST_Typecast] = "cast"; - lookup_table[AST_Transmute] = "as"; + lookup_table[AST_Typecast] = "typecast"; + lookup_table[AST_Transmute] = "transmute"; lookup_table[AST_Condition] = "condition"; lookup_table[AST_List] = "list"; lookup_table[AST_ExprList] = "expr list"; From 0e098db7261fea530cdb7b33d5d538294dbb2f0d Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Tue, 21 May 2024 12:21:54 +0200 Subject: [PATCH 8/9] Update test_ast.py --- tests/ast/test_ast.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ast/test_ast.py b/tests/ast/test_ast.py index 28407f9..e3e5d48 100644 --- a/tests/ast/test_ast.py +++ b/tests/ast/test_ast.py @@ -58,8 +58,8 @@ def run_check_print_node(): 27 == 28 > 29 < -30 cast -31 as +30 typecast +31 transmute 32 funcall 33 value 34 typedef From 1d7fb31da56d6784a9de4d950c6a429d8338acfd Mon Sep 17 00:00:00 2001 From: SirTalksalot75 <132705706+SirTalksalot75@users.noreply.github.com> Date: Tue, 21 May 2024 14:20:15 +0200 Subject: [PATCH 9/9] Update CMakeLists.txt changed yacc ->bison --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ced5f45..213143c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,7 +62,7 @@ set(YACC_GENERATED_SOURCE_FILE ${PROJECT_SOURCE_DIR}/src/yacc/parser.tab.c) add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE} - COMMAND yacc + COMMAND bison ARGS -Wno-yacc -Wcounterexamples -d -o ${YACC_GENERATED_SOURCE_FILE} ${YACC_SOURCE_FILE} COMMENT "generate C source file for parser"