mighty

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

commit 15338ce99edbd81afbf1bab6cc96c12be9314816
parent 01f5f24a69ff4cbd500e8cbf0aff101956a6cb24
Author: citbl <citbl@citbl.org>
Date:   Sun, 24 May 2026 20:32:31 +1000

parsing wip

Diffstat:
Mmtcl/parser.lua | 30+++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/mtcl/parser.lua b/mtcl/parser.lua @@ -27,20 +27,29 @@ function parser:match_ident() return current end +function parser:add(ast) + print("(+) adding node: " .. ast.kind) + self.nodes[#self.nodes + 1] = ast +end + function parser:parse_statement() print("todo parse statement") parser:advance() end function parser:parse_function(is_exported) + local name = "unamed function" + local parameters = {} + local returntypes = {} + local statements = {} local token = parser:peek() parser:advance() -- consume fx/fn - local ident = parser:expect(TK.IDENT) + name = parser:expect(TK.IDENT) parser:expect(TK.L_PAREN) - while parser:peek().kind ~= TK.R_PAREN do + while parser:peek().kind ~= TK.R_PAREN do -- parameters local kind = parser:expect(TK.IDENT, "missing kind in param") local name = parser:expect(TK.IDENT, "missing name in param") - + parameters[#parameters + 1] = { kind = kind, name = name } if parser:peek().kind == TK.COMMA then parser:advance() else @@ -49,7 +58,8 @@ function parser:parse_function(is_exported) end parser:expect(TK.R_PAREN) while parser:peek().kind ~= TK.L_BRACE do -- return type(s) - local rettype = parser:expect(TK.IDENT, "rettype no ident") + local kind = parser:expect(TK.IDENT, "rettype no ident") + returntypes[#returntypes + 1] = { kind = kind } if parser:peek().kind == TK.COMMA then parser:advance() else @@ -59,13 +69,11 @@ function parser:parse_function(is_exported) parser:expect(TK.L_BRACE, "no rbrace end of function") while parser:peek().kind ~= TK.R_BRACE do -- function body statements - parser:parse_statement() + local stmt = parser:parse_statement() + statements[#statements + 1] = stmt end - local node = ast.func(name, params, ret, body) -end - -function parser:add(ast) - table.insert(self.nodes, ast) + local node = ast.func(name, params, ret, statements) + parser:add(node) end function parser:parse_use() @@ -73,7 +81,7 @@ function parser:parse_use() self:advance() local lib = parser:match_ident() local node = ast.use(lib) - table.insert(self.nodes, node) + parser:add(node) end function unhandled(token, extramsg)