Syntax Directed Definition (SDD)
Technical and Numerical View
What is SDD?
• A Syntax Directed Definition (SDD) is a
context-free grammar combined with
attributes and semantic rules.
• Attributes carry values or information.
• Two types of attributes:
• - Synthesized (bottom-up)
• - Inherited (top-down)
Attribute Types
• Attribute Type | Flow Direction | Example
Use
• -------------------|----------------|-------------
• Synthesized | Bottom-up | Compute
expression values
• Inherited | Top-down | Pass type
information
Example Rule with Attributes
• Grammar:
• E → E1 + T
• Attributes:
• E.val = E1.val + T.val
• If:
• E1.val = 5, T.val = 7
• Then:
Full Numerical Example
• Grammar:
• E → E1 + T
• E → T
• T → num
• Input: 3 + 4
• Attribute Values:
• Node | Attribute | Value
Syntax Tree with Attributes
• Draw this tree:
• E
• /|
• E1 + T
• | |
• T num(4)
• |
• num(3)
Summary
• Syntax Directed Definition helps in annotating
parse trees.
• Synthesized attributes are most common in
bottom-up parsing.
• Numerical evaluations (like calculator apps)
use SDD heavily.

Syntax_Directed_Definition_Professional.pptx

  • 1.
    Syntax Directed Definition(SDD) Technical and Numerical View
  • 2.
    What is SDD? •A Syntax Directed Definition (SDD) is a context-free grammar combined with attributes and semantic rules. • Attributes carry values or information. • Two types of attributes: • - Synthesized (bottom-up) • - Inherited (top-down)
  • 3.
    Attribute Types • AttributeType | Flow Direction | Example Use • -------------------|----------------|------------- • Synthesized | Bottom-up | Compute expression values • Inherited | Top-down | Pass type information
  • 4.
    Example Rule withAttributes • Grammar: • E → E1 + T • Attributes: • E.val = E1.val + T.val • If: • E1.val = 5, T.val = 7 • Then:
  • 5.
    Full Numerical Example •Grammar: • E → E1 + T • E → T • T → num • Input: 3 + 4 • Attribute Values: • Node | Attribute | Value
  • 6.
    Syntax Tree withAttributes • Draw this tree: • E • /| • E1 + T • | | • T num(4) • | • num(3)
  • 7.
    Summary • Syntax DirectedDefinition helps in annotating parse trees. • Synthesized attributes are most common in bottom-up parsing. • Numerical evaluations (like calculator apps) use SDD heavily.