I am trying to convert a miniC program (limited features) into a 3AC using lex and yacc. I read a bit about it on google but all the examples given always have some variable in their operations. What If in the source code theres something like this
x = 2+3+4;
Will the 3AC for this would look like?
t0 = 2+3;
t1 = t0+4;
x = t1;
Or should this be optimized to?
x = 9;
For the first implementation I think its fairly easy. But if second is the way to go, how would I implement that? How do compilers handle this situation? Do they generate the second 3AC right away? Or do they start with the first 3AC and then have multiple passes for optimizations?
(I am not looking to implement a multiple pass 3AC generator)