40 likes | 196 Views
This overview explores LL(1) parsers and their unique properties, focusing on the conditions necessary for a grammar to classify as LL(1). We delve into the ambiguous grammar example provided and highlight the challenges of defining distinct productions without overlap. Our discussion addresses the significance of the First and Follow sets in parser construction and underscores the necessity of eliminating left recursion and ambiguity to ensure proper parsing. This foundational knowledge is pivotal for anyone involved in compiler design or language processing.
E N D
LL(1) PARSER Eg:Consider the following grammar: S --> iEtSS’ | a S’ --> eS | ع E --> b
First Follow S i,a $,e E b t S’ e,ع $,e
The grammar is ambiguous and it is evident by the fact that we have two entries corresponding to M[S’,e] containing S -->ع and S->eS.This ambiguity can be resolved if we choose S’-->eS i.e associating the else’s with the closest previous “then”. LL(1) grammars have distinct properties.No ambiguous grammar or left recusive grammar can be LL(1).A grammar is LL(1) if and only if whenever a production A--> C | D the following conditions hold: 1)For no terminal a both C and D derive strings beginning with a.Thus First(C) != First(D) 2)At most one of C or D can derive € • 3) If C* ع then D doesnot derive any string beginning with terminal Follow(A).