infix_expression.go 782 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package ast
  2. import (
  3. "bytes"
  4. "code.osinet.fr/fgm/waiig15/token"
  5. )
  6. // InfixExpression fulfills the Node and Statement interfaces.
  7. // It represents a prefixed expression like:
  8. // "-5;"
  9. type InfixExpression struct {
  10. Token token.Token
  11. Left Expression
  12. Operator string
  13. Right Expression
  14. }
  15. // String satisfies the Node and fmt.Stringer interfaces.
  16. func (ie *InfixExpression) String() string {
  17. var out bytes.Buffer
  18. out.WriteString("(")
  19. out.WriteString(ie.Left.String())
  20. out.WriteString(" " + ie.Operator + " ")
  21. out.WriteString(ie.Right.String())
  22. out.WriteString(")")
  23. return out.String()
  24. }
  25. func (ie *InfixExpression) expressionNode() {}
  26. // TokenLiteral satisfies the Node interface.
  27. func (ie *InfixExpression) TokenLiteral() string {
  28. return ie.Token.Literal
  29. }