From 0a286901b4b91a61401cd9db3bf21353e9608725 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Fri, 30 Jan 2026 21:11:06 -0600 Subject: begin on parser --- src/parser.zig | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/parser.zig (limited to 'src/parser.zig') diff --git a/src/parser.zig b/src/parser.zig new file mode 100644 index 0000000..4252e3b --- /dev/null +++ b/src/parser.zig @@ -0,0 +1,58 @@ +const std = @import("std"); +const tok = @import("tokenizer.zig"); +const Token = tok.Token; + +const typ = union { + Funct: struct { + inputtyp: []*typ, + bodytyp: *typ, + rettyp: *typ, + }, + Type: union { + Int: u32, + Float: f32, + Bool: bool, + String: []const u8, + }, +}; + +var typmap: std.AutoHashMap([]const u8, typ) = undefined; + +var index: u32 = 0; +pub fn parse(allocator: std.mem.Allocator, toks: []Token) void { + typmap = std.AutoHashMap([]const u8, typ).init(allocator); + + parser: switch (toks[0]) { + .LPAREN => break :parser typedef(toks), + .BUILTIN => |b| break :parser builtin(toks, b), + .FUNC => |f| break :parser funcdef(toks, f), + } +} + +fn typedef(allocator: std.mem.Allocator, toks: []Token) !Token { + index += 1; + const name = toks[index]; + var inputTyp: typ = undefined; + switch (name) { + .FUNC => { + var inputArr = std.ArrayList(typ){}; + while (toks[index] != .RPAREN) : (index += 1) { + if (toks[index] != .LARROW) return error{UnexpectedToken}; + index += 1; + inputArr.append(allocator, toks[index]); + // fix this please + + + } + }, + } + + while (toks[index] != .PERIOD) : (index += 1) { + switch (toks[index]) { + + } + } + return toks[index]; +} +fn builtin(toks: []Token, fun: []const u8) Token { _=fun; _=toks; } +fn funcdef(toks: []Token, fun: []const u8) Token { _=fun; _=toks; } -- cgit v1.2.3