infix parsing and cleanup
This commit is contained in:
23
ast/ast.go
23
ast/ast.go
@@ -74,6 +74,13 @@ type PrefixExpression struct {
|
||||
Right Expression
|
||||
}
|
||||
|
||||
type InfixExpression struct {
|
||||
Token token.Token
|
||||
Left Expression
|
||||
Operator string
|
||||
Right Expression
|
||||
}
|
||||
|
||||
func (ls *LetStatement) statementNode() {
|
||||
}
|
||||
func (ls *LetStatement) TokenLiteral() string {
|
||||
@@ -157,3 +164,19 @@ func (pe *PrefixExpression) String() string {
|
||||
|
||||
return out.String()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user