Skip to content

Instantly share code, notes, and snippets.

@korzio
Last active March 17, 2021 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save korzio/6ff8349cf49286f85691a0f782ec46b6 to your computer and use it in GitHub Desktop.
Save korzio/6ff8349cf49286f85691a0f782ec46b6 to your computer and use it in GitHub Desktop.
func nud(acc interface{}, next token.Token) iterator {
// Node{Token: token.Token{Type: token.PLUS, Literal: "+"}, Left: &Node{Token: token.Token{Type: token.INT, Literal: "2"}}}
node := ast.Node{Token: &next}
it := iterator{nud: &node}
accIt, isIt := acc.(iterator)
if isIt {
// { , {... }
node.Left = accIt.nud
// save current stack
it.stack = accIt.stack
}
// finish nud iteration
if next.Type == token.INT {
it.left = &node
it.nud = nil
}
return it
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment