From 82824a4bf2b72d7e078e1f17a962f06e842bb5d3 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Wed, 6 Mar 2024 14:19:37 -0500 Subject: [PATCH] Avoid using Bison's typed mid-rule actions These work with `%union`, but will not work with C++ `variant` --- src/asm/parser.y | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/asm/parser.y b/src/asm/parser.y index a15d3c5e..b40d7432 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -266,6 +266,9 @@ %token T_SECT_WRAM0 "WRAM0" T_SECT_WRAMX "WRAMX" T_SECT_HRAM "HRAM" %token T_SECT_VRAM "VRAM" T_SECT_SRAM "SRAM" T_SECT_OAM "OAM" +%type capture_rept +%type capture_macro + %type sectmod %type macroargs @@ -834,10 +837,8 @@ load: ; rept: - T_POP_REPT uconst T_NEWLINE { - $$ = lexer_CaptureRept(captureBody); - } endofline { - if ($4) + T_POP_REPT uconst T_NEWLINE capture_rept endofline { + if ($4) fstk_RunRept($2, captureBody.lineNo, captureBody.body, captureBody.size); } ; @@ -847,10 +848,8 @@ for: lexer_ToggleStringExpansion(false); } T_ID { lexer_ToggleStringExpansion(true); - } T_COMMA for_args T_NEWLINE { - $$ = lexer_CaptureRept(captureBody); - } endofline { - if ($8) + } T_COMMA for_args T_NEWLINE capture_rept endofline { + if ($8) fstk_RunFor( $3, $6.start, @@ -863,6 +862,12 @@ for: } ; +capture_rept: + %empty { + $$ = lexer_CaptureRept(captureBody); + } +; + for_args: const { $$.start = 0; @@ -893,14 +898,18 @@ macrodef: lexer_ToggleStringExpansion(false); } T_ID { lexer_ToggleStringExpansion(true); - } T_NEWLINE { - $$ = lexer_CaptureMacroBody(captureBody); - } endofline { - if ($6) + } T_NEWLINE capture_macro endofline { + if ($6) sym_AddMacro($3, captureBody.lineNo, captureBody.body, captureBody.size); } ; +capture_macro: + %empty { + $$ = lexer_CaptureMacroBody(captureBody); + } +; + rsset: T_POP_RSSET uconst { sym_AddVar("_RS", $2); @@ -1170,7 +1179,7 @@ print_expr: printf("$%" PRIX32, $1); } | string { - printf("%s", $1); + fputs($1, stdout); } ;