sic

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

commit 3b669b1ae207f7a3c8692343732463539299140e
parent 1f2f877f46df3a286d69d5d0432e575032945e94
Author: citbl <citbl@citbl.org>
Date:   Thu, 14 May 2026 19:03:31 +1000

lex more tokens

Diffstat:
Msrc/lexer.c | 37++++++++++++++++++++++++++++++++++++-
Msrc/lexer_tools.c | 18++++++++++++++++++
Msrc/token.h | 18+++++++++++++++++-
Mtest.sic | 3++-
Atests/lex_basics.sic | 6++++++
5 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/src/lexer.c b/src/lexer.c @@ -152,6 +152,20 @@ Lexer* lexer_lex(Lexer* lex) add_token(lex, t); continue; case '=': + if (peek(lex) == '=') { + t.type = EQ_EQ; + add_token(lex, t); + advance(lex); + advance(lex); + continue; + } + if (peek(lex) == '>') { + t.type = EQ_GT; + add_token(lex, t); + advance(lex); + advance(lex); + continue; + } t.type = EQ; add_token(lex, t); advance(lex); @@ -161,15 +175,36 @@ Lexer* lexer_lex(Lexer* lex) add_token(lex, t); advance(lex); continue; + case '(': + t.type = LPAREN; + add_token(lex, t); + advance(lex); + continue; + case ')': + t.type = RPAREN; + add_token(lex, t); + advance(lex); + continue; + case '{': + t.type = LBRACE; + add_token(lex, t); + advance(lex); + continue; + case '}': + t.type = RBRACE; + add_token(lex, t); + advance(lex); + continue; case '\n': case '\r': + case '\t': case ' ': advance(lex); continue; break; } - printf("unhandled: %zu: %c\n", lex->state.pos, c); + printf("unhandled: %s: %zu:%zu %c\n", lex->filename, lex->state.line, lex->state.col, c); advance(lex); } diff --git a/src/lexer_tools.c b/src/lexer_tools.c @@ -24,9 +24,27 @@ void print_tokens(Lexer* lex) case LIT_INT: printf("DECIMAL LITERAL: %s\n", lex->tokens[i].lexeme.value); break; + case LBRACE: + printf("LBRACE {\n"); + break; + case RBRACE: + printf("RBRACE }\n"); + break; + case LPAREN: + printf("LPAREN (\n"); + break; + case RPAREN: + printf("RPAREN )\n"); + break; case EQ: printf("EQ =\n"); break; + case EQ_EQ: + printf("EQ_EQ ==\n"); + break; + case EQ_GT: + printf("EQ_GT =>\n"); + break; case SEMICOL: printf("SEMICOL ;\n"); break; diff --git a/src/token.h b/src/token.h @@ -7,7 +7,7 @@ typedef enum Token_Type { KEYWORD, SYMBOL, PLUS, - MIN, + MINUS, STAR, SLASH, BACKSLASH, @@ -24,7 +24,23 @@ typedef enum Token_Type { DASH_GT, EQ, BANG, + PLUS_EQ, + MINUS_EQ, + STAR_EQ, + SLASH_EQ, + PERCENT_EQ, + QUESTION, + COLON, SEMICOL, + PIPE, + AMPERSAND, + CARET, + LT, + GT, + LT_LT, + GT_GT, + PLUS_PLUS, + MINUS_MINUS, LIT_STRING, LIT_DECIMAL, LIT_INT, diff --git a/test.sic b/test.sic @@ -4,5 +4,6 @@ str name = "Johnny Mnemonic"; int age = 45; int km = 400_000_000; dec height = 188.3; - +if(a == b) print("success"); +token => id; diff --git a/tests/lex_basics.sic b/tests/lex_basics.sic @@ -0,0 +1,6 @@ +// this is a comment + +void main() { + print("hello"); +} +