IAE Academy

Compiler Design formula sheet

20 formulas in 5 topics, each with when to use it. Each is explained in the topic notes.

Print the whole sheet

REMOVING IMMEDIATE LEFT RECURSION

Conditions: no starts with , and no is . is a new nonterminal. The new grammar has alternatives in total: for and for .

LEFT FACTORING

Applies when two or more alternatives of share a nonempty prefix (take the longest one); is a new nonterminal, and an empty becomes . Repeat until no two alternatives of any nonterminal share a prefix.

FORM OF A SYNTHESIZED RULE

The attribute being defined belongs to the head ; its arguments are attributes of the body symbols (or of itself).

FORM OF AN INHERITED RULE

The attribute being defined belongs to a body symbol ; the arguments may be attributes of the head and of the body symbols.

LIVE ACTIVATIONS

Holds under stack allocation, where every live activation has exactly one record on the stack. Counts the records on the stack at one instant; the maximum over the run is the peak stack depth. Includes the main program's record.

ACCESS-LINK HOPS FOR A VARIABLE

Static scoping with access links. A procedure at nesting depth uses a variable whose nearest enclosing declaration is at depth . Start at the current record and follow access links this many times; 0 means the variable is local.

INSTRUCTION AND TEMPORARY COUNT FOR AN ASSIGNMENT

For where has operator occurrences and nothing is shared. The scheme gives each operator a new temporary (temporaries are never reused) and then copies the last one to . With a DAG, replace by the number of operator nodes in the DAG.

ONE-DIMENSIONAL ARRAY ADDRESS

is the width of one element in bytes and is the lower bound of the index. For a 0-based array the term is just .

LIVE VARIABLES (BACKWARD, UNION)

A variable is live at a point if its current value may be read later before being overwritten. Initialise IN[B] = ∅ for all B; OUT of an exit block is ∅ unless the question names live-out variables.

REACHING DEFINITIONS (FORWARD, UNION)

A definition reaches a point if some path from it to that point does not redefine the variable. Initialise OUT[B] = ∅; IN[entry] = ∅.