1 CFGS Consider the following grammar. erpr := erpr + expr | erpr + erpr|(crpr) | number number := number digit | digit digit := 0 I 1 | 21 3I 4I5I 6I7 | 8 I 9 1. Redefine the grammar in a way that numbers are defined by regular expressions. That is, remove two grammar rules for number and digit nonterminals, and replace them with a single regular expres- sions for numbers. 2. Modify the grammar to define assignment statements with a syntax similar to C/C+, where ex- pressions are assigned to identifiers. Here are the steps: (a) Add identifier token ID to the CFG. You may define it with regular expressions (since identi- fiers are tokens). We have already seen how to define identifiers with regular expressions, in previous sessions. (b) Consider a nonterminal for assignment. Let's call this nonterminal assignment. You need to define a CFG rule that defines assignment. An assignment in C/C+ grammatically consists of an identifier (defined in previous step), folowed by equality symbol (a terminal), followed by an expression (an already defined nonterminal). This sequence of terminals and nonterminals should be given in the RHS of your CFG rule.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
1 CFGS
Consider the following grammar.
erpr := erpr + expr | erpr + erpr|(crpr) | number
number := number digit | digit
digit := 0 I 1 | 21 3I 4I5I 6I7 | 8 I 9
1. Redefine the grammar in a way that numbers are defined by regular expressions. That is, remove two
grammar rules for number and digit nonterminals, and replace them with a single regular expres-
sions for numbers.
2. Modify the grammar to define assignment statements with a syntax similar to C/C+, where ex-
pressions are assigned to identifiers. Here are the steps:
(a) Add identifier token ID to the CFG. You may define it with regular expressions (since identi-
fiers are tokens). We have already seen how to define identifiers with regular expressions, in
previous sessions.
(b) Consider a nonterminal for assignment. Let's call this nonterminal assignment. You need to
define a CFG rule that defines assignment. An assignment in C/C+ grammatically consists of
an identifier (defined in previous step), folowed by equality symbol (a terminal), followed by
an expression (an already defined nonterminal). This sequence of terminals and nonterminals
should be given in the RHS of your CFG rule.
Transcribed Image Text:1 CFGS Consider the following grammar. erpr := erpr + expr | erpr + erpr|(crpr) | number number := number digit | digit digit := 0 I 1 | 21 3I 4I5I 6I7 | 8 I 9 1. Redefine the grammar in a way that numbers are defined by regular expressions. That is, remove two grammar rules for number and digit nonterminals, and replace them with a single regular expres- sions for numbers. 2. Modify the grammar to define assignment statements with a syntax similar to C/C+, where ex- pressions are assigned to identifiers. Here are the steps: (a) Add identifier token ID to the CFG. You may define it with regular expressions (since identi- fiers are tokens). We have already seen how to define identifiers with regular expressions, in previous sessions. (b) Consider a nonterminal for assignment. Let's call this nonterminal assignment. You need to define a CFG rule that defines assignment. An assignment in C/C+ grammatically consists of an identifier (defined in previous step), folowed by equality symbol (a terminal), followed by an expression (an already defined nonterminal). This sequence of terminals and nonterminals should be given in the RHS of your CFG rule.
Expert Solution
Step 1

When working with text, whether authoring or editing, we often need to change something. Name of some feature from A to B. Spelling error. Numerical value. A phrase that does not fit the rest of text. And usually, we just delete the wrong text and type in the correct one. If a spelling error or incorrect spelling variant is repeated across the document, we may use Find/Change to correct all instances at once.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY