Lessee...a stack of tokens, a couple of functions...a couple objects to encapsulate the data about those tokens into more manageable packages. Hell, let's make the stack an object while we're at it too. So, that'll be the Stack object and the Operator objects, and $stack->iterate(); will act on the Operator objects in turn...
Who said logfile analyzers had to be boring? Or trivial? Or even sane?