954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Algorithm: BNF question

How do i get from 2 character words to 4 character words or 5 character words??
can anyone show me how to do that plz...


Q) Consider a language of words, where each word is a string of dots and dashes. The following grammar describes this language:

::= | | ::= .
::= -

The meta-symbols of BNF are:

::= meaning “is defined as
| meaning is “or
<> angle brackets are used to surround category names

Question: List all strings with exactly three characters that are in this language?
Is the string ...---(three dots followed by three dashes) in this language?

Let's start listing the possible words. The only word consisting of one character is a single dot. By applying the second production rule, you can add a dash in front of the word, which gives you . If you apply the third rule instead, you add a dot after the first dot, resulting in .

So now I have two valid words consisting of two characters each:

-.
..

Now I can go on and apply the two production rules again to these two words, resulting in four three-character words. Of course, in the same way, you get 8 four-character words, 16 five-character words and so on.

How do I apply the production rule to get to the four 3 character word??

jack223
Light Poster
27 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 

I came up with three three-character words:

...
-..
--.


I don't see how to create the fourth one.

agiorgio
Newbie Poster
15 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

I came up with three three-character words:

... -.. --.

I don't see how to create the fourth one.

That's what I got too....the fourth one is "-.." which already exist so it doens't count.


I have another question and this one is little harder. = aa | bb | a | b

Q: list all the 5-character strings that are in this language?

My answer is there are four 5-character strings in this language and they are "ababa" , "abbba" , "baaab" , "babab".....is this right??

= aa
= bb
= a
= b

so therefore, = abba = ababa or abbba

and = bb = baab = baaab or babab

jack223
Light Poster
27 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You