Write a regular expression that captures the same language as the following context-free grammar:
S → p R v S → q R v R → u R R → u
Give two six-symbol strings that are in the language defined by the following context-free grammar:
S → a S d S → a T d T → b c T → b T cThen give a concise English language description for the set of strings specified by the grammar.
Consider the following context-free grammar:
A → t A e A A → t A A → x
Write two sentences consisting of five or more symbols that are in the language specified by the grammar.
Is the grammar ambiguous? If so, write a sentence and two different parse trees that illustrate that fact. If not, give an argument why not.
def matchE(tokens):
if len(tokens) == 0:
raise ParseError('unxpected end of input')
elif tokens[0] == "n":
matchChar(tokens, 'n')
else:
matchChar(tokens, '(')
matchE(tokens)
matchChar(tokens, '+')
matchE(tokens)
matchChar(tokens, ')')
def matchChar(tokens, c):
if len(tokens) == 0:
raise ParseError('unxpected end of input')
elif tokens[0] == c:
tokens.pop(0) # eat character c from token stream
else:
raise ParseError('%c expected' % c)
Write a context-free grammar that corresponds to this parser.
Suppose we wrote a similar parser for this grammar:
E → n E → E + EWhat problems might we encounter when we run our program?
Do one of the following:
Write a computer program in a language of your choosing that takes a context-free grammar for an input and returns true if and only if the grammar is unambiguous.
or
Write a brief explanation of why you feel that the first part of this question is not a fair question to ask on this problem set.