Presentation is loading. Please wait.

Presentation is loading. Please wait.

LL(1) Parser Generators

Similar presentations


Presentation on theme: "LL(1) Parser Generators"— Presentation transcript:

1 LL(1) Parser Generators
SLLGEN and JavaCC 11/27/2018 PPL LL(1) Parser Generators

2 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 ). 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

3 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

4 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

5 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

6 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

7 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

8 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

9 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

10 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

11 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

12 LL(1) class dictionaries
A special kind of nonambiguous class dictionaries. Membership can be checked efficiently. 11/27/2018 PPL LL(1) Parser Generators

13 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

14 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


Download ppt "LL(1) Parser Generators"

Similar presentations


Ads by Google