Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine if a language is context free or not?

How can I know whether the languages are context free or not?

like image 710
user423733 Avatar asked Aug 18 '10 08:08

user423733


People also ask

How do you prove a language is not context-free?

The language A is not context free. We have that w ∈ A and |w| = 3n ≥ n, so the pumping lemma guarantees that there must exist strings u, v, x, y, z ∈ r∗ so that w = uvxyz and the three properties in the statement of that lemma hold: (i) vy = e, (ii) |vxy| ≤ n, and (iii) uvixyiz ∈ A for all i ∈ N.

What makes a language context-free?

A valid (accepted) sentence in the language must follow particular rules, the grammar. A context-free language is a language generated by a context-free grammar. They are more general (and include) regular languages. The same context-free language might be generated by multiple context-free grammars.

How do you know if a language is context-sensitive?

Where α, β ∈ (N ∪ T)*, A ∈ N; γ ∈ (N ∪ T)+ and a rule of the form S → λ is allowed if the start symbol S do not appear on the right hand side of any rule. The language generated by such a grammar is called a context-sensitive language.


2 Answers

First, you should attempt to build a context-free grammar that forms the language in subject. A grammar is context-free if left-hand sides of all productions contain exactly one non-terminal symbol. By definition, if one exists, then the language is context-free.

An equivalent construct would be a pushdown automaton. It's the same as DFA, but with a stack available. It may be easier to build than a grammar.

However, if you fail to build a grammar or an automaton, it doesn't mean that a language is not context-free; perhaps, it's just you who can't build a grammar tricky enough (for example, I once spent about 7 hours to build a grammar for a tricky language).

If you start to doubt if the language is context-free, you should use a so-called "pumping lemma for context-free languages". It describes a property of all context-free languages, and if your language violates it, then it's definitely not context-free (see usage notes at Wikipedia).

This lemma is a corollary of Ogden's lemma. So Ogden's is more powerful, and if you failed to apply pumping lemma, you might try Ogden's (it's used the same way).

like image 79
P Shved Avatar answered Oct 08 '22 10:10

P Shved


Edit

As suggested in the comments to prove a language to be non-CFG, I believe is by using an ogdens' lemma. The inherent misinterpretation contained in my earlier answer is to be excused :) Retaining the earlier answer for lurkers.

Old answer

By looking at the grammar and rules used! As seen from the image (courtesy wikipedia chomsky hierarchy). Only regular languages are non-context-free. Implying anything which uses things of form A->aB or A->Ba alone are not context free.

alt text

Edit A->aB and A->Ba definitions are meant to express Left and Right recursive grammars and are not to be taken literally.

like image 27
questzen Avatar answered Oct 08 '22 11:10

questzen