8.8 Grammar and IR Generation for miniC

In Chapter 12, we plan to present a complete development of a compiler for a stripped down C-like language, miniC. Here we present, as examples of Intermediate Representation for most important program constructs, along with the action terms added in the yacc grammar to generate them. The following are considered:

  • expressions
  • assignments
  • statements: IF-THEN, IF-THEN-ELSE, WHILE-DO
  • IF-THEN and IF-THEN-ELSE initiation
  • WHILE-DO initiation
  • variable declarations
  • function definitions
  • function calls

We use three additional stacks to keep track of various code-related parameters:

tstack: Stack for the temporaries Tn number, tcount used in the 4-tuple IR. Corresponding stack functions are tpush() and tpop(). The ...

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.