Question

In: Computer Science

Q1)   Convert the following set of BNF rules to a single EBNF rule. <E> --> <E>...

Q1)   Convert the following set of BNF rules to a single EBNF rule.

<E> --> <E> + <T>
     |  <E> - <T>
     |  <T>

Q2)   Briefly explain how the expected type and actual type of <expr>

            in the following two BNF rules are determined:

<assign> --> <var> = <expr>  (Rule 1)
<expr>   --> <var> + <var>   (Rule 2)

Solutions

Expert Solution

Answer 1.

BNF:

<E> --> <E> + <T>

     | <E> - <T>

     | <T>

Conversion to EBNF:

<E> --> <E> <O> <T> +

<O> --> ‘+’ | ‘-‘

E equals to ‘E’ ‘O’ ‘T’

Where

E is expression

O is operator which can be ‘+’ or ‘-‘

T is term which is one or more.

Answer 2.

actual-type: a synthesized attribute which stores the actual type of a <VAR> or an <EXPRESSION>. In the case of an <EXPRESSION> , the type is computed given the types of the component <VAR>s.

expected-type: an inherited attribute which stores the expected type of <EXPRESSION> . It is determined by the type of the <VAR> on the left-hand-side of the expression statement.

Answer 1.

BNF:

<E> --> <E> + <T>

     | <E> - <T>

     | <T>

Conversion to EBNF:

<E> --> <E> <O> <T> +

<O> --> ‘+’ | ‘-‘

E equals to ‘E’ ‘O’ ‘T’

Where

E is expression

O is operator which can be ‘+’ or ‘-‘

T is term which is one or more.

Answer 2.

actual-type: a synthesized attribute which stores the actual type of a <VAR> or an <EXPRESSION>. In the case of an <EXPRESSION> , the type is computed given the types of the component <VAR>s.

expected-type: an inherited attribute which stores the expected type of <EXPRESSION> . It is determined by the type of the <VAR> on the left-hand-side of the expression statement.


Related Solutions

Create an E/R diagram for the following business situation and convert the diagram into a set...
Create an E/R diagram for the following business situation and convert the diagram into a set of related tables: A health insurance company sells a number of insurance policies. Employer companies can buy any number of policies including zero and up to 4. A policy must be bought by at least one employer. Employees working for the employers can select at most one insurance policy. A policy can be selected by any number of employees including zero. Employees can add...
5-Write an EBNF rules that describes the following while statement of Java. Then, write the recursive-descent...
5-Write an EBNF rules that describes the following while statement of Java. Then, write the recursive-descent subprogram in Java or C/C++ for the EBNF rule. Please summit your source code and a screen shot of the parsing of the following examples. do { if ( number % 2 == 0 ) even ++; number=number+1; } while (number <= 10)
Rule Based System 1. Given the rule following rules from the class notes on production rules...
Rule Based System 1. Given the rule following rules from the class notes on production rules to convert an Arabic number less than 40 to a roman numeral. USING LOGIC Rule 1: if x is null then prompt the user and read x Rule 2: if x is higher than 999 then print “too Big” and make x null Rule 3: if x is between 10 and 39 then print “X” and reduce x by 10 Rule 4: if x...
Write EBNF descriptions for the following: • a Java For each statement Assume that EBNF descriptions...
Write EBNF descriptions for the following: • a Java For each statement Assume that EBNF descriptions for statement(s), type, array, white space are given. (statmnts, type, array, and whitespace respectively) You have to create EBNF descriptions for For each statement and also variable. Use the following Java variable naming rules to create EBNF description for variable. o All variable names must begin with a letter of the alphabet, an underscore ( _ ) , or a dollar sign ( $...
PCAOB Rules Rule 3520—Auditor Independence Rule 3521—Contingent Fees Rule 3522—Tax Transactions Rule 3523—Tax Services for Persons...
PCAOB Rules Rule 3520—Auditor Independence Rule 3521—Contingent Fees Rule 3522—Tax Transactions Rule 3523—Tax Services for Persons in Financial Reporting Oversight Roles Rule 3526 establishes guidelines when an accounting firm should discuss with the audit committee of the client information with respect to any relationships between the firm and the entity that might bear on auditor independence. Under the rule, a registered public accounting firm must do the following: Page 252 Prior to accepting an initial engagement, pursuant to the standards...
Which one of the following terms is the name for a set of rules describing how...
Which one of the following terms is the name for a set of rules describing how the corporation regulates its existence (ex. how directors are elected)? Multiple Choice Articles of incorporation. Corporate breakdown. Legal liability. Bylaws. Agency problem.
please explain the multiplication rule as it applies to the Rules of Probability in at least...
please explain the multiplication rule as it applies to the Rules of Probability in at least 400 words
Construct NFA of following languages and convert it to equivalent DFA. The set of all binary...
Construct NFA of following languages and convert it to equivalent DFA. The set of all binary strings such that 3th symbol from right end is 0.
Consider the following simple ingress ACL with three rules: Rule 1. If TCP destination port=80 or...
Consider the following simple ingress ACL with three rules: Rule 1. If TCP destination port=80 or TCP destination port=443, then allow connection. Rule 2. If TCP destination port=25 and IP destination address=60.47.3.35, then allow connection. Rule 3. Disallow ALL connections. Now answer the following questions: Why is Rule 2 safer than Rule 1? Which rule in the ACL represents the default behaviour of SPI firewalls for ingress connection-opening attempts? Given the above ACL, what would the firewall do with an...
Explain what a Liability Rule is and the role of liability rules to internalize externalities. Be...
Explain what a Liability Rule is and the role of liability rules to internalize externalities. Be specific in your answer, (examples help) and describe: what are the external costs and who bears them? Why might these costs not be taken into account in decision-making of those who would generate the costs? How do Liability rules internalize these costs? What is necessary for liability rules to alter decisions sufficiently to fully take these costs into account? In what circumstances are liability...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT