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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.