Skip to content

Instantly share code, notes, and snippets.

@korzio
Last active March 17, 2021 20:34
Show Gist options
  • Save korzio/9b068193062ef843c2817efe9987bd6e to your computer and use it in GitHub Desktop.
Save korzio/9b068193062ef843c2817efe9987bd6e to your computer and use it in GitHub Desktop.
type Node struct {
Token *token.Token
Left *Node
Right *Node
}
// string representation
// 1 * 2 + 3 -> {+,{*,{1},{2}},{3}}
func (n *Node) ToString() string {
res := "{" + n.Token.Literal
if n.Left != nil {
res += "," + n.Left.ToString()
}
if n.Right != nil {
res += "," + n.Right.ToString()
}
res += "}"
return res
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment