Skip to content

Commit

Permalink
Refactor the parser to have fewer *_no_str intermediate rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Feb 4, 2025
1 parent fbde24e commit d9d381c
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions src/asm/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,11 @@
%type <Expression> relocexpr
%type <Expression> relocexpr_no_str
%type <Expression> reloc_8bit
%type <Expression> reloc_8bit_no_str
%type <Expression> reloc_8bit_offset
%type <Expression> reloc_16bit
%type <Expression> reloc_16bit_no_str

// Constant numbers
%type <int32_t> iconst
%type <int32_t> const_no_str
%type <int32_t> uconst
// Constant numbers used only in specific contexts
%type <int32_t> bit_const
Expand Down Expand Up @@ -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
Expand All @@ -1251,7 +1248,8 @@ constlist_8bit:
;

constlist_8bit_entry:
reloc_8bit_no_str {
relocexpr_no_str {
$1.checkNBit(8);
sect_RelByte($1, 0);
}
| string {
Expand All @@ -1266,7 +1264,8 @@ constlist_16bit:
;

constlist_16bit_entry:
reloc_16bit_no_str {
relocexpr_no_str {
$1.checkNBit(16);
sect_RelWord($1, 0);
}
| string {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -1545,12 +1530,6 @@ iconst:
}
;

const_no_str:
relocexpr_no_str {
$$ = $1.getConstVal();
}
;

precision_arg:
%empty {
$$ = fix_Precision();
Expand Down Expand Up @@ -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<uint32_t>($3));
$$.args.push_back(static_cast<uint32_t>($3.getConstVal()));
}
| strfmt_va_args COMMA string {
$$ = std::move($1);
Expand Down

0 comments on commit d9d381c

Please sign in to comment.