1 / 21

Programming Language Syntax 7

Programming Language Syntax 7. http://flic.kr/p/ zCyMp. Recall: Recursive Descent Parsers. …. …. Recall: Recursive Descent Parsers. …. What types of grammars can recursive descent parsers handle?. Answer: LL grammars. …. Recall: Recursive Descent Parsers. ….

craigm
Download Presentation

Programming Language Syntax 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Language Syntax 7 http://flic.kr/p/zCyMp

  2. Recall: Recursive Descent Parsers … …

  3. Recall: Recursive Descent Parsers … What types of grammars can recursive descent parsers handle? Answer:LL grammars …

  4. Recall: Recursive Descent Parsers … What procedures does a recursive descent parser contain? Answer:1 for each production + match() …

  5. Recall: Recursive Descent Parsers … Each procedure contains what type of statement? Answer:A branching statement (case or if/else) …

  6. Recall: Recursive Descent Parsers … What does each branch do? Answer:Predict right-hand side and execute corresponding procedure(s) or match, or identify parse error …

  7. Recall: Recursive Descent Parsers … Does this algorithm recognize sentences in a language? Create a parse tree? Answer: Yes Answer: No …

  8. Recall: Recursive Descent Parsers … How could it be modified to create a parse tree? Answer: When each procedure is called, hang a node from node associated w/ caller …

  9. Recall: Recursive Descent Parsers … How does the parser generator determine the predict sets? Answer: Computes two mappings:FIRST, FOLLOW (+EPS) …

  10. Recall Mappings(aka functions in the mathematical sense) • FIRST maps • each left-hand side of a production to • a set of terminals that can start it • Follow maps • each left-hand side of a production to • a set of terminals that can follow it • EPS maps • each left-hand side of a production to • true or false, depending whether the right-hand side can be empty or not

  11. Activity: Run FIRST/EPS algorithm on grammar

  12. Solution

  13. Algorithm for computing FOLLOW sets

  14. Activity: Run FOLLOW algorithm on grammar

  15. Solution

  16. Given the FIRST, FOLLOW, and EPS sets/values, can you deduce the PREDICT sets?

  17. Algorithm for computing PREDICT sets Based on computed PREDICT sets, how can you tell if a grammar is LL(1)? If two rules with the same left-hand side have the non-disjoint (overlapping) PREDICT sets, then the grammar is not LL(1)

  18. Solution

  19. ANTLR-Generated Parser (Java) ANTLR 4 generates recursive descent parsers … ANTLR Grammar … EBNF Grammar … … …

  20. ANTLR 4 is Adaptive LL(*) aka ALL(*) • Can process all non-left-recursive grammars • Can process grammars with direct left recursion • ANTLR 3 was just LL(*), so it couldn’t do this

  21. What’s next? • Homework 3 assigned next class

More Related