00:01
We're asked to construct a phrase structure grammar that generates all signed decimal numbers consisting of a sign either plus or minus, a non -negative integer, and the decimal fraction that is either the empty string or a decimal point followed by a positive integer, where initial zeros in an integer are allowed.
00:31
So this is actually pretty straightforward.
00:40
We have that from our start symbol s will produce sign followed by integer.
01:01
From our start symbol s, we could also produce sine integer.
01:12
So bracket, sign, bracket integer, and then a decimal point followed by bracket positive integer.
01:26
Now for sign, we have that bracket sign produces plus or bracket sign produces minus.
02:00
For integer, we have bracket integer produces bracket integer, bracket digit, i guess bracket digit, bracket digit.
02:23
We have that it can also produce bracket integer, can produce bracket digit.
02:44
In case our integer is only one digit.
02:57
Now, for a positive integer, we have bracket positive integer.
03:18
This can produce, i think here to keep continuity.
03:22
I'll actually change some things around.
03:24
So before we add integer, bracket integer produces digit integer.
03:29
Inside we have, let's do bracket integer produces integer digit.
03:33
We'll see why in just a second.
03:42
So bracket positive integer produces integer followed by 9.
03:52
0 digit followed by integer.
04:13
We also have the positive integer produces in the case that we just end with a non -zero digit integer followed by non -zero digit and finally when we have the two other cases positive integer produces non -zero digit followed by integer and finally we have positive integer produces a non -zero digit this is in the case that our decimal only has one digit after the decimal point.
05:59
Now we know that digit can produce a non -zero digit, although it won't always, because in the other case, we have a digit will be producing a zero.
06:18
And this is a terminal symbol.
06:22
And we know that non -zero digits are obviously going to produce digits 1 through 9.
06:27
So non -zero digit produces one, non -zero digit, produces a 2 and here i'm just going to skip instead of writing all these non -zero digit produces a 9 so 1 through 9 and so this is going to be the grammar for part a now in part b we're asked to give the bacchus naur form of this grammar this is pretty easy to do all we have to do is combine productions from the previous answer that all have the same left -hand side and we'll change the notation.
07:32
So for example, starting off with signed decimal number, well we saw earlier that this produced, this was really our start state s, this produced sign integer on the one hand, or sorry, sine integer.
08:36
Of course, i could also produce sign, bracket, integer, decimal point, bracket, positive number, or positive integer.
09:03
And that vertical line just means that either outcome gives a possible production.
09:10
Now for sign, you see bracket, sign has two columns, followed by an equals sign, and then sign can be plus, or can be minus.
09:23
We have the vertical line, and then we have a minus.
09:30
So for integer, see the integer produces either integer digit or produces digit...