Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Writing Grammars Number Grammars Note that many of these grammars could be written as regular grammars, but here we'll practice writing them in standard Backus-Naur

image text in transcribed

Writing Grammars Number Grammars Note that many of these grammars could be written as regular grammars, but here we'll practice writing them in standard Backus-Naur Form BNF (note: do not use Extended BNF). NUM1 = the set of all integers, including leading '-' and optional leading '+' signs. Give parse trees for 0 and -128 NUM2 = the set of even negative integers (-2,-4, -6, ...). Give parse trees for -16, and -378. NUM3 = the set of signed decimal numbers, with at least one digit (possibly zero) both before and after the decimal point. Give parse trees for +1.2, and -33.03. Identifier Grammars ID1 = the set of strings beginning with an upper-case letter, followed by any number of lower- case letters or digits. Give parse trees for Sum1 and R. ID2 = the set of strings of letters, digits, underscores and dashes, provided that (1) the first character in the string is an upper-case letter, and (2) the final character is neither an underscore nor a dash. Give parse trees for BB-8 and case_1. ID3 = the set of strings axbx -- any number of a's followed by an equal number of b's. Give parse trees for the empty string (i.e. O a's and 0 bs) and aabb. Boolean Expression Grammar Write a grammar for Boolean expressions . Arithmetic expressions might be simple literals like 3 or 97 or may be more complex syntactic units like (3+x)/4. They evaluate to a number. You needn't concern yourself with their structure; just that they can be used as below. Boolean expressions include the literals TRUE and FALSE; they can be combined with the unary operator ! (meaning NOT) and binary operators && and || (meaning AND and OR). Also, arithmetic expressions can be combined with the following binary operators to form new Boolean expressions: , =, !=. When your grammar is complete, you should be able to derive parse trees for expressions like the following: TRUE || FALSE FALSE && !TRUE 27 = TRUE FALSE Writing Grammars Number Grammars Note that many of these grammars could be written as regular grammars, but here we'll practice writing them in standard Backus-Naur Form BNF (note: do not use Extended BNF). NUM1 = the set of all integers, including leading '-' and optional leading '+' signs. Give parse trees for 0 and -128 NUM2 = the set of even negative integers (-2,-4, -6, ...). Give parse trees for -16, and -378. NUM3 = the set of signed decimal numbers, with at least one digit (possibly zero) both before and after the decimal point. Give parse trees for +1.2, and -33.03. Identifier Grammars ID1 = the set of strings beginning with an upper-case letter, followed by any number of lower- case letters or digits. Give parse trees for Sum1 and R. ID2 = the set of strings of letters, digits, underscores and dashes, provided that (1) the first character in the string is an upper-case letter, and (2) the final character is neither an underscore nor a dash. Give parse trees for BB-8 and case_1. ID3 = the set of strings axbx -- any number of a's followed by an equal number of b's. Give parse trees for the empty string (i.e. O a's and 0 bs) and aabb. Boolean Expression Grammar Write a grammar for Boolean expressions . Arithmetic expressions might be simple literals like 3 or 97 or may be more complex syntactic units like (3+x)/4. They evaluate to a number. You needn't concern yourself with their structure; just that they can be used as below. Boolean expressions include the literals TRUE and FALSE; they can be combined with the unary operator ! (meaning NOT) and binary operators && and || (meaning AND and OR). Also, arithmetic expressions can be combined with the following binary operators to form new Boolean expressions: , =, !=. When your grammar is complete, you should be able to derive parse trees for expressions like the following: TRUE || FALSE FALSE && !TRUE 27 = TRUE FALSE

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago