Parse some more operations

This commit is contained in:
2026-02-20 14:22:26 +11:00
parent b98487caaf
commit cb13200545
2 changed files with 47 additions and 9 deletions

View File

@@ -17,20 +17,20 @@ bash build.c
- [x] bool
- [x] Lex keywords
- [x] Ignore comments (//, /**/, #)
- [ ] Lex delimiters
- [x] Lex delimiters
- [x] ()
- [x] {}
- [x] .
- [x] :
- [x] ,
- [ ] ==, =
- [ ] >, >=
- [ ] <, <=
- [ ] !, !=
- [ ] +, +=, ++
- [ ] -, -=, --
- [ ] *, *=
- [ ] /, /=
- [x] ==, =
- [x] >, >=
- [x] <, <=
- [x] !, !=
- [x] +, +=, ++
- [x] -, -=, --
- [x] *, *=
- [x] /, /=
- [ ] Lex types
- [x] Basic types (int, double, string, bool, char)
- [ ] Advanced types (fun(...), template(...), object(...))

View File

@@ -503,6 +503,44 @@ ResultType(voidptr, charptr) lex(SolsLexer* lexer) {
break;
}
// These characters may be followed by an equals sign, or nothing else.
case '=':
case '!':
case '>':
case '<':
case '*':
case '/': {
if (strcmp(buf.str, "") != 0) {
ResultType(SolsToken, charptr) result = identifyToken(buf.str);
if (result.error) {
return Error(voidptr, charptr, createParsingError(lineNum, currentLine.str, result.as.error));
}
addTokenToSolsTokens(&lexer->output, result.as.success);
DESTROY_ESTR(buf);
buf = CREATE_ESTR("");
}
ResultType(char, Nothing) next = lexerPeek(lexer, 1);
if (next.error || next.as.success != '=') {
char tmp[] = {chr.as.success, '\0'};
ResultType(SolsToken, charptr) result = identifyToken(tmp);
if (result.error) {
return Error(voidptr, charptr, createParsingError(lineNum, currentLine.str, result.as.error));
}
addTokenToSolsTokens(&lexer->output, result.as.success);
}
if (next.as.success == '=') {
char tmp[] = {chr.as.success, '=', '\0'};
ResultType(SolsToken, charptr) result = identifyToken(tmp);
if (result.error) {
return Error(voidptr, charptr, createParsingError(lineNum, currentLine.str, result.as.error));
}
addTokenToSolsTokens(&lexer->output, result.as.success);
lexerConsume(lexer);
}
break;
}
// '.' requires checking whether it's a number or an identifier after
case '.': {
ResultType(char, Nothing) peek = lexerPeek(lexer, 1);