0

I'm learning about ambiguity in grammars and I need a little help to understand better. Here is a grammar:

<S> ::= if <S> then <S>
<S> ::= if <S> then <S> else <S>
<S> ::= a

Using a parse tree or left-most derivation, how can I show that this grammar is ambiguous?

SarahCaw
  • 11
  • 2
  • Try nesting `if` statements in different combinations, and for each one think of whether you can put "parentheses" on it multiple conflicting ways – Alex Knauth Mar 27 '20 at 00:29

1 Answers1

1

Consider the following:

if a then if a then a else a

You could consider grouping it either of the following two ways:

(if a then (if a then a else a))

or

(if a then (if a then a) else a)

Both are possible with the grammar you provide, so it's ambiguous.

MLavrentyev
  • 1,827
  • 2
  • 24
  • 32