Implement 'character' literals (#1747)

This commit is contained in:
Rangi
2025-07-15 13:08:50 -04:00
committed by GitHub
parent b6d77fbb9e
commit 1fecf80659
8 changed files with 124 additions and 11 deletions

View File

@@ -339,6 +339,7 @@
// Literals
%token <int32_t> NUMBER "number"
%token <std::string> STRING "string"
%token <std::string> CHARACTER "character"
%token <std::string> SYMBOL "symbol"
%token <std::string> LABEL "label"
%token <std::string> LOCAL "local label"
@@ -1415,6 +1416,15 @@ relocexpr_no_str:
NUMBER {
$$.makeNumber($1);
}
| CHARACTER {
std::vector<int32_t> output = charmap_Convert($1);
if (output.size() == 1) {
$$.makeNumber(static_cast<uint32_t>(output[0]));
} else {
::error("Character literals must be a single charmap unit");
$$.makeNumber(0);
}
}
| OP_LOGICNOT relocexpr %prec NEG {
$$.makeUnaryOp(RPN_LOGNOT, std::move($2));
}