Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Language Syntax 7

Similar presentations


Presentation on theme: "Programming Language Syntax 7"— Presentation transcript:

1 Programming Language Syntax 7

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 a set of terminals that can follow it EPS maps 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 4 generates recursive descent parsers
ANTLR-Generated Parser (Java) 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


Download ppt "Programming Language Syntax 7"

Similar presentations


Ads by Google