Greater than and Less Than
Some checks failed
Build / build (push) Failing after 1m12s
Test / build (push) Failing after 11m29s

This commit is contained in:
Chuck Smith
2024-03-18 16:17:13 -04:00
parent d454572870
commit b47a39e1b2
11 changed files with 116 additions and 43 deletions

View File

@@ -25,6 +25,8 @@ var precedences = map[token.TokenType]int{
token.NOT_EQ: EQUALS,
token.LT: LESSGREATER,
token.GT: LESSGREATER,
token.LTE: LESSGREATER,
token.GTE: LESSGREATER,
token.PLUS: SUM,
token.MINUS: SUM,
token.SLASH: PRODUCT,
@@ -78,7 +80,9 @@ func New(l *lexer.Lexer) *Parser {
p.registerInfix(token.EQ, p.parseInfixExpression)
p.registerInfix(token.NOT_EQ, p.parseInfixExpression)
p.registerInfix(token.LT, p.parseInfixExpression)
p.registerInfix(token.LTE, p.parseInfixExpression)
p.registerInfix(token.GT, p.parseInfixExpression)
p.registerInfix(token.GTE, p.parseInfixExpression)
p.registerInfix(token.LPAREN, p.parseCallExpression)
p.registerInfix(token.LBRACKET, p.parseIndexExpression)

View File

@@ -285,6 +285,14 @@ func TestOperatorPrecedenceParsing(t *testing.T) {
"5 < 4 != 3 > 4",
"((5 < 4) != (3 > 4))",
},
{
"5 >= 4 == 3 <= 4",
"((5 >= 4) == (3 <= 4))",
},
{
"5 <= 4 != 3 >= 4",
"((5 <= 4) != (3 >= 4))",
},
{
"3 + 4 * 5 == 3 * 1 + 4 * 5",
"((3 + (4 * 5)) == ((3 * 1) + (4 * 5)))",