summaryrefslogtreecommitdiff
path: root/src/parser.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.zig')
-rw-r--r--src/parser.zig58
1 files changed, 58 insertions, 0 deletions
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; }