Questions tagged [context-free-language]

In formal language theory, a context-free language (CFL) is a language generated by some context-free grammar (CFG). The set of regular languages is a subset of the set of context-free languages.

183 questions
3
votes
1 answer

How to create a context-free grammar?

I am learning compilers and I am troubled by how to create the context-free grammar of a language. Is there a method I can follow to create the context-free grammar for most language ? I'm new to this field so the question is basic,and I hope you…
2
votes
1 answer

Context-free grammar for language describing a, ab, abc, ac...?

I'm trying to figure out what will be the CFG for a language described like that: only one a 0 or more b 0 or more c I tried this: S -> a | Sb | Sc Or something like that: S -> a | B | C B -> Bb C -> Cc but it doesn't seem to work. Is there any…
Corei7
  • 43
  • 2
2
votes
3 answers

Constructing CFG for even length words with maximum of two 0's

I am struggling to construct a good CFG for a L={xE{0,1}* | that is of even length and have a maximum of two 0s} So words like L={11, 10, 0011...} I am trying with the following attempt. S -> E | E0A | A0E | E0E0E | 00EA | EA00 E-> 1A | e A ->…
2
votes
2 answers

Are there any languages such that they are proper subsets of each other and satisfy these conditions

Are there languages such that A ⊂ B ⊂ C ⊂ D ⊂ E over the alphabet {a,b,c} where: A is not context-free B is context-free and non-regular C is regular D is non regular E is regular and not {a,b,c}*
2
votes
1 answer

All the strings X2Y where X and Y are composed of 0s and 1s and X ≠ Y

This problem was taken from A. Shen's book "Algorithms and Programming. Problems and Solutions". The problem itself was communicated by M. Sipser. The author asks the reader to define a context-free grammar which generates the following…
2
votes
1 answer

CFG: Why is this grammar ambiguous?

The grammar is as follows. S -> SS' | a | b S' -> a | b The way I understand it, derivations from this grammar will be like SS'S'S'S'... (0 or more S'), where each S or S' will generate a or b. Can someone provide an example that shows this grammar…
2
votes
2 answers

Context-free grammar for the language L = {a^(n)b^(m)c^(k): m = |i - k|}

I have this language L = {a^n b^m c^k: m = |n - k|}. I know m = |n - k| can be expressed in two ways 1) m = n - k for n >= k or n = m + k 2) m = k - n for k >= n or k = m + n Therefore, I get two languages where L1 = {a^n b^m c^k: n = m + k}…
2
votes
1 answer

How do you determine if a language is regular, context free but not regular, or not context free?

I have a homework problem that requires you to prove if a language is one of the three: A Regular Language Context-Free but Not Regular Not Comtext-Free How would you prove each one? I know Pumping Lemma can verify if a language is Not Regular…
2
votes
1 answer

Is the the set difference of 2 context free languages context free?

I've searched on the internet and most say just say that context free languages are closed for union, concatenation, reversal, and Kleene Star. Are they also closed for set difference?
2
votes
0 answers

Given the following language L, provide a CFG or prove it isn't context free

I was shown this at university lecture as a optional challenge problem but have no idea how to work it out. Let L be the language L = {apbqapbq : p,q >= 0}. Is this language context-free? Either give a context-free grammar for it or prove that it is…
2
votes
1 answer

LL(1) Parse table for S → a | ba | c

I'm new to LL(1) parsing and am currently trying to figure out how to create a parse table for the language: S → Saa|b and S-> A|B A-> aa B-> bb and S → AB A → aa B → bb
2
votes
1 answer

Is there a regular expression that return substrings from a string, that do not match a given list of specific substrings?

Hi I am wondering if there is a regular expression that can do the following: Select all the substrings from a string that : start with & and have n number of characters after the & (n >= 0) AND those substrings are NOT & ' < >…
2
votes
1 answer

Pushdown Automata for Palindrones

So I've found this PDA to accept palindromes in the language {0,1}*. However, I'm failing to understand how it could could accept '1' or '0'. In B it can read a 1 or 0 and push the same symbol to the stack and then go to C. However once it's in C,…
2
votes
1 answer

Does there exist a context-free grammar for {0^i1^j such that 1 <= i <= j <=2i }?

I have come across two completely different answers. One says that: Yes, there does exist a context-free grammar for {0i1j | 1≤i≤j≤2i}, the following grammar ensures that there can be half or lesser 0’s for the 1’s that are present: S -> 0S11 |…
rgs
  • 125
  • 1
  • 6
1
vote
1 answer

CFG for L={ a^n b^m : n <= m+3 , n,m>=0}

I want to find Context Free Grammar for L={ a^n b^m : n <= m+3 , n,m>=0} What I have so far S -> AAAB A -> a | ε B -> aBb | Bb | ε Does this make any sense?
1
2
3
12 13