Question

Convert an example EBNF grammar into a BNF grammar. For an example BNF grammar, determine if...

Convert an example EBNF grammar into a BNF grammar. For an example BNF grammar, determine if it is ambiguous.Rewrite an ambiguous grammar so that it is unambiguous.

Homework Answers

Answer #1

Lets take an example of EBNF grammar:

.BNF

<expr>   :: =            <expr> + <term>

                                 | <expr> - <term>

                                 | <term>

<term> :: =            <term> * <factor>

                                | <term> / <factor>

                                | <factor>

Lets take an example of EBNF grammar:

Syntax for EBNF:-

.EBNF

<expr> :: =      <term> { (+ | -) <term> }

<term> :: =     <factor> { ( * | / ) <factor> }

<factor> :: = <exp> { ^<exp> }

<exp>       :: = (<expr> ) | id | literal

Above symbols denotes as:-

A| B      Either A or B

A*        Zero or more instance of A

A+        One or more instances of A

A?         Zero or one instance of A

For example: -

<expr> :: =      <term> { (+ | -) <term> }

<term> :: =     <factor> { ( * | / ) <factor> }

<factor> :: = <exp> { ^<exp> }

<exp>       :: = (<expr> ) | id | literal

Ex: -    (8+z )– (2*a)

Converting this to BNF grammar:-

<expr>   :: =            <expr> + <term>

                                 | <expr> - <term>

                                 | <term>

<term> :: =            <term> * <factor>

                                | <term> / <factor>

                                | <factor>

Ex:- -    (8+z )– (2*a)

For an example BNF grammar,

Now we will determine if it is ambiguous.Rewrite an ambiguous grammar so that it is unambiguous.

Let a grammar be:

E :: = E + E | E * E

E :: = id

Then with the help of this diagram we will see it is ambiguous.

For an example BNF grammar,

Now we will determine if it is ambiguous.Rewrite an ambiguous grammar so that it is unambiguous.

Let a grammar be:

E :: = E + E | E * E

E :: = id

Then with the help of this diagram we will see it is ambiguous.

Id+ id = id

It has 2 operator on either side of it.Which operator should we associate this with?

So there is an ambiguity.

So we can make write this ambiguous grammar into unambiguous:

E :: = E + T/T

T :: = T * F/ F

F :: = id

id + id * id

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Given a sample sentence and an explanation of its language, produce a BNF grammar for the...
Given a sample sentence and an explanation of its language, produce a BNF grammar for the language. Convert a BNF grammar into an EBNF grammar.
Make sure you are able to: Given a sample sentence and an explanation of its language,...
Make sure you are able to: Given a sample sentence and an explanation of its language, produce a BNF grammar for the language. Convert a BNF grammar into an EBNF grammar. Convert an EBNF grammar into a BNF grammar. Given a BNF grammar, determine if it is ambiguous. Rewrite an ambiguous grammar so that it is unambiguous. Given a BNF grammar, be able to identify the tokens which a lexical analyzer would be able to produce. Given a BNF grammar,...
Convert the following set of BNF rules to a single EBNF rule. <E> --> <E> +...
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)
Write EBNF descriptions for a C++ switch statement. Show, with examples, the EBNF grammar will work...
Write EBNF descriptions for a C++ switch statement. Show, with examples, the EBNF grammar will work on all types of switch statements. The examples should be shown in a tree format.
Show that any LL grammar is unambiguous. (Note: This is so obvious it is hard to...
Show that any LL grammar is unambiguous. (Note: This is so obvious it is hard to prove. Instead, prove the contrapositive: ambiguous implies not LL(k) for any k.)
Try to write a BNF like Grammar for each one of the following constructs: - positive...
Try to write a BNF like Grammar for each one of the following constructs: - positive and negative integer numbers - floating point numbers - variable names. Notice: Recursion is needed here (use right recursion): here is an example (a grammar of two rules defines any positive integer) : Note the length in digits is not defined in this grammar, it can go recursively for ever. So we need to add another annotation (a semantic part). <positive_Number> -> <digit> |...
Convert the following CFL grammar to an equivalent grammar in Chomsky normal form. A → BAB...
Convert the following CFL grammar to an equivalent grammar in Chomsky normal form. A → BAB | B | ε B → OO | ε
Write a BNF grammar for a new language called 4040. It should include the following rules:...
Write a BNF grammar for a new language called 4040. It should include the following rules: Variable definitions should start with var. There must be only single space after var. Variable names should come after the var and single space. Variable names should start with a letter or underscore(_). Starting with a digit is not allowed. Variable names can have digits after the first letter. There can be multiple variable names separated by comma. Between variables, spaces are allowed. There...
Convert the grammar below to Chromsky Normal Form: U --> Vab| S T--> abS|E
Convert the grammar below to Chromsky Normal Form: U --> Vab| S T--> abS|E
How to convert a Regular Expression to left-linear grammar (0+1)*00(0+1)*
How to convert a Regular Expression to left-linear grammar (0+1)*00(0+1)*
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT