سوال ۴۸ کنکور ارشد مهندسی کامپیوتر ۱۴۰۴
درخصوص گرامر مستقل از متن از متن زیر، کدام مورد درست است؟
پاسخ صحیح: گزینهٔ C — گرامر در تولید رشته 1110 ابهام دارد.
A grammar is ambiguous if some string has two distinct parse trees (equivalently, two distinct leftmost derivations). We test each candidate string against
Key structural facts: every string produced via ends in ; every string via or ends in . Also can never derive a single (its productions are , , ).
String 1111 (option 1). It ends in , so it cannot use . The only path is repeated down to the base : . This is forced and unique — no ambiguity.
String 1101 (option 2). Ends in , so with . Since ends in , it uses with . Now must be with (the alternative would need , which is impossible). Every step is forced — unique, no ambiguity.
String 1110 (option 3). Ends in , so it must use with . But has two distinct derivations:
- (using )
- (using )
These give two different parse trees for , hence two parse trees for . So the grammar is ambiguous on 1110.
Option 4 is therefore false: the grammar is ambiguous.
The correct choice is option 3.
Exam trick: To spot ambiguity fast, anchor on the last symbol. A trailing forces , pushing all the work into , and 's two right-recursive rules and (the latter feeding 's own right recursion ) are exactly what create two ways to lay down the same run of s.