140 likes | 397 Views
LL(1) Parser Generators. SLLGEN and JavaCC. class dictionaries (11 kinds). inductive. nonleft-recursive. 9. 10. 11. 8. 7. 6. 1. 2. LL(1). 3. 4. nonambiguous. 5. Venn Diagram. 11 kinds of class dictionaries. Why 11 and not 16?
E N D
LL(1) Parser Generators SLLGEN and JavaCC PPL LL(1) Parser Generators
class dictionaries (11 kinds) inductive nonleft-recursive 9 10 11 8 7 6 1 2 LL(1) 3 4 nonambiguous 5 Venn Diagram PPL LL(1) Parser Generators
11 kinds of class dictionaries • Why 11 and not 16? • Four properties: nonambiguous, LL(1), inductive, non-left recursive: 16 sets if independent • But: implication relationships • LL(1) implies nonambiguous: 12 left • LL(1) and inductive imply nonleft-recursive: 11 left PPL LL(1) Parser Generators
SLLGEN Error messages • What are the error messages you get from the SLLGEN Parser Generator if you violate any of the four properties? PPL LL(1) Parser Generators
JavaCC Error messages • What are the error messages you get from the JavaCC Parser Generator if you violate any of the four properties? • Answers follow. PPL LL(1) Parser Generators
Inductive class dictionaries • inductiveness already defined for class graphs • contains only good recursions: recursions that terminate Car = Motor. Motor = <belongsTo> Car. bad recursion, objects must be cyclic, cannot use for parsing: useless nonterminals PPL LL(1) Parser Generators
Inductive class dictionaries • A node v in a class graph is inductive if there is at least one finite tree object of class v. • A class graph is inductive if all its nodes are inductive. Car = Motor Transmission. Motor = <belongsTo> Car. Transmission = . Which nodes are inductive? PPL LL(1) Parser Generators
Inductiveness style rule to follow • Maximize the number of classes which are inductive. • Reasons: cyclic objects • cannot be parsed directly from sentences. • require visitors to break infinite loops. • it is harder to reason about cyclic objects. • No message from the Java Compiler Compiler! PPL LL(1) Parser Generators
Left-recursive class dictionaries • Bring us back to the same class without consuming input. • Java Compiler Compiler: left recursion detected: A -> C -> A A : B | C. B = “b”. C = A. PPL LL(1) Parser Generators
Ambiguous class dictionaries • cannot distinguish between objects. Print is not injective (one-to-one). Fruit : Apple | Orange. Apple = “a”. Orange = “a”. But: undecidable PPL LL(1) Parser Generators
Java Compiler Compiler:error message • Warning: Choice conflict … A common prefix is “a”. Consider using a lookahead of 2 ... PPL LL(1) Parser Generators
LL(1) class dictionaries • A special kind of nonambiguous class dictionaries. Membership can be checked efficiently. PPL LL(1) Parser Generators
Java Compiler CompilerLL(1) error messages: Rule 2 • A = [B]. B = . • Error message: expansion can be mapped by empty string, line x, column y in Parser.jj. • A = [B] [“b” C]. B = “b”. C = . • Warning only: Choice conflict … line x column y. Expansion nested within construct and expansion following construct have common prefixes one of which is b. PPL LL(1) Parser Generators
Style rule • Ideally, make your class dictionaries LL(1), nonleft-recursive and inductive. PPL LL(1) Parser Generators