block none stack pop(whenever we start new node we increment the brackets count and create new empty block this block is added as the last child of the stack' top block' list of children and is itself pushed onto the stack if the block has color or name we will be able to set it because we keep reference to the block in the block variable the logic used here is slightly different from the logic used in the recursive descent parser--there we pushed new blocks onto the stack only if we knew that they had nested blocks here we always push new blocks onto the stacksafe in the knowledge that they'll be popped straight off again if they don' contain any nested blocks this also makes the code simpler and more regular when we reach the end of block we decrement the brackets count--and if it is negative we know that we have had too many close brackets and can report the error immediately otherwisewe set block to none since we now have no current block and pop the top of the stack (which should never be emptyelif token type ="color"if block is none or block is_new_row(block)raise lexerror("syntax error"block color token value[:- elif token type ="name"if block is none or block is_new_row(block)raise lexerror("syntax error"block name token value if we get color or namewe set the corresponding attribute of the current block which should refer to block rather than being none or denoting new row elif token type ="empty_node"stack[- children append(block get_empty_block()elif token type ="new_rows"for in range(len(token value))stack[- children append(block get_new_row()if we get an empty node or one or more new rowswe add them as the last child of the stack' top block' list of children if bracketsraise lexerror("unbalanced brackets []"except lexerror as errraise valueerror("error {{ }}:line { }{ }formattoken lineno err)