



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




(let me count the ways …)
In scanning & parsing, formalism won; different story here.
Number ⇒ Sign List ⇒ – List ⇒ – Bit ⇒ – 1
Number
List
Bit
1
Sign
For “–1”
Number ⇒ Sign List ⇒ Sign List Bit ⇒ Sign List 1 ⇒ Sign List Bit 1 ⇒ Sign List 0 1 ⇒ Sign Bit 0 1 ⇒ Sign 1 0 1 ⇒ – 101
Number
Sign List
1
List
Bit
0
List
Bit
1
For “–101”
Symbol Attributes Number val Sign neg List pos, val Bit pos, val
pos
val
pos
val
pos
val
pos
val
pos
val
pos
val
pos
val
pos
val
pos
val
Number
Sign List
List Bit
List Bit
Bit
1
0
1
pos: val:
pos: val:
pos: val:
pos: val:
pos: val:
pos: 0 val:
val:
neg:
For “–101”
Number
Sign List
List Bit
List Bit
Bit
1
0
1
pos: 1 val:
pos: 0 val:
pos: 2 val:
pos: 2 val:
pos: 1 val:
pos: 0 val:
val:
neg:
For “–101”
Inherited Attributes
Number
Sign List
List^ Bit
List Bit
Bit
1
0
1
pos: 1 val: 0
pos: 0 val: 1
pos: 2 val: 4
pos: 2 val:
pos: 1 val:
pos: 0 val:
val:
neg: true
For “–101”
Synthesized attributes
Number
Sign List
List^ Bit
List Bit
Bit
1
0
1
pos: 1 val: 0
pos: 0 val: 1
pos: 2 val: 4
pos: 2 val: 4
pos: 1 val: 4
pos: 0 val: 5
val: –
neg: true
For “–101”
Synthesized attributes
Number
Sign List
List Bit
List Bit
Bit
1
0
1
pos: 1 val: 0
pos: 0 val: 1
pos: 2 val: 4
pos: 2 val: 4
pos: 1 val: 4
pos: 0 val: 5
val: –
neg: true
For “–101”
& then peel away the parse tree ...
If we show the computation ...
1
0
1
pos: 1 val: 0
pos: 0 val: 1
pos: 2 val: 4
pos: 2 val: 4
pos: 1 val: 4
pos: 0 val: 5
val: –
neg: true
For “–101”
All that is left is the attribute dependence graph. This succinctly represents the flow of values in the problem instance. The dynamic methods sort this graph to find independent values, then work along graph edges. The rule-based methods try to discover “good” orders by analyzing the rules. The oblivious methods ignore the structure of this graph.
The dependence graph must be acyclic
Block 0 → Block 1 Ass ign Block 0 .cost^ ←^ Block^1 .cost^ + Assign.cost Assign Block 0 .cost ← Assign.co st
Assign → Ident = Expr ; Assign.cost^ ←^ COS T(st ore) + Expr.c ost Expr 0 → Expr 1 + T erm Expr 0 .cost ← Expr 1 .cost + COS T(add) + Term. co st Expr 1 – Term Expr 0 .cost ← Expr 1 .cost + COS T(add) + Term. co st Term Expr 0 .cost ← Term.co st
Term 0 → Term 1 * Fac tor Term 0 .cost ← T erm 1 .cost + COS T(mult ) + Fac tor.cost Term 1 / F acto r Term 0 .cost ← T erm 1 .cost + COS T(div) + Factor.cost Fac tor Term 0 .cost ← Fac tor.cost
Fac tor → ( Expr ) Fac tor.cost ← Expr.c ost Numb er Fac tor.cost ← COS T(loa dI ) Identifier Fac tor.cost ← COS T(loa d)
Factor → ( Expr ) Factor.cost ← Expr.cost ; Expr.Before ← Factor.Before ; Factor.After ← Expr.After (^) Number Factor.cost ← COST(loadi) ; Factor.After ← Factor.Before Identifier If (Identifier.name ∉∉∉∉ Factor.Before) then Factor.cost ← COST(load); Factor.After ← Factor.Before ∪ Identifier.name else Factor.cost ← 0 Factor.After ← Factor.Before
This looks more complex! CS430 30
Goal → Expr $$ = $1; Expr → Expr + Term $$ = MakeAddNode($1,$3); | Expr – Term $$ = MakeSubNode($1,$3); | Term $$ = $1; Term → Term * Factor $$ = MakeMulNode($1,$3); | Term / Factor $$ = MakeDivNode($1,$3); | Factor $$ = $1; Factor →^ ( Expr ) $$ = $2; | number $$ = MakeNumNode(token); | id $$ = MakeIdNode(token);