LL(1) Parser Generators SLLGEN and JavaCC 11/27/2018 PPL LL(1) Parser Generators
PPL LL(1) Parser Generators class dictionaries (11 kinds) inductive nonleft-recursive 9 10 11 8 7 6 1 2 LL(1) 3 1: ideal case 2: JavaCC does not complain (Oct. 30 1997). Grammar contains useless symbols. Ok if we don’t want to parse but forces cyclic objects. 4 nonambiguous 5 Venn Diagram 11/27/2018 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 11/27/2018 PPL LL(1) Parser Generators
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? 11/27/2018 PPL LL(1) Parser Generators
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. 11/27/2018 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 11/27/2018 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? 11/27/2018 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! 11/27/2018 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. 11/27/2018 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 11/27/2018 PPL LL(1) Parser Generators
Java Compiler Compiler: error message Warning: Choice conflict … A common prefix is “a”. Consider using a lookahead of 2 ... 11/27/2018 PPL LL(1) Parser Generators
LL(1) class dictionaries A special kind of nonambiguous class dictionaries. Membership can be checked efficiently. 11/27/2018 PPL LL(1) Parser Generators
Java Compiler Compiler LL(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. 11/27/2018 PPL LL(1) Parser Generators
PPL LL(1) Parser Generators Style rule Ideally, make your class dictionaries LL(1), nonleft-recursive and inductive. 11/27/2018 PPL LL(1) Parser Generators