I was wondering if I am answering these questions correctly. And how would I start off on the pseudo code for the recursive function?
Consider a language of strings that contains only X’s, Y’s and Z’s. A string in this language must begin with an X. If a Y is present in a string, it must be the final character of the string.
a. Write a recursive grammar for this language.
<string> = <X>|<body>|<Y>
<X> = X
<Y> = Y
<Z> = Z
<body> = <X>|<Z>
b. Write all the possible two-character strings of this language.
{X,Y}, {Z,Y}, {X,Z}, {Z,X}
Consider the following grammar:
<G> = empty string |<E>|<V><E>|<E><G><V>
<E> = &|#
<V> = W|A
a. Write pseudo code for a recursive function that returns true if a string is in this language and returns false otherwise.
b. Is the string &W#W in this language?
<E><V><E><V> is not possible.
No
Recursive Gramm-a-r
Page 1 of 17 Replies - 1906 Views - Last Post: 08 September 2016 - 11:35 AM
Replies To: Recursive Gramm-a-r
#2
Re: Recursive Gramm-a-r
Posted 07 September 2016 - 05:05 PM
DELETE
IGNORE FIRST TWO POSTS
I was wondering if I am answering these questions correctly.
Consider a language of strings that contains only X’s, Y’s and Z’s. A string in this language must begin with an X. If a Y is present in a string, it must be the final character of the string.
a. Write a recursive grammar for this language.
<X> = X
<Y> = Y
<Z> = Z
<body> = <X>|<Z>
<string> = <X>|<body>|<Y>
b. Write all the possible two-character strings of this language.
{X,Y}, {Z,Y}, {X,Z}, {Z,X}
Consider the following grammar:
<G> = empty string |<E>|<V><E>|<E><G><V>
<E> = &|#
<V> = W|A
a. Write pseudocode for a recursive function that returns true if a string is in this language and returns false otherwise.
IsIdentLegal (Iden: String) Boolean
If (Iden length is 1)
If (Iden is <G> || <E> || <V>)
Return true
Else
Return false
Else If (Iden.length < 1)
Return false
b. Is the string &W#W in this language?
<E><V><E><V> is possible.
Yes
I was wondering if I am answering these questions correctly.
Consider a language of strings that contains only X’s, Y’s and Z’s. A string in this language must begin with an X. If a Y is present in a string, it must be the final character of the string.
a. Write a recursive grammar for this language.
<X> = X
<Y> = Y
<Z> = Z
<body> = <X>|<Z>
<string> = <X>|<body>|<Y>
b. Write all the possible two-character strings of this language.
{X,Y}, {Z,Y}, {X,Z}, {Z,X}
Consider the following grammar:
<G> = empty string |<E>|<V><E>|<E><G><V>
<E> = &|#
<V> = W|A
a. Write pseudocode for a recursive function that returns true if a string is in this language and returns false otherwise.
IsIdentLegal (Iden: String) Boolean
If (Iden length is 1)
If (Iden is <G> || <E> || <V>)
Return true
Else
Return false
Else If (Iden.length < 1)
Return false
b. Is the string &W#W in this language?
<E><V><E><V> is possible.
Yes
[/quote]
DELTE THIS THREAD please
IGNORE FIRST TWO POSTS
I was wondering if I am answering these questions correctly.
Consider a language of strings that contains only X’s, Y’s and Z’s. A string in this language must begin with an X. If a Y is present in a string, it must be the final character of the string.
a. Write a recursive grammar for this language.
<X> = X
<Y> = Y
<Z> = Z
<body> = <X>|<Z>
<string> = <X>|<body>|<Y>
b. Write all the possible two-character strings of this language.
{X,Y}, {Z,Y}, {X,Z}, {Z,X}
Consider the following grammar:
<G> = empty string |<E>|<V><E>|<E><G><V>
<E> = &|#
<V> = W|A
a. Write pseudocode for a recursive function that returns true if a string is in this language and returns false otherwise.
IsIdentLegal (Iden: String) Boolean
If (Iden length is 1)
If (Iden is <G> || <E> || <V>)
Return true
Else
Return false
Else If (Iden.length < 1)
Return false
b. Is the string &W#W in this language?
<E><V><E><V> is possible.
Yes
I was wondering if I am answering these questions correctly.
Consider a language of strings that contains only X’s, Y’s and Z’s. A string in this language must begin with an X. If a Y is present in a string, it must be the final character of the string.
a. Write a recursive grammar for this language.
<X> = X
<Y> = Y
<Z> = Z
<body> = <X>|<Z>
<string> = <X>|<body>|<Y>
b. Write all the possible two-character strings of this language.
{X,Y}, {Z,Y}, {X,Z}, {Z,X}
Consider the following grammar:
<G> = empty string |<E>|<V><E>|<E><G><V>
<E> = &|#
<V> = W|A
a. Write pseudocode for a recursive function that returns true if a string is in this language and returns false otherwise.
IsIdentLegal (Iden: String) Boolean
If (Iden length is 1)
If (Iden is <G> || <E> || <V>)
Return true
Else
Return false
Else If (Iden.length < 1)
Return false
b. Is the string &W#W in this language?
<E><V><E><V> is possible.
Yes
[/quote]
DELTE THIS THREAD please
#3
Re: Recursive Gramm-a-r
Posted 07 September 2016 - 05:04 PM
I was wondering if I am answering these questions correctly.
Consider a language of strings that contains only X’s, Y’s and Z’s. A string in this language must begin with an X. If a Y is present in a string, it must be the final character of the string.
a. Write a recursive grammar for this language.
<X> = X
<Y> = Y
<Z> = Z
<body> = <X>|<Z>
<string> = <X>|<body>|<Y>
b. Write all the possible two-character strings of this language.
{X,Y}, {Z,Y}, {X,Z}, {Z,X}
Consider the following grammar:
<G> = empty string |<E>|<V><E>|<E><G><V>
<E> = &|#
<V> = W|A
a. Write pseudocode for a recursive function that returns true if a string is in this language and returns false otherwise.
IsIdentLegal (Iden: String) Boolean
If (Iden length is 1)
If (Iden is <G> || <E> || <V>)
Return true
Else
Return false
Else If (Iden.length < 1)
Return false
b. Is the string &W#W in this language?
<E><V><E><V> is possible.
Yes
Consider a language of strings that contains only X’s, Y’s and Z’s. A string in this language must begin with an X. If a Y is present in a string, it must be the final character of the string.
a. Write a recursive grammar for this language.
<X> = X
<Y> = Y
<Z> = Z
<body> = <X>|<Z>
<string> = <X>|<body>|<Y>
b. Write all the possible two-character strings of this language.
{X,Y}, {Z,Y}, {X,Z}, {Z,X}
Consider the following grammar:
<G> = empty string |<E>|<V><E>|<E><G><V>
<E> = &|#
<V> = W|A
a. Write pseudocode for a recursive function that returns true if a string is in this language and returns false otherwise.
IsIdentLegal (Iden: String) Boolean
If (Iden length is 1)
If (Iden is <G> || <E> || <V>)
Return true
Else
Return false
Else If (Iden.length < 1)
Return false
b. Is the string &W#W in this language?
<E><V><E><V> is possible.
Yes
#4
Re: Recursive Gramm-a-r
Posted 07 September 2016 - 05:09 PM
Please do not open duplicate threads. Is there a C/C++ specific question? If not, I will move this to the Computer Science forum.
#5
Re: Recursive Gramm-a-r
Posted 07 September 2016 - 05:18 PM
#6
Re: Recursive Gramm-a-r
Posted 07 September 2016 - 06:59 PM
I will move this thread to the Computer Science forum. Consider this a formal warning to stop spamming your post. If you are doing so to get edit permissions, I will move you to the Restricted Editors group which will permanently restrict your editing permissions.
#7
Re: Recursive Gramm-a-r
Posted 08 September 2016 - 08:42 AM
Quote
a. Write a recursive grammar for this language.
<X> = X
<Y> = Y
<Z> = Z
<body> = <X>|<Z>
<string> = <X>|<body>|<Y>
<X> = X
<Y> = Y
<Z> = Z
<body> = <X>|<Z>
<string> = <X>|<body>|<Y>
Typically, a recursive string would need to recurse. An example would be <body> = X<body>|Y. This rule produces all strings of any number of X's followed by a Y. These rules function by replacement. You start with <body> and replace it with one of the two possibilities from the rule until you are left with nothing to replace. So, to produce the string XXXY
<body> //Start X<body> //I chose first option to replace <body> XX<body> //I chose first option XXX<body> //I chose first option XXXY //I chose second option. Nothing left to replace
With the grammer you produced we can only do the following
<string> //start <X> //first option X //finished <string> //start <Y> Y //finished <string> //start <body> <X> X //finished <string> //start <body> <Z> Z //finished
Doesn't even come close to what you need.
Quote
b. Write all the possible two-character strings of this language.
{X,Y}, {Z,Y}, {X,Z}, {Z,X}
{X,Y}, {Z,Y}, {X,Z}, {Z,X}
Strings in the language must begin with X, so this is wrong. You do have 2 of the 3 possible strings though.
Quote
a. Write pseudocode for a recursive function that returns true if a string is in this language and returns false otherwise.
Your pseudo code doesn't work. If I pass the string &W it is supposed to return true. Your code wouldn't even return.
Page 1 of 1

New Topic/Question
Reply


MultiQuote







|