aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Lexer.zig2
-rw-r--r--src/main.zig10
-rw-r--r--src/parse.zig15
3 files changed, 11 insertions, 16 deletions
diff --git a/src/Lexer.zig b/src/Lexer.zig
index 6840d1d..cb146c7 100644
--- a/src/Lexer.zig
+++ b/src/Lexer.zig
@@ -12,7 +12,6 @@ pub const Token = struct {
integer_literal,
plus,
minus,
- semicolon,
equal,
invalid,
eof,
@@ -76,7 +75,6 @@ fn getNext(self: *Self) Token {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9' => self.integerLiteral(),
'+' => self.create(.plus),
'-' => self.create(.minus),
- ';' => self.create(.semicolon),
'=' => self.create(.equal),
'#' => {
while ((self.eatChar() orelse '\n') != '\n') {}
diff --git a/src/main.zig b/src/main.zig
index 81ca5c8..7af0885 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -38,13 +38,13 @@ pub fn main() !void {
const source =
\\{
- \\ let x = 69;
+ \\ let x = 69
\\ {
- \\ # let x = read_int(0);
- \\ print(18446744073709551615);
- \\ print(x + x);
+ \\ # let x = read_int(0)
+ \\ print(18446744073709551615)
+ \\ print(x + x)
\\ }
- \\ print(x);
+ \\ print(x)
\\}
;
var lexer: Lexer = .{ .source = source };
diff --git a/src/parse.zig b/src/parse.zig
index b509fe7..422b4f5 100644
--- a/src/parse.zig
+++ b/src/parse.zig
@@ -55,9 +55,9 @@ pub const Stmt = struct {
fn format(self: Stmt, writer: anytype, source: []const u8, indent: usize) !void {
try writer.writeByteNTimes(' ', indent);
return switch (self.type) {
- .expr => |expr| writer.print("{};", .{fmt(expr, source, indent)}),
+ .expr => |expr| writer.print("{}", .{fmt(expr, source, indent)}),
.block => |b| writer.print("{}", .{fmt(b, source, indent)}),
- .declare_var => |declare_var| writer.print("let {s} = {};", .{
+ .declare_var => |declare_var| writer.print("let {s} = {}", .{
declare_var.ident.getIdent(source),
fmt(declare_var.value, source, indent),
}),
@@ -113,7 +113,7 @@ pub const Expr = struct {
}
};
-const ParseError = error{ OutOfMemory, ExpectedRightParen, UnexpectedToken, ExpectedSemicolon };
+const ParseError = error{ OutOfMemory, ExpectedRightParen, UnexpectedToken };
pub fn block(allocator: Allocator, lexer: *Lexer) !Block {
const left_curly = try mustEat(lexer, .left_curly);
@@ -135,9 +135,8 @@ pub fn statement(allocator: Allocator, lexer: *Lexer) ParseError!Stmt {
const ident = try mustEat(lexer, .identifier);
_ = try mustEat(lexer, .equal);
const value = try expression(allocator, lexer);
- const semicolon = try mustEat(lexer, .semicolon);
return .{
- .loc = let.loc.combine(semicolon.loc),
+ .loc = let.loc.combine(value.loc),
.type = .{ .declare_var = .{ .ident = ident.loc, .value = value } },
};
},
@@ -149,11 +148,9 @@ pub fn statement(allocator: Allocator, lexer: *Lexer) ParseError!Stmt {
};
},
else => {
- var expr = try expression(allocator, lexer);
- const semicolon = lexer.next();
- if (semicolon.type != .semicolon) return error.ExpectedSemicolon;
+ const expr = try expression(allocator, lexer);
return .{
- .loc = expr.loc.combine(semicolon.loc),
+ .loc = expr.loc,
.type = .{ .expr = expr },
};
},