Beyond Syntax, Attributes Grammar - Compiler Construction - Lecture Slides, Slides of Compiler Construction

Beyond Syntax, Context analysis, Sensitive analysis, Values, Computation, Formal methods, Ad Hoc techniques are basic concepts discussed of course.

Typology: Slides

2011/2012

Uploaded on 11/03/2012

ekavia
ekavia 🇮🇳

4.3

(58)

241 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Compiler
Construction
Lecture 31
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Beyond Syntax, Attributes Grammar - Compiler Construction - Lecture Slides and more Slides Compiler Construction in PDF only on Docsity!

Compiler

Construction

Lecture 31

2

Beyond Syntax

 These questions are part of

context-sensitive analysis

 Answers depend on values,

not parts of speech

 Answers may involve

computation

4

Beyond Syntax

 These questions are part of

context-sensitive analysis

 Answers depend on values,

not parts of speech

 Answers may involve

computation

5

Beyond Syntax

How can we answer these

questions?

 Use formal methods

  • Context-sensitive

grammars

  • Attribute grammars

7

Beyond Syntax

How can we answer these

questions?

 Use formal methods

  • Context-sensitive

grammars

  • Attribute grammars

8

Beyond Syntax

 Use ad-hoc techniques

  • Symbol tables
  • ad-hoc code

10

Attribute Grammars

 A CFG is augmented with a

set of rules

 Each symbol in the derivation

has a set of values or

attributes

 Rules specify how to compute

a value for each attribute

11

Attribute Grammars

 A CFG is augmented with a

set of rules

 Each symbol in the derivation

has a set of values or

attributes

 Rules specify how to compute

a value for each attribute

13

Attribute Grammars

derivation for “–1”

Number → Sign List

→ – List

→ – Bit

14

Attribute Grammars

For “-101”

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

16

Attribute Grammars

 We will add rules to

compute decimal value of a

signed binary number

17

Attribute Grammars

Productions Attribution Rules

Number → Sign List List.pos ← 0 if Sign.neg then Number.val ← List.val else Number.val ← List.val

Sign → + (^) Sign.neg ← false

Sign → – (^) Sign.neg ← true

19

Attribute Grammars

Productions Attribution Rules List 0 → List 1 Bit List 1 .pos ← List 0 .pos + 1 Bit.pos ← List 0 .pos List 0 .val ← List 1 .val + Bit.val

List → Bit Bit.pos ← List.pos List.val ← Bit.val

Bit → 0 Bit.val ← 0

Bit → 1 Bit.val ← 2 Bit.pos

20

Attribute Grammars

 Attributes are associated with

nodes in parse tree

 Rules are value assignments

associated with productions