aboutsummaryrefslogtreecommitdiff
path: root/ast
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-11-08 17:56:53 +0000
committerBobby <[email protected]>2023-11-08 17:56:53 +0000
commit152e63c1865d8bc1df36f54218cc9286b7fd1ff2 (patch)
tree4c8b996fb65d8b86a0c0d1ee620ff5f13732963e /ast
parentaed19195e4476ed6933eac2d1d748bcdcb4277e7 (diff)
downloadmana-152e63c1865d8bc1df36f54218cc9286b7fd1ff2.tar.xz
mana-152e63c1865d8bc1df36f54218cc9286b7fd1ff2.zip
parse infix operators
Diffstat (limited to 'ast')
-rw-r--r--ast/ast.go27
1 files changed, 27 insertions, 0 deletions
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