Professional Documents
Culture Documents
GLOBAL EDITION
Chapter 3
Describing Syntax
and Semantics
mark = 2 + 3 + final;
• Terminals are lexemes or tokens
• A rule has a left-hand side (LHS), which is a
nonterminal, and a right-hand side (RHS), which is
a string of terminals and/or nonterminals
<program> ® <stmts>
<stmts> ® <stmt> | <stmt> ; <stmts>
<stmt> ® <var> = <expr>
<var> ® a | b | c | d
<expr> ® <term> + <term> | <term> - <term>
<term> ® <var> | const
<stmts>
<stmt>
<var> = <expr>
a <term> + <term>
<var> const
b
Copyright © 2023 Pearson Education Ltd. All Rights Reserved. 1-15
Ambiguity in Grammars
A=B+C*A
<expr>
<expr> + <term>
<term> <term> / id
id id
Copyright © 2023 Pearson Education Ltd. All Rights Reserved. 1-21
Specifying Precedence in Grammars
(continued)