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.
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)
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)*
Convert the grammar G = ({S,A,B,C},{a,b},P,S), where P is given below, into the Chomsky Normal Form....
Convert the grammar G = ({S,A,B,C},{a,b},P,S), where P is given below, into the Chomsky Normal Form. S −→ AaA | AB A −→ BB | bAA | ε B −→ bS | b | ε
Consider the following grammar (A and B are non-terminals) A → A a | B |...
Consider the following grammar (A and B are non-terminals) A → A a | B | B d B → b d | b Are there any ambiguities? If so, please give an example.
give an example of measurement on a ratio scale then convert the measurement to a lower...
give an example of measurement on a ratio scale then convert the measurement to a lower level of measurement
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT