210 likes | 225 Views
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. ….
E N D
Programming Language Syntax 7 http://flic.kr/p/zCyMp
Recall: Recursive Descent Parsers … What types of grammars can recursive descent parsers handle? Answer:LL grammars …
Recall: Recursive Descent Parsers … What procedures does a recursive descent parser contain? Answer:1 for each production + match() …
Recall: Recursive Descent Parsers … Each procedure contains what type of statement? Answer:A branching statement (case or if/else) …
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 …
Recall: Recursive Descent Parsers … Does this algorithm recognize sentences in a language? Create a parse tree? Answer: Yes Answer: No …
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 …
Recall: Recursive Descent Parsers … How does the parser generator determine the predict sets? Answer: Computes two mappings:FIRST, FOLLOW (+EPS) …
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
Given the FIRST, FOLLOW, and EPS sets/values, can you deduce the PREDICT sets?
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)
ANTLR-Generated Parser (Java) ANTLR 4 generates recursive descent parsers … ANTLR Grammar … EBNF Grammar … … …
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
What’s next? • Homework 3 assigned next class