mighty

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

commit 49c3e9d1e902077b992d0ef00903351d2c529743
parent 3142ed49e9e825200441d1aae18fee6433552d30
Author: citbl <citbl@citbl.org>
Date:   Tue, 26 May 2026 18:44:25 +1000

parser wip

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

diff --git a/mtcl/parser.lua b/mtcl/parser.lua @@ -6,6 +6,10 @@ function parser:peek() return self.tokens[self.pos] or 0 end +function parser:nextpeek() + return self.tokens[self.pos + 1] or 0 +end + function parser:advance() self.pos = self.pos + 1 end @@ -32,10 +36,30 @@ function parser:add(ast) self.nodes[#self.nodes + 1] = ast end +function parser:parse_var() print("todo parse_var") end +function parser:parse_while() print("todo parse_while") end +function parser:parse_for() print("todo parse_for") end +function parser:parse_return() print("todo parse_return") end +function parser:parse_as_cast() print("todo parse_as_cast") end +function parser:parse_call() print("todo parse_call") end + function parser:parse_statement() - local next = parser:peek().kind - print("todo parse statement: " .. next) - if next == TK.IDENT then + local first = parser:peek().kind + local second = parser:nextpeek().kind + print("todo parse statement: " .. first) + if first == TK.IDENT then + if second == TK.L_PAREN then + parser:parse_call() + elseif second == TK.IDENT then + parser:parse_var() + end + elseif first == TK.KEYWORD then + local kw = parser:peek() + if kw.lexeme == "while" then parse:parse_while() + elseif kw.lexeme == "for" then parse:parse_for() + elseif kw.lexeme == "return" then parse:parse_return() + elseif kw.lexeme == "as" then parse:parse_as_cast() + end end parser:advance() end