7 Replies - 977 Views - Last Post: 08 September 2016 - 11:35 AM

#1 Dinomite07  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 9
  • Joined: 07-September 16

Recursive Gramm-a-r

Posted 07 September 2016 - 04:35 PM

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 Xs, Ys and Zs. 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

Is This A Good Question/Topic? 0
  • +

Replies To: Recursive Gramm-a-r

#2 Dinomite07  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 9
  • Joined: 07-September 16

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 Xs, Ys and Zs. 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 Xs, Ys and Zs. 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
Was This Post Helpful? 0
  • +
  • -

#3 Dinomite07  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 9
  • Joined: 07-September 16

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 Xs, Ys and Zs. 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
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12134
  • View blog
  • Posts: 45,117
  • Joined: 27-December 08

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.
Was This Post Helpful? 0
  • +
  • -

#5 Dinomite07  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 9
  • Joined: 07-September 16

Re: Recursive Gramm-a-r

Posted 07 September 2016 - 05:18 PM

View Postmacosxnerd101, on 07 September 2016 - 05:09 PM, said:

Please do not open duplicate threads. Is there a C/C++ specific question? If not, I will move this to the Computer Science forum.

Please delete this thread, I am going to make a new one in the CS forum
Was This Post Helpful? -1
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12134
  • View blog
  • Posts: 45,117
  • Joined: 27-December 08

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.
Was This Post Helpful? 0
  • +
  • -

#7 mojo666  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 408
  • View blog
  • Posts: 882
  • Joined: 27-June 09

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>


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}


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.
Was This Post Helpful? 1
  • +
  • -

#8 andrewsw  Icon User is offline

  • lashings of ginger beer
  • member icon

Reputation: 6340
  • View blog
  • Posts: 25,565
  • Joined: 12-December 12

Re: Recursive Gramm-a-r

Posted 08 September 2016 - 11:35 AM

grammar not grammer :rolleyes2:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1