Add modulo operators to lexer

Tokens MODULO and SLASH_MODULO are going to represent the modulo and
fmod operations on integers and floats, or return a pair with the
divisor and the modulo, respectively.
This commit is contained in:
Petar Kapriš 2025-01-17 20:47:03 +01:00
parent 4178bfefea
commit 9e1ef93990

View file

@ -37,6 +37,8 @@ const (
SLASH
SLASH_DOT
SLASH_UNDERSCORE
SLASH_MODULO
MODULO
// Literals
IDENTIFIER
@ -179,6 +181,8 @@ func (l *Lexer) scanToken() {
} else {
l.addSimpleToken(GREATER)
}
case '%':
l.addSimpleToken(MODULO)
case '/':
if l.match('/') {
// A comment goes until the end of the line
@ -211,6 +215,8 @@ func (l *Lexer) scanToken() {
l.addSimpleToken(SLASH_DOT)
} else if l.match('_') {
l.addSimpleToken(SLASH_UNDERSCORE)
} else if l.match('%') {
l.addSimpleToken(SLASH_MODULO)
} else {
l.addSimpleToken(SLASH)
}