Answered step by step
Verified Expert Solution
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started