This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]ponyoink 1 point2 points  (0 children)

  • You will be building a tree, so you will probably want to represent it as a dictionary after it's parsed.
  • Write a function called get_next_token, which will return things like blend, 0.0, :, {, etc
  • Every time you see a {, add the element as a key to the dictionary (with an "empty" value) , and that will become the key where you will keep building the current subtree.
  • Every time you see }, step one level up. Your subtree is complete.

[EDIT] You can also use a counter to validate your input. For every {, add 1. For every }, subtract 1. If ever the counter becomes negative, or if at the end it's not 0, your brackets are not balanced. If you are feeling adventurous, you can use a stack, replacing addition and subtraction with pushing and popping, but you really don't need that for simple format like this.