Write a python parser program that uses the following context free grammar
<S> → ‘a’ <S> ‘b’
<S> → ‘c’
Test your parser with c, acb, aacbb, λ, ca, ab,acbb, aacb, and bca(λ represents a null string)


Code
s = input('Enter String: ')
s = list(s)
buff = ['S']
print('Input',s,' Buffer',buff)
while s!=[]:
if buff==[]:
break
if s[0]==buff[0]:
print('Match ',s.pop(0))
buff.pop(0)
elif buff[0]=='S':
buff.pop(0)
if s[0]=='a':
buff=['a','S','b']+buff
print('Using Production S->aSb')
elif s[0]=='c':
buff=['c']+buff
print('Using Production S->c')
else:
print('Error in parsing!! No Production found!!')
break;
else:
print('Error in parsing!! Mismatch found')
break;
print('Input',s,' Buffer',buff)
if s==[] and buff==[]:
print('Parsing complete!!')
else:
print('Parsing failed!!')
Write a python parser program that uses the following context free grammar <S> → ‘a’ <S>...
6. (5 points) Consider the context free grammar G = (V, E, R, S) where V is {S, A, B, a, b,c}, & is {a,b,c}, and R consists of the following rules: S + BcA S B +a → A S + b A+S Is this grammar ambiguous? swer. Justify your an-
Give a context-free-grammar describing the syntax of the
following language.
Thank you =)
Give a context-free-grammar describing the syntax of the following language: L = { ww| we{a, b }" } is a context- free language, where w is a non-empty string from alphabet {a, b } and wt denotes the reversal of string w.
Q1: Given the below language and context free gramma:, a. Show that the grammar is ambiguous using the string ( abc) by using substitutions. b. Then design a push down automata that recognizes the language. C. Then show the tracing of (abc, abbccc) using the push down automata. d. Then Show which two simple languages create the greaterlanguage. Give set builder notation for each language. e. Then produce Chomsky normal form for the grammar. The following context-free language is inherently...
Write a context-free grammar that generates the same language as regular expression which is ab*|c+ (Describe the four components of context-free grammar which are start symbol(S), non-terminals(NT), terminals(T), and set of production rules(P))
Given the following ambiguous context free grammar (3x20) 1. (a) Explain why the grammar is ambiguous (b) Find an equivalent unambiguous context-free grammar. (c) Give the unique leftmost derivation and derivation tree for the string s generated from the unambiguous grammar above. 2. Construct non-deterministic pushdown automata to accept the following language (20) 3. Convert the following CFG into an cquivalent CFG in Chomsky Normal Form (CNF) (20)-
Please help with the following context free grammar over alphabet (0,1): S —> A | B A —> 1S | ^ B—> 0S | ^ a. Show that the grammar is ambiguous for a non-empty string. b. Convert the CFG to Chomsky normal Form.
4. Consider the following context-free grammar S SSSS a (a) Show how the string aa+a* can be generated by this grammar (b) What language does this grammar generate? Explain
Write a context-free grammar for the language where all strings are of even length and the first half of the string is all 0’s, but it must be an odd number of 0’s
1)Convert the following context free grammar to Chomsky Normal Form S → a X | Yb X → S | λ Y → b Y | λ 2)Some languages distinguish between uppercase and lowercase in identifiers. What are the pros and cons of this design decision? 3)Use the pumping lemma to prove that the following languages are not regular. (The alphabet is Σ = {a, b}.) a) L = {an b1 ak: k >= n+ l} b) L = {ww:...
The following shows a context-free Tammar on {0, 1}. Show that the grammar is ambiguous by generating 2 derivation sequences for word 00111. S > AS5 A → Al|0A101 The following is a context-free grammar on alphabet {a}. Use the string a +a- a to verify whether or not the grammar is ambiguous. AA+AA-AA The following is a gamar equivalent to the one shown above in problem (5). Is it ambiguous? Use a +a- a to verify it. A →...