5.6 Intermediate Representation Output for miniC

Though it is possible to include actions in the yacc grammar of a language to either directly execute a program written in that language (as is done in hoc6) or directly generate a target code, we have taken the option of generating Intermediate Representation (IR) (Chapter 8) in anticipation of discussion of various optimization methods.

Any reasonable IR can be obtained by including proper action terms in the yacc grammar. Here we illustrate a small part of the final grammar with action terms for generating two kinds of IR – reverse polish notation (RPN) and 4-tuple notation. The full grammar with IR generating actions is given in Chapters 8 and 12. Here, we show IR for arithmetic expressions ...

Get Compilers: Principles and Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.