an experimental ambiguity detection tool
play

An Experimental Ambiguity Detection Tool Sylvain Schmitz - PowerPoint PPT Presentation

An Experimental Ambiguity Detection Tool Sylvain Schmitz Laboratoire I3S, Universit e de Nice - Sophia Antipolis & CNRS March 25, 2007 Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA07 1 / 28


  1. An Experimental Ambiguity Detection Tool Sylvain Schmitz Laboratoire I3S, Universit´ e de Nice - Sophia Antipolis & CNRS March 25, 2007 Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 1 / 28

  2. Syntax Issue Standard ML Standard ML Milner et al. [1997] Example datatype ’ a option = NONE | SOME of ’ a fun f i l t e r pred l = let fun f i l t e r P ( x : : r , l ) = case ( pred x ) of SOME y = > f i l t e r P ( r , y : : l ) | NONE = > f i l t e r P ( r , l ) | f i l t e r P ( [ ] , l ) = rev l in f i l t e r P ( l , [ ] ) end Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 3 / 28

  3. Syntax Issue Standard ML The Issue SML Compilers Behaviour | f i l t e r P ( [ ] , l ) = rev l ◮ MLton ◮ Moscow ML ◮ Poly/ML ◮ SML/NJ Error: match.sml 9.25. Syntax error: replacing EQUALOP with DARROW. Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 5 / 28

  4. Syntax Issue Standard ML The Issue SML Compilers Behaviour | f i l t e r P ( [ ] , l ) = rev l ◮ MLton ◮ Moscow ML ◮ Poly/ML ◮ SML/NJ ! Toplevel input: ! | filterP ([], l) = rev l ! ^ ! Syntax error. Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 5 / 28

  5. Syntax Issue Standard ML The Issue SML Compilers Behaviour | f i l t e r P ( [ ] , l ) = rev l ◮ MLton ◮ Moscow ML ◮ Poly/ML ◮ SML/NJ Error: => expected but = was found Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 5 / 28

  6. Syntax Issue Standard ML The Issue SML Compilers Behaviour | f i l t e r P ( [ ] , l ) = rev l ◮ MLton ◮ Moscow ML ◮ Poly/ML ◮ SML/NJ stdIn:7.24-7.29 Error: syntax error: deleting EQUALOP ID Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 5 / 28

  7. Syntax Issue Shift/Reduce Conflict The Issue Partial SML Grammar � dec � → fun � fvalbind � → � sfvb � | � fvalbind � ′ | ′ � sfvb � � fvalbind � � sfvb � → vid � atpats � = � exp � � exp � → case � exp � of � match � → � mrule � | � match � ′ | ′ � mrule � � match � � mrule � → � pat � = > � exp � � atpats � → � atpat � | � atpats � � atpat � � pat � → vid � atpat � � atpat � → vid Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 6 / 28

  8. Syntax Issue Shift/Reduce Conflict The Issue Shift/Reduce Conflict GNU Bison state 20 6 exp: "case" exp "of" match . 8 match: match . ’|’ mrule ’|’ shift, and go to state 24 ’|’ [reduce using rule 6 (exp)] Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 8 / 28

  9. Syntax Issue Shift/Reduce Conflict The Issue Shift/Reduce Conflict Which action to choose? � fvalbind � � match � � match � � mrule � � mrule � � pat � � exp � � pat � � exp � . . . of SOME y = > filterP(r, y::l) | NONE = > filterP(r, l) Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 8 / 28

  10. Syntax Issue Shift/Reduce Conflict The Issue Shift/Reduce Conflict Which action to choose? Reduce? � fvalbind � � sfvb � � exp � � match � � sfvb � � mrule � � pat � � exp � error! vid . . . of SOME y = > filterP(r, y::l) | NONE = > filterP(r, l) Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 8 / 28

  11. Syntax Issue Shift/Reduce Conflict The Issue Shift/Reduce Conflict Which action to choose? Shift? � fvalbind � � match � � match � � mrule � � mrule � � pat � � exp � � pat � � exp � . . . of SOME y = > filterP(r, y::l) | NONE = > filterP(r, l) Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 8 / 28

  12. Syntax Issue Shift/Reduce Conflict The Issue Shift/Reduce Conflict Which action to choose? � fvalbind � � fvalbind � � sfvalbind � � exp � � match � � mrule � � sfvalbind � � pat � � exp � � atpats � � exp � . . . | NONE = > filterP(r, l) | filterP ([], l) = rev l Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 8 / 28

  13. Syntax Issue Shift/Reduce Conflict The Issue Shift/Reduce Conflict Which action to choose? Reduce? � fvalbind � � fvalbind � � sfvalbind � � exp � � match � � mrule � � sfvalbind � � pat � � exp � � atpats � � exp � . . . | NONE = > filterP(r, l) | filterP ([], l) = rev l Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 8 / 28

  14. Syntax Issue Shift/Reduce Conflict The Issue Shift/Reduce Conflict Which action to choose? Shift? � fvalbind � � fvalbind � � sfvalbind � � exp � � match � � match � � mrule � � pat � � exp � � pat � � exp � error! . . . | NONE = > filterP(r, l) | filterP ([], l) = rev l � fvalbind � Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 8 / 28

  15. Syntax Issue Shift/Reduce Conflict The Issue Shift/Reduce Conflict Which action to choose? Lookahead? | � sfvb � | � mrule � � atpats � � pat � vid = > = ... ... � atpat � vid � atpat � ... ... An unbounded lookahead is needed. Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 8 / 28

  16. Syntax Issue Shift/Reduce Conflict The Issue Shift/Reduce Conflict Which action to choose? Example Ambiguous contruct: case a of b = > case b of c = > c | d = > d Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 8 / 28

  17. Syntax Issue Shift/Reduce Conflict The Issue Shift/Reduce Conflict Which action to choose? Reduce? Example Ambiguous contruct: case a of b = > case b of c = > c | d = > d Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 8 / 28

  18. Syntax Issue Shift/Reduce Conflict The Issue Shift/Reduce Conflict Which action to choose? Shift? Example Ambiguous contruct: case a of b = > case b of c = > c | d = > d Here, the standard favors the shift. Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 8 / 28

  19. Syntax Issue GLR Parsing Generalized LR Tomita [1986] ◮ checks every possibility ◮ considered fast enough ◮ painless Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 9 / 28

  20. Syntax Issue GLR Parsing Generalized LR Tomita [1986] ◮ checks every possibility ◮ considered fast enough ◮ painless. . . or is it? Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 9 / 28

  21. Syntax Issue GLR Parsing Generalized LR ◮ painless. . . or is it? ◮ need to consider ambiguity � exp � � match � ≡ � match � � mrule � � match � � mrule � � exp � � exp � � match � � match � � exp � � pat � � exp � � mrule � � mrule � case a of b = > case b of c = > c | d= > d Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 9 / 28

  22. Syntax Issue GLR Parsing Generalized LR ◮ need to consider ambiguity � exp � � match � ≡ � match � � mrule � � match � � mrule � � exp � � exp � � match � � match � � exp � � pat � � exp � � mrule � � mrule � case a of b = > case b of c = > c | d= > d ◮ select a single tree: disambiguation filters Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 9 / 28

  23. Syntax Issue GLR Parsing Disambiguation Filters Klint and Visser [1994] Example � exp � � match � ≡ � match � � mrule � � match � � mrule � � exp � � exp � � match � � match � � exp � � pat � � exp � � mrule � � mrule � case a of b = > case b of c = > c | d= > d Select the tree according to the employed rule: � match �→� mrule � rather than � match �→� match � ′ | ′ � mrule � . ◮ prefer and avoid in SDF2 ◮ %dprec in GNU Bison Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 10 / 28

  24. Syntax Issue GLR Parsing Disambiguation Filters Klint and Visser [1994] Example � exp � � match � ≡ � match � � mrule � � match � � mrule � � exp � � exp � � match � � match � � exp � � pat � � exp � � mrule � � mrule � case a of b = > case b of c = > c | d= > d Select the tree according to the employed rule: � match �→� mrule � rather than � match �→� match � ′ | ′ � mrule � . ◮ prefer and avoid in SDF2 ◮ %dprec in GNU Bison Sylvain Schmitz (U. Nice Sophia Antipolis) An ExperimentalAmbiguity Detection Tool LDTA’07 10 / 28

Recommend


More recommend