views:

291

answers:

2

Give the EBNF specification for the language L that is made up of the chars a, b and c such that sentences in the language have the form

L : sqsR

-s   is a string of any combination of the characters a and b
-sR  is that same string s reversed
-q   is an  odd number of c's followed by either an odd number of b's
     or an even number of a’s.

What I have so far:

L -> S
S -> {a}{b}Q
Q ->

If this is right, I'm still not really sure how to produce from Q and also how to represent S in reverse.

Any help is welcomed :)

+1  A: 
  • Try building the first two parts from the middle out
  • You can force an odd number of repetitions by starting with exactly one item and adding N*2 additional items (for integer N). This should suggest how to force an even number as well
dmckee
Thanks, this helps a bit
+1  A: 

This is a string that starts and ends with the same string, but reversed:

X -> aXa
  -> bXb

This is a string with an odd number of c's:

Y -> cY2
Y2 -> ccY2

I've left out some crucial bits, but hopefully this can get you started.

1800 INFORMATION
Thanks, I see how the odd number of c's works but I am a little confused on how that X production works to reverse a string.
It might help if you try using the X rule to produce a few strings - start with some combination of a's or b's and see what you end up with
1800 INFORMATION
The syntax is just confusing me I think; X -> aXa seems left-recursive, how would you get to -> bXb from that?
The syntax to me means X is either aXa or bXb, recursively
1800 INFORMATION
Ah, I see how that works now. Thanks so much for the help :)