My compiler design professor said while evaluating a statement, we convert every token into postfix notation. Everything other than function calls are in infix notation, and therefore must be converted to postfix.However functions are in prefix and NOT infix notation. So they must be converted as well.
This can be demonstrated as a+b
in infix being equivalent to +(a,b)
or +ab
in prefix notation.
However, I do not understand why we must convert everything to postfix and not prefix notation instead? Functions are already in prefix, so shouldn't it be faster to convert non function entities to prefix notation and execute in reverse?
The approach your instructor is describing is one possible approach to parsing expressions, but it's not the only one. Fundamentally, the goal of parsing is to get the expression into a format that's easy to work with and interpret, and both prefix and postfix notations meet those requirements. In an actual compiler it's far more common to build an abstract syntax tree, a tree encoding the structure of the input, and you can think of both prefix and postfix notations as either a preorder or postorder walk of that tree.
As for efficiency - the actual difference in cost between using prefix and postfix notations are trivial and are not going to be the bottleneck in your compiler. Typically, the most time-intensive phase of a compiler is optimization, with parsing consuming very little time. I wouldn't worry about doing the efficiency of parsing until you have concrete evidence that it's causing a problem.