O'Reilly logo

Compilers: Principles and Practice by Himanshu B. Dave, Parag H. Dave

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required