Question

a) Give a Backus-Naur Form (BNF) grammar for Java integer literals (decimal, hexa, octal). b) Show...

a) Give a Backus-Naur Form (BNF) grammar for Java integer literals (decimal, hexa, octal).

b) Show a BNF grammar that is ambiguous.

c) Is a BNF able to express “the maximum of a byte literal is 127” ? Why or why not?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a)

<package name> :::くidentifier <package name>·</dentifier <type name> ::-«identiner> 1 <package name>·</dentiner> simple type

cexponent indicetoo e|E sign> «noet type sumx> ::zfIFIdID boolean itea true false «character literal> ::-·«single character>-

This is the BNF Grammar for Java Literals. Although the question has asked for integer literals only, other literals (floating-point, boolean, character, string etc.) have been added for completeness and clarity.  

b)

where x,y,z are terminals.

This grammar is ambiguous because the string yyxzx can have either of these two parse trees:

yAz A I1 yAz A y A x

c)

A BNF Grammar will not be able to express "the maximum of a byte literal is 127" because it cannot count. A BNF Grammar can only tell if a particular string is part of the grammar or not. There is nothing limiting the recurrence at 127 or for that matter any number. This may not cause a problem during compilation, however the code will be buggy because of this error during execution.

Add a comment
Know the answer?
Add Answer to:
a) Give a Backus-Naur Form (BNF) grammar for Java integer literals (decimal, hexa, octal). b) Show...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT