previous | start | next

Question 3 answer


Show that this grammar is ambiguous:

1            <S> -> <A>
2,3          <A> -> <A> '+' <A> | <id>
4,5,6        <id> -> 'a' | 'b' | 'c'



The following string is a sentence for this grammar and it has two
different left-most derivations: 

   a + b + c

Left-most derivation 1:
                               Rule Used 
    1   <S> => <A>                     1         
    2       => <A> + <A>               2         
    3       => id + <A>                3         
    4       => a + <A>                 4         
    5       => a + <A> + <A>           2
    6       => a + id + <A>            3
    7       => a + b + <A>             5
    8       => a + b + id              3
    9       => a + b + c               6

Left-most derivation 2:
                               Rule Used 
    1   <S> => <A>                     1         
    2       => <A> + <A>               2         
    3       => <A> + <A> + <A>         2
    4       => id + <A> + <A>          3
    5       => a + <A> + <A>           4
    6       => a + id + <A>            3
    7       => a + b + <A>             5
    8       => a + b + id              3
    9       => a + b + c               6



previous | start | next