aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/stage1/tokenizer.cpp8
-rw-r--r--src/translate_c.zig11
2 files changed, 10 insertions, 9 deletions
diff --git a/src/stage1/tokenizer.cpp b/src/stage1/tokenizer.cpp
index 4550f32e8c..f10579c966 100644
--- a/src/stage1/tokenizer.cpp
+++ b/src/stage1/tokenizer.cpp
@@ -1286,10 +1286,6 @@ void tokenize(const char *source, Tokenization *out) {
t.column -= 1;
t.state = TokenizeState_start;
continue;
- case 'e':
- case 'E':
- t.state = TokenizeState_float_exponent_unsigned;
- break;
case DIGIT:
t.state = TokenizeState_float_fraction_dec;
break;
@@ -1308,10 +1304,6 @@ void tokenize(const char *source, Tokenization *out) {
t.column -= 1;
t.state = TokenizeState_start;
continue;
- case 'p':
- case 'P':
- t.state = TokenizeState_float_exponent_unsigned;
- break;
case HEXDIGIT:
t.out->ids.last() = TokenIdFloatLiteral;
t.state = TokenizeState_float_fraction_hex;
diff --git a/src/translate_c.zig b/src/translate_c.zig
index 715ce73d45..b462743753 100644
--- a/src/translate_c.zig
+++ b/src/translate_c.zig
@@ -4932,8 +4932,17 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node {
}
},
.FloatLiteral => |suffix| {
- if (lit_bytes[0] == '.')
+ const dot_index = mem.indexOfScalar(u8, lit_bytes, '.').?;
+ if (dot_index == 0) {
lit_bytes = try std.fmt.allocPrint(c.arena, "0{s}", .{lit_bytes});
+ } else if (dot_index + 1 == lit_bytes.len or !std.ascii.isDigit(lit_bytes[dot_index + 1])) {
+ // If the literal lacks a digit after the `.`, we need to
+ // add one since `1.` or `1.e10` would be invalid syntax in Zig.
+ lit_bytes = try std.fmt.allocPrint(c.arena, "{s}0{s}", .{
+ lit_bytes[0 .. dot_index + 1],
+ lit_bytes[dot_index + 1 ..],
+ });
+ }
if (suffix == .none) {
return transCreateNodeNumber(c, lit_bytes, .float);
}