Consider building the expression tree using a recursive algorithm, as described in the book.