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

Very easy: Write an EBNF rule that describes the following for statement in Java for (...
Very easy: Write an EBNF rule that describes the following for statement in Java for ( counter = 1; counter <= 10; counter ++) { sum=sum+1; } Then test your EBNF rule in Java as a recursive-descent subprogram
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...
Can following BNF convert to CFG (Context Free Grammar) <Boolean_expr> → <Boolean_expr>||<Boolean_term>|<Boolean_term> <Boolean _term> → <Boolean...
Can following BNF convert to CFG (Context Free Grammar) <Boolean_expr> → <Boolean_expr>||<Boolean_term>|<Boolean_term> <Boolean _term> → <Boolean _term> && <Boolean _factor>| <Boolean _factor> <Boolean _factor> →ID | !<Boolean _factor>| (<Boolean _factor>) |<relation_expr> <relation_expr> → ID==ID | ID !=ID | ID < ID | ID≤ID | ID>ID | ID>=ID The above BNF is for Boolean Expression and Relational Expression.
Q1.Convert C46C000016 into a 32-bit single-precision IEEE floating-point binary number.
Q1.Convert C46C000016 into a 32-bit single-precision IEEE floating-point binary number.
Q1. a. Given a schema R (A, B, C, D, E, F) and a set F...
Q1. a. Given a schema R (A, B, C, D, E, F) and a set F of functional dependencies {A → B, A → D, CD → E, CD → F, C → F, C → E, BD → E}, find the closure of the set of functional dependencies ?+ b. Given a schema R = CSJDPQV and a set FDs of functional dependencies FDs = {C → CSJDPQV, SD → P, JP → C, J → S} 1. Find...
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.
Answer the following questions based on HSAB theory. If using Fajans Rules, give the rule number...
Answer the following questions based on HSAB theory. If using Fajans Rules, give the rule number and explain why it applies. 1. Explain why aluminum perchlorate is less soluble than aluminum cyanide. This is unusual since perchorates tend to be very soluble. 2. Explain why the Ksp for FeBr2 is 4.1 x 10–4 and the Ksp for FeF2 is 3.2 x 19–7. 3. Explain why the Ksp for Fe(OH)3 is 1.2 x 10–36 and the Ksp for Fe(OH)2 is 7.8...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT