Chapter 4 - Semantic Analysis

The role of the semantic analyzer

The role of the semantic analyzer

The role of the semantic analyzer

Dynamic checks

Static analysis

Static analysis

Attribute grammars

Evaluating attributes

Evaluating attributes in an S-attributed grammar

Evaluating attributes that are inherited

Evaluating attributes that are inherited

expr(A) ::= CONST(B) exprtail(C). 
  {C.st = B.val; A.val = C.val}
exprtail(A) ::= MINUS CONST(B) exprtail(C). 
  {C.st = C.st - B.val; A.val = C.val}
exprtail(A) ::= . 
  {A.val = A.st}

Evaluating attributes that are inherited

expr(A) ::= CONST(B) exprtail(C). 
  {C.st = B.val; A.val = C.val}
exprtail(A) ::= MINUS CONST(B) exprtail(C). 
  {C.st = C.st - B.val; A.val = C.val}
exprtail(A) ::= . 
  {A.val = A.st}

Upshot

Attribute flow

Attribute flow

Attribute flow is not just "LR <-> S-attribute"

One pass compilation

Building a syntax tree

Building a syntax tree

Building a syntax tree

Figure 4.7 from text

Building a syntax tree

Building a syntax tree

Figure 4.8 from text

Action Routines

Action Routines

Space managment for attributes

Decorating a Syntax Tree

Example of S-attributed grammar

Example here