Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Context-free languages and recursive descent parsing Answer Question b only please We use regular expressions to describe regular languages. Regular expressions are themselves strings over

Context-free languages and recursive descent parsing

Answer Question b only please

image text in transcribed

We use regular expressions to describe regular languages. Regular expressions are themselves strings over an alphabet including regular characters and special characters such as parentheses, ., I, and "*". The string".*(1.111..1). *" is a valid regular expression while the string ((101) (" is not. This language turns out not be regular (because it includes strings with arbitrarily deeply nested sets of parentheses). Let us assume we have already constructed a scanner that identifies the tokens regular expressions are composed of. The tokens we are allowed to build regular expressions from are (L.* + ? char where char denotes any valid character of the underlying alphabet. You don't have to worry about recognizing valid characters; we assume the scanner takes care of this for us. (a) Provide a context-free grammar that defines the language of regular expressions. As is customary, assume that each input string is terminated by a special end-of-string marker $. Make sure the grammar represents the semantic structure of regular expressions. For example, the partial grammar E char EEE E E|E would allow us to parse the regular expression ablc to be composed of two regular expressions a and b|c, which is semantically incorrect. The correct parse is a regular expression composed of two regular expressions ab" (which in turn is composed of smaller regular expressions) and c. Review how we ensured arithmetic expressions are parsed in a way that reflects operator precedence to get an idea how you can ensure that the parse tree corresponding to a regular expression correctly reflects its structure. (b) Provide the parse tree used to generate the string.*(1.1|1..1).*" using your grammar. (C) Verify that your grammar is LL(1). (If it is not, modify the grammar to make it LL(1).) In particular, provide FIRST, FOLLOW, and PREDICT sets for characters and productions and explain why they prove that the language is LL(1). (d) (Bonus: 25%) Provide the pseudo-code for a recursive descent parser for regular expressions based on your grammar. We use regular expressions to describe regular languages. Regular expressions are themselves strings over an alphabet including regular characters and special characters such as parentheses, ., I, and "*". The string".*(1.111..1). *" is a valid regular expression while the string ((101) (" is not. This language turns out not be regular (because it includes strings with arbitrarily deeply nested sets of parentheses). Let us assume we have already constructed a scanner that identifies the tokens regular expressions are composed of. The tokens we are allowed to build regular expressions from are (L.* + ? char where char denotes any valid character of the underlying alphabet. You don't have to worry about recognizing valid characters; we assume the scanner takes care of this for us. (a) Provide a context-free grammar that defines the language of regular expressions. As is customary, assume that each input string is terminated by a special end-of-string marker $. Make sure the grammar represents the semantic structure of regular expressions. For example, the partial grammar E char EEE E E|E would allow us to parse the regular expression ablc to be composed of two regular expressions a and b|c, which is semantically incorrect. The correct parse is a regular expression composed of two regular expressions ab" (which in turn is composed of smaller regular expressions) and c. Review how we ensured arithmetic expressions are parsed in a way that reflects operator precedence to get an idea how you can ensure that the parse tree corresponding to a regular expression correctly reflects its structure. (b) Provide the parse tree used to generate the string.*(1.1|1..1).*" using your grammar. (C) Verify that your grammar is LL(1). (If it is not, modify the grammar to make it LL(1).) In particular, provide FIRST, FOLLOW, and PREDICT sets for characters and productions and explain why they prove that the language is LL(1). (d) (Bonus: 25%) Provide the pseudo-code for a recursive descent parser for regular expressions based on your grammar

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2004 Workshops Edbt 2004 Workshops Phd Datax Pim P2panddb And Clustweb Heraklion Crete Greece March 2004 Revised Selected Papers Lncs 3268

Authors: Wolfgang Lindner ,Marco Mesiti ,Can Turker ,Yannis Tzitzikas ,Athena Vakali

2005th Edition

3540233059, 978-3540233053

More Books

Students also viewed these Databases questions

Question

7. What decisions would you make as the city manager?

Answered: 1 week ago