From 152e63c1865d8bc1df36f54218cc9286b7fd1ff2 Mon Sep 17 00:00:00 2001 From: Bobby Date: Wed, 8 Nov 2023 17:56:53 +0000 Subject: parse infix operators --- ast/ast.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'ast') diff --git a/ast/ast.go b/ast/ast.go index 021b387..1942a68 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -151,6 +151,33 @@ func (pe *PrefixExpression) String() string { return out.String() } +// InfixExpression represents an infix expression. + +type InfixExpression struct { + Token tokens.Token // the operator token, e.g. + + Left Expression + Operator string + Right Expression +} + +func (ie *InfixExpression) expressionNode() {} +func (ie *InfixExpression) TokenLiteral() string { + return ie.Token.Literal +} +func (ie *InfixExpression) String() string { + var out bytes.Buffer + + + out.WriteString("(") + out.WriteString(ie.Left.String()) + out.WriteString(" " + ie.Operator + " ") + out.WriteString(ie.Right.String()) + out.WriteString(")") + + return out.String() +} + + // IntegerLiteral represents an integer literal. type IntegerLiteral struct { Token tokens.Token // the token.INT token -- cgit v1.2.3