From 9e1ef93990273f6993ab62e9cb5799803e74c845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20Kapri=C5=A1?= Date: Fri, 17 Jan 2025 20:47:03 +0100 Subject: [PATCH] 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. --- pj1-go/lexer/lexer.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pj1-go/lexer/lexer.go b/pj1-go/lexer/lexer.go index da32f2a..a0caf04 100644 --- a/pj1-go/lexer/lexer.go +++ b/pj1-go/lexer/lexer.go @@ -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) }