mighty

The mighty programming language, compiler and tools (WIP)
Log | Files | Refs

commit 6044e4593f6c5104a42deaf5b0b15742fb42409e
parent 6dbfc4900579c7acfac8f957193b6d4280c71ce1
Author: citbl <citbl@citbl.org>
Date:   Sun, 24 May 2026 13:50:53 +1000

ast start

Diffstat:
Amtcl/ast.lua | 33+++++++++++++++++++++++++++++++++
Mmtcl/main.lua | 3+++
Mmtcl/parser.lua | 20++++++++++++++++++--
3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/mtcl/ast.lua b/mtcl/ast.lua @@ -0,0 +1,33 @@ +local AST = { file = "", line = 0, col = 0 } + +function AST:program(body) + return { + kind = "program", + body = body, + file = self.file, + line = self.line, + col = self.col, + } +end + +function AST:use(lib) + return { + kind = "use", + lib = lib, + file = self.file, + line = self.line, + col = self.col, + } +end + +function AST:func(name, params, ret, body) + return { + kind = "func", + name = name, + params = params, + body = body, + file = self.file, + line = self.line, + col = self.col, + } +end diff --git a/mtcl/main.lua b/mtcl/main.lua @@ -1,6 +1,7 @@ -- comp local lexer = require("lexer") +local parser = require("parser") local filename = arg[1] -- TODO check local file = io.open(filename, "rb") @@ -9,3 +10,5 @@ local contents = file:read("*all") lexer:lex(filename, contents) print(#lexer.tokens .. " tokens") + +parser:parse(filename, contents, lexer.tokens) diff --git a/mtcl/parser.lua b/mtcl/parser.lua @@ -1,3 +1,19 @@ -local parser = {} +local parser = { file, src, tokens } -function parser:parse(filename, src, parser) end +function parser:parse(file, src, tokens) + -- + self.file = file + self.src = src + self.tokens = tokens + + local i = 1 + + while i <= #tokens do + local t = tokens[i] + t2 = tokens[i + 1] or 0 + + i = i + 1 + end +end + +return parser