Purchase Solution

BNF grammar and parse tree

Not what you're looking for?

Ask Custom Question

1. Write a BNF grammar that describes the structure of a nonterminal called <number>. Assume that <number> contains an optional + sign followed by exactly 2 decimal digits, the first of which cannot be a 0. Thus 23, +91, and +40 are legal, but 9, +01, and 123 are not.

Using this grammar, show a parse tree for the value +90.

2. Write a BNF grammar for identifiers that consist of an arbitrarily long string of letters and digits, the first one of which must be a letter.

Using this grammar, show a parse tree for the identifier AB5C8.

Attachments
Purchase this Solution

Solution Summary

Answer shows the parse trees (drawn neatly) in text mode.

Solution Preview

1. BNF grammar :

<number> ::= + <nzdigit> <digit> | <nzdigit> <digit>
<digit> ::= 0 | <nzdigit>
<nzdigit> ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Parse tree for +90 :

number
/ |
+ |
nzdigit
| digit
9 |
...

Purchase this Solution


Free BrainMass Quizzes
C# variables and classes

This quiz contains questions about C# classes and variables.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Basic Networking Questions

This quiz consists of some basic networking questions.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.