Last active
March 17, 2021 20:34
-
-
Save korzio/9b068193062ef843c2817efe9987bd6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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