# -*- coding: utf-8 -*-
'''
Created on Aug 18, 2013

@author: shywel


'''
"""
Another Grammar by Dimitris -GR

Given the following grammar:

something  --> Word something
something  --> Word
word  --> Hey!
word  --> Listen!

in Backus - Naur Form, which of the following sentences "CAN NOT " be derived from this grammar, starting from something ?
ver: http://es.wikipedia.org/wiki/Backus-Naur_form
------------------

Instructor Notes

Here is the grammar written in a way that more clearly distinguishes nonterminals (Italics) and terminals (bold):

Something -> Word Something
Something -> Word
Word -> Hey!
Word -> Listen!

Check the box for each string that cannot be produced starting from Something.

---------------------------

1). Hey!
2). Hey! Listen!
3). Hey! Listen! Watch out!  --> Esta no seria derivada de esta gramatica. Whtch out! no está como 'terminal'
4). Hey! Hey! Hey! Listen! Listen! Listen! Listen! Hey!
5). Hey! Hey! Hey! Listen!! Listen! Listen!  --> Esta no derivaria de esta gramatica. Listen con dos !! no está como 'terminal'

"""



#===============================================================================
# The first, second and fourth options are incorrect, since you can generate them as follows:
# 1) something-> word -> Hey!
# 
# 2) something -> word something -> word word -> Hey! word -> Hey! Listen!
# 
# 4) something -> word something -> word word something -> word word word something -> word word word word something ->
# -> word word word word word something -> word word word word word word something -> word word word word word word word ->
# -> Hey! word word word word word word -> Hey! Hey! word word word word word -> Hey! Hey! Hey! word word word word ->
# -> Hey! Hey! Hey! Listen! word word word -> Hey! Hey! Hey! Listen! Listen! word word ->
# -> Hey! Hey! Hey! Listen! Listen! Listen! word -> Hey! Hey! Hey! Listen! Listen! Listen! Hey!
# 
# Please note that text highlighted in green, denotes the use of one of the rules, as specified in the given grammar to replace a (non-terminal) value. Furthermore, please notice that all the final sequences we ended up with, cannot be further replaced, since they are composed solely of terminal values (namely: "Hey!" and "Listen!").
# 
# Options 3 and 5 CANNOT be derived with the given set of rules.
# Option 3, contains a "Watch out!" which is not known to us to be neither a terminal value like: "Hey!" and "Listen!", nor a not-terminal value like: "word" or "something".
# 
# Option 5, is a bit trickier to notice, as it contains an extra exclamation mark at some point. Our given grammar, always inserts a single exclamation mark at the end of each terminal value, but never two exclamations. As a disclaimer, this option was not intended to be THAT tricky, but was modified upon entering the "Contest" by one of the mods to help students develop a "keen eye", when it comes to reading code and detecting potential errors.
# 
# Now, regarding the starred optional question:
# You can produce infinitely many sequences by using the rule:
# something -> word something
# over and over, theoretically forever.
# 
# Hope this clarifies things up a bit. :)
# -Jim
# http://forums.udacity.com/questions/100059202/what-is-the-right-answer-for-the-optional-homework/100092857
#===============================================================================










