An event-based math parser