mighty

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

commit 86e49fcd2661662b02ef226160fa9c87a5434386
parent 422d8de5d84d3d3746f6328a140f158c7b6117cd
Author: citbl <citbl@citbl.org>
Date:   Sat, 16 May 2026 17:12:54 +1000

lexer wip

Diffstat:
Mmtc/lexer/lexer.go | 27++++++++++++++++++++++++---
Mmtc/test.mty | 4+++-
2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/mtc/lexer/lexer.go b/mtc/lexer/lexer.go @@ -1,6 +1,8 @@ package lexer -import "fmt" +import ( + "fmt" +) type Kind int @@ -16,6 +18,7 @@ const ( MinusMinus LParen RParen + Dot EOF IntLiteral FloatLiteral @@ -75,11 +78,26 @@ func Lex(src string) []Token { res = append(res, Token{numeric, src[start:i], line, startCol}) continue } + if c == '"' { + i++ // consume opening dbquote + col++ + for i < len(src) && src[i] != '"' { + i++ + col++ + } + + res = append(res, Token{StringLiteral, src[start+1 : i], line, startCol}) + i++ // consume closing dbquote + col++ + continue + } var cx byte if i+1 < len(src) { cx = src[i+1] } switch c { + case '.': + res = append(res, Token{Dot, src[i : i+1], line, col}) case ':': switch cx { case ':': @@ -138,6 +156,8 @@ func is_digit(c byte) bool { func (k Kind) String() string { switch k { + case Dot: + return "Dot" case Ident: return "Ident" case Plus: @@ -175,11 +195,12 @@ func (k Kind) String() string { case BadToken: return "BAD~~~TOKEN" default: - return "Unknown" + return "Print:Unknown" } } + func Print_tokens(tokens []Token) { for _, tok := range tokens { - fmt.Printf("%-d:%-2d %-12s %-12q\n", tok.Line, tok.Col, tok.Kind, tok.Value) + fmt.Printf("%-d:%-2d %-16s %-16q\n", tok.Line, tok.Col, tok.Kind, tok.Value) } } diff --git a/mtc/test.mty b/mtc/test.mty @@ -1,2 +1,4 @@ int main() :: - io.putln("hello world " + 123) + io.putln("hello world") + io.putln("hello " + 123) +