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

1-Give a BNF grammar (do not use EBNF) for the language that generates the set of...
1-Give a BNF grammar (do not use EBNF) for the language that generates the set of all strings consisting of the keyword begin, followed by zero or more statements with a semicolon after each one, followed by the keyword end. Use the non-terminal for statements, and do not give productions for it. 2-Give a BNF grammar (do not use EBNF) for the language that generates the set of all strings consisting of the keyword begin, followed by one or more...
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...
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...
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)
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...
a): Suppose we have developed the following rules and facts for our system. Rule 1: If...
a): Suppose we have developed the following rules and facts for our system. Rule 1: If X is an animal then X is living spices Rule 2: If X is living spices then X is a life form Rule 3: If X is a life form then X is mortal Fact: Dog is an animal. Goal: Is Dog a mortal? Problem: Using forward chaining, try to conclude that Dog is mortal. b)The following is the rule set of a simple...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT