diff options
| author | Bobby <[email protected]> | 2023-11-08 17:56:53 +0000 |
|---|---|---|
| committer | Bobby <[email protected]> | 2023-11-08 17:56:53 +0000 |
| commit | 152e63c1865d8bc1df36f54218cc9286b7fd1ff2 (patch) | |
| tree | 4c8b996fb65d8b86a0c0d1ee620ff5f13732963e /ast | |
| parent | aed19195e4476ed6933eac2d1d748bcdcb4277e7 (diff) | |
| download | mana-152e63c1865d8bc1df36f54218cc9286b7fd1ff2.tar.xz mana-152e63c1865d8bc1df36f54218cc9286b7fd1ff2.zip | |
parse infix operators
Diffstat (limited to 'ast')
| -rw-r--r-- | ast/ast.go | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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 |
