What is a Context Free Grammar?

A context free grammar is a grammar which satisfies certain properties. In computer science, grammars describe languages; specifically, they describe formal languages. A formal language is just a set (mathematical term for a collection of objects) of strings (sequences of symbols… very similar to the programming usage of the word “string”). A simple example of … Read more

What is the language of this deterministic finite automata?

How to write regular expression for a DFA In any automata, the purpose of state is like memory element. A state stores some information in automate like ON-OFF fan switch. A Deterministic-Finite-Automata(DFA) called finite automata because finite amount of memory present in the form of states. For any Regular Language(RL) a DFA is always possible. … Read more

Regular vs Context Free Grammars

Regular grammar is either right or left linear, whereas context free grammar is basically any combination of terminals and non-terminals. Hence you can see that regular grammar is a subset of context-free grammar. So for a palindrome for instance, is of the form, S->ABA A->something B->something You can clearly see that palindromes cannot be expressed … Read more

Is C++ context-free or context-sensitive?

Below is my (current) favorite demonstration of why parsing C++ is (probably) Turing-complete, since it shows a program which is syntactically correct if and only if a given integer is prime. So I assert that C++ is neither context-free nor context-sensitive. If you allow arbitrary symbol sequences on both sides of any production, you produce … Read more