Pl12ch3 Part 2
Pl12ch3 Part 2
• Introduction
• The General Problem of Describing Syntax
• Formal Methods of Describing Syntax
• Attribute Grammars
• Describing the Meanings of Programs:
Dynamic Semantics
<expr>
<expr>
<expr> + const
<expr> + const
const
Copyright © 2023 Pearson Education Ltd. All Rights Reserved. 1-3
Extended BNF
• BNF
<expr> ® <expr> + <term>
| <expr> - <term>
| <term>
<term> ® <term> * <factor>
| <term> / <factor>
| <factor>
• EBNF
<expr> ® <term> {(+ | -) <term>}
<term> ® <factor> {(* | /) <factor>}
• Syntax
<assign> -> <var> = <expr>
<expr> -> <var> + <var> | <var>
<var> A | B | C
• actual_type: synthesized for <var>
and <expr>
• expected_type: inherited for <expr>
<expr>.actual_type ¬ <var>[1].actual_type
<expr>.actual_type =? <expr>.expected_type