From d9d381cb625cceaf5665cc0adc1de64c35cae7e5 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Tue, 4 Feb 2025 14:24:00 +0100 Subject: [PATCH] Refactor the parser to have fewer `*_no_str` intermediate rules --- src/asm/parser.y | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/src/asm/parser.y b/src/asm/parser.y index 279cd7d97..e6b82c5ca 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -327,14 +327,11 @@ %type relocexpr %type relocexpr_no_str %type reloc_8bit -%type reloc_8bit_no_str %type reloc_8bit_offset %type reloc_16bit -%type reloc_16bit_no_str // Constant numbers %type iconst -%type const_no_str %type uconst // Constant numbers used only in specific contexts %type bit_const @@ -1226,8 +1223,8 @@ print_exprs: ; print_expr: - const_no_str { - printf("$%" PRIX32, $1); + relocexpr_no_str { + printf("$%" PRIX32, $1.getConstVal()); } | string { // Allow printing NUL characters @@ -1251,7 +1248,8 @@ constlist_8bit: ; constlist_8bit_entry: - reloc_8bit_no_str { + relocexpr_no_str { + $1.checkNBit(8); sect_RelByte($1, 0); } | string { @@ -1266,7 +1264,8 @@ constlist_16bit: ; constlist_16bit_entry: - reloc_16bit_no_str { + relocexpr_no_str { + $1.checkNBit(16); sect_RelWord($1, 0); } | string { @@ -1297,13 +1296,6 @@ reloc_8bit: } ; -reloc_8bit_no_str: - relocexpr_no_str { - $$ = std::move($1); - $$.checkNBit(8); - } -; - reloc_8bit_offset: OP_ADD relocexpr { $$ = std::move($2); @@ -1322,13 +1314,6 @@ reloc_16bit: } ; -reloc_16bit_no_str: - relocexpr_no_str { - $$ = std::move($1); - $$.checkNBit(16); - } -; - relocexpr: relocexpr_no_str { $$ = std::move($1); @@ -1545,12 +1530,6 @@ iconst: } ; -const_no_str: - relocexpr_no_str { - $$ = $1.getConstVal(); - } -; - precision_arg: %empty { $$ = fix_Precision(); @@ -1647,9 +1626,9 @@ strfmt_args: strfmt_va_args: %empty {} - | strfmt_va_args COMMA const_no_str { + | strfmt_va_args COMMA relocexpr_no_str { $$ = std::move($1); - $$.args.push_back(static_cast($3)); + $$.args.push_back(static_cast($3.getConstVal())); } | strfmt_va_args COMMA string { $$ = std::move($1);