| | |
Algorithm: BNF question
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2005
Posts: 27
Reputation:
Solved Threads: 0
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:
<word> ::= <dot> | <dash><word> | <word> <dot>
<dot> ::= .
<dash> ::= -
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 <dash> <dot>. If you apply the third rule instead, you add a dot after the first dot, resulting in <dot> <dot>.
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??
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:
<word> ::= <dot> | <dash><word> | <word> <dot>
<dot> ::= .
<dash> ::= -
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 <dash> <dot>. If you apply the third rule instead, you add a dot after the first dot, resulting in <dot> <dot>.
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??
•
•
Join Date: Nov 2005
Posts: 27
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by agiorgio
I came up with three three-character words:
...
-..
--.
I don't see how to create the fourth one.
I have another question and this one is little harder.
<S> = a<S>a | b<S>b | 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??
<S> = a<S>a
<S> = b<S>b
<S> = a
<S> = b
so therefore, <S> = ab<S>ba = ababa or abbba
and <S> = b<S>b = ba<S>ab = baaab or babab
![]() |
Similar Threads
- Help with HW question on STL (C)
- Same ip linkbuilding (Search Engine Optimization)
- Today Question (C)
- My question with the data type in C (C)
- Recursion: when do you use it? (C++)
Other Threads in the C Forum
- Previous Thread: Inheritance
- Next Thread: unable to access random lines within a file
| Thread Tools | Search this Thread |
#include adobe ansi api append array arrays asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic execv feet fgets file fork framework frequency function getlasterror givemetehcodez global grade gtkgcurlcompiling hacking hardware highest histogram include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue number odf opensource overwrite owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scripting segmentationfault sequential socket socketprograming standard string systemcall testing threads turboc unix user voidmain() wab windows.h windowsapi





