0

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)

2
  • Compilers usually create an AST and do transformations on it before generating the final result. As for which output you prefer, I'm not able to tell. Commented Apr 12, 2023 at 20:05
  • What do you mean which output? Are you talking about the 3AC? Commented Apr 12, 2023 at 21:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.