Chapter 5:Semantic Analysis

 

production Attribute rule
number sign list

list.position 0

if sign.negative

then number.value - list.value

else number.value list.value

sign + sign.negative false
sign - sign.negative true
list bit

bit.position list.position

list.value bit.value

list0 list 1 bit

list1 .position list 0 .position + 1

bit.position list 0 .position

list0 .value list1 .value + bit.value

bit 0 bit.value 0
bit 1 bit.value 2bit.position
   
   

Explanation of attribute rules

 

Num -> sign list /*since list is the rightmost so it is assigned position 0
  *Sign determines whether the value of the number would be
  *same or the negative of the value of list*/
Sign -> + | - /*Set the Boolean attribute (negative) for sign*/
List -> bit /*bit position is the same as list position because this bit is the rightmost
  *value of the list is same as bit.*/
List0 -> List1 bit /*position and value calculations*/
Bit -> 0 | 1 /*set the corresponding value*/
 

Attributes of RHS can be computed from attributes of LHS and vice versa.