Parses infix expressions.

Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
Mariano Uvalle 2025-01-04 17:56:10 -08:00
parent f286a88039
commit 5fa7b2481a
4 changed files with 201 additions and 4 deletions

View file

@ -131,7 +131,7 @@ func (il *IntegerLiteral) String() string {
}
type PrefixExpression struct {
Token token.Token
Token token.Token // The operator token
Operator string
Right Expression
}
@ -143,3 +143,18 @@ func (pe *PrefixExpression) TokenLiteral() string {
func (pe *PrefixExpression) String() string {
return "(" + pe.Operator + pe.Right.String() + ")"
}
type InfixExpression struct {
Token token.Token // The operator token
Operator string
Left Expression
Right Expression
}
func (ie *InfixExpression) expressionNode() {}
func (ie *InfixExpression) TokenLiteral() string {
return ie.Token.Literal
}
func (ie *InfixExpression) String() string {
return "(" + ie.Left.String() + " " + ie.Operator + " " + ie.Right.String() + ")"
}