0

I'm having a hard time with this textbook and my professor sees answering questions as unfair to the students who already know the material coming into the class (getting feedback from this guy is a data mining process in and of itself). Anyways, my question revolves around derivations for CFG's (formal languages/functional programming class).

Given a context free grammar that looks like: 
S-> a|B
B-> b|C
C-> c

find the left most derivation. Is is simply a? because S->a is the left-most rule in S->a|B? or do I just conclude that the derivation can be either a, b, or c? I'm really confused on which rule to actually choose, I've been blowing through these problems just going in left-right sequential order for picking the rules on each (left-most) variable analyzed, but this one doesn't have recursion in it so I'm not sure what to do. I would very much appreciate any insight on this, I've watched videos and read the book, but no one seems to talk about this scenario. Thanks.

Also, our book: http://cglab.ca/~michiel/TheoryOfComputation/TheoryOfComputation.pdf

Rashwan L
  • 38,237
  • 7
  • 103
  • 107
zodian
  • 23
  • 1
  • 6
  • Find the left-most derivation of *what*? – rici Dec 03 '15 at 01:55
  • "The typical left most derivation for the grammar." An example I know how to do would be something like S->aSc|b. Solution being S=>aSc=>aaScc=>aabcc -and I can then use aabcc as a string in an LL parse/PDA. – zodian Dec 03 '15 at 02:27
  • Wikipedia has a reasonable explanation of what "leftmost derivation" means: https://en.wikipedia.org/wiki/Context-free_grammar#Derivations_and_syntax_trees Note that unless some production has more than one non-terminal in its right-hand side, there will never be more than one non-terminal in a partial derivation and thus all derivations will be both leftmost *and* rightmost. – rici Dec 03 '15 at 02:49

1 Answers1

0

You have no string to derive from.That is why you're having a hard time for that. The given you gave to us is just the production rules.

So for example, our grammar looks like this

S -> A + B | a | b A -> B + B | a | b B -> a | b | c

Let's say we are about to find the leftmost-derivation of string a+b+c.

then, this is the time we are going to consult the production rules.

let's start the derivation with the starting symbol

S => A + B (S has been derived to A + B )

A + B => B + B + B (A, the leftmost variable has been derived to B + B)

B + B + B => a + B + B (B, the leftmost variable has been derived to a)

a + B + B => a + b + B (B, the leftmost variable has been derived to b)

a + b + B => a + b + c (the remaining B, and the leftmost B has been derived to c)

since the final string we've generated ( a + b + c ) matched to the

string we're about to derive ( a + b + c ), then we've finished the derivation using leftmost derivation.