Implement simple math parser using Dijkstra's algorithm