Skip to content

Commit

Permalink
feat: adds modulus babyyy
Browse files Browse the repository at this point in the history
  • Loading branch information
Tezzish committed Sep 27, 2024
1 parent 5472228 commit 2f30cf0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func (l *Lexer) NextToken() token.Token {
tok = newToken(token.ASTERISK, l.character)
case '/':
tok = newToken(token.SLASH, l.character)
case '%':
tok = newToken(token.MODULUS, l.character)
case '<':
tok = newToken(token.LT, l.character)
case '>':
Expand Down
2 changes: 2 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var precedences = map[token.TokenType]int{
token.NEQ: EQUALS,
token.LT: LESSGREATER,
token.GT: LESSGREATER,
token.MODULUS: PRODUCT,
token.PLUS: SUM,
token.MINUS: SUM,
token.SLASH: PRODUCT,
Expand Down Expand Up @@ -62,6 +63,7 @@ func New(l *lexer.Lexer) *Parser {
p.registerPrefix(token.IF, p.parseIfExpression)
p.registerPrefix(token.FUNCTION, p.parseFunctionLiteral)
p.infixParseFns = make(map[token.TokenType]infixParseFn)
p.registerInfix(token.MODULUS, p.parseInfixExpression)
p.registerInfix(token.PLUS, p.parseInfixExpression)
p.registerInfix(token.MINUS, p.parseInfixExpression)
p.registerInfix(token.SLASH, p.parseInfixExpression)
Expand Down
1 change: 1 addition & 0 deletions token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
BANG = "!"
ASTERISK = "*"
SLASH = "/"
MODULUS = "%"

LT = "<"
GT = ">"
Expand Down

0 comments on commit 2f30cf0

Please sign in to comment.