Formal Languages and Grammars

Description: This quiz is designed to assess your understanding of formal languages and grammars, which are fundamental concepts in computer science and linguistics.
Number of Questions: 15
Created by:
Tags: formal languages grammars syntax semantics chomsky hierarchy
Attempted 0/15 Correct 0 Score 0

What is a formal language?

  1. A set of strings that can be generated by a grammar

  2. A set of strings that can be recognized by a finite automaton

  3. A set of strings that can be parsed by a context-free grammar

  4. A set of strings that can be translated by a compiler


Correct Option: A
Explanation:

A formal language is a set of strings that can be generated by a grammar. A grammar is a set of rules that define how strings can be constructed from a set of symbols.

What is the Chomsky hierarchy?

  1. A classification of formal languages based on their generative power

  2. A classification of formal languages based on their recognition power

  3. A classification of formal languages based on their parsing power

  4. A classification of formal languages based on their translation power


Correct Option: A
Explanation:

The Chomsky hierarchy is a classification of formal languages based on their generative power. It consists of four levels: regular languages, context-free languages, context-sensitive languages, and unrestricted languages.

Which of the following is not a type of formal grammar?

  1. Regular grammar

  2. Context-free grammar

  3. Context-sensitive grammar

  4. Unrestricted grammar


Correct Option: D
Explanation:

Unrestricted grammars are not a type of formal grammar. The Chomsky hierarchy consists of four levels: regular languages, context-free languages, context-sensitive languages, and unrestricted languages. Unrestricted grammars are not included in the Chomsky hierarchy.

What is the difference between a regular grammar and a context-free grammar?

  1. Regular grammars can generate only finite languages, while context-free grammars can generate infinite languages.

  2. Regular grammars can generate only regular languages, while context-free grammars can generate context-free languages.

  3. Regular grammars can generate only context-free languages, while context-free grammars can generate context-sensitive languages.

  4. Regular grammars can generate only context-sensitive languages, while context-free grammars can generate unrestricted languages.


Correct Option: B
Explanation:

The main difference between regular grammars and context-free grammars is the type of languages they can generate. Regular grammars can generate only regular languages, while context-free grammars can generate context-free languages.

What is the pumping lemma for regular languages?

  1. For any regular language L, there exists a constant n such that every string in L of length at least n can be pumped.

  2. For any regular language L, there exists a constant n such that every string in L of length at least n can be pumped twice.

  3. For any regular language L, there exists a constant n such that every string in L of length at least n can be pumped three times.

  4. For any regular language L, there exists a constant n such that every string in L of length at least n can be pumped four times.


Correct Option: A
Explanation:

The pumping lemma for regular languages states that for any regular language L, there exists a constant n such that every string in L of length at least n can be pumped. Pumping means that a substring of the string can be repeated any number of times to produce a new string that is also in L.

What is the Chomsky-Schützenberger theorem?

  1. Every context-free language is a regular language.

  2. Every regular language is a context-free language.

  3. Every context-free language is a context-sensitive language.

  4. Every context-sensitive language is an unrestricted language.


Correct Option: A
Explanation:

The Chomsky-Schützenberger theorem states that every context-free language is a regular language. This means that any language that can be generated by a context-free grammar can also be generated by a regular grammar.

What is the difference between a context-sensitive grammar and an unrestricted grammar?

  1. Context-sensitive grammars can generate only context-sensitive languages, while unrestricted grammars can generate unrestricted languages.

  2. Context-sensitive grammars can generate only unrestricted languages, while unrestricted grammars can generate context-sensitive languages.

  3. Context-sensitive grammars can generate only context-free languages, while unrestricted grammars can generate context-sensitive languages.

  4. Context-sensitive grammars can generate only regular languages, while unrestricted grammars can generate context-free languages.


Correct Option: A
Explanation:

The main difference between context-sensitive grammars and unrestricted grammars is the type of languages they can generate. Context-sensitive grammars can generate only context-sensitive languages, while unrestricted grammars can generate unrestricted languages.

What is the Greibach normal form for context-free grammars?

  1. A context-free grammar in which every production rule is of the form A -> aB or A -> a

  2. A context-free grammar in which every production rule is of the form A -> BC or A -> a

  3. A context-free grammar in which every production rule is of the form A -> aBC or A -> a

  4. A context-free grammar in which every production rule is of the form A -> BC or A -> aB


Correct Option: A
Explanation:

The Greibach normal form for context-free grammars is a context-free grammar in which every production rule is of the form A -> aB or A -> a, where A and B are non-terminal symbols, a is a terminal symbol, and B does not contain A.

What is the Cocke-Younger-Kasami algorithm?

  1. An algorithm for parsing context-free grammars

  2. An algorithm for generating context-free grammars

  3. An algorithm for recognizing context-free grammars

  4. An algorithm for translating context-free grammars


Correct Option: A
Explanation:

The Cocke-Younger-Kasami algorithm is an algorithm for parsing context-free grammars. It is a bottom-up parsing algorithm that works by constructing a parse tree for the input string.

What is the Earley algorithm?

  1. An algorithm for parsing context-free grammars

  2. An algorithm for generating context-free grammars

  3. An algorithm for recognizing context-free grammars

  4. An algorithm for translating context-free grammars


Correct Option: A
Explanation:

The Earley algorithm is an algorithm for parsing context-free grammars. It is a bottom-up parsing algorithm that works by constructing a parse forest for the input string.

What is the difference between a deterministic context-free grammar and a non-deterministic context-free grammar?

  1. Deterministic context-free grammars can generate only deterministic languages, while non-deterministic context-free grammars can generate non-deterministic languages.

  2. Deterministic context-free grammars can generate only non-deterministic languages, while non-deterministic context-free grammars can generate deterministic languages.

  3. Deterministic context-free grammars can generate only context-free languages, while non-deterministic context-free grammars can generate context-sensitive languages.

  4. Deterministic context-free grammars can generate only context-sensitive languages, while non-deterministic context-free grammars can generate unrestricted languages.


Correct Option: A
Explanation:

The main difference between deterministic context-free grammars and non-deterministic context-free grammars is the type of languages they can generate. Deterministic context-free grammars can generate only deterministic languages, while non-deterministic context-free grammars can generate non-deterministic languages.

What is the CYK algorithm?

  1. An algorithm for parsing context-free grammars

  2. An algorithm for generating context-free grammars

  3. An algorithm for recognizing context-free grammars

  4. An algorithm for translating context-free grammars


Correct Option: C
Explanation:

The CYK algorithm is an algorithm for recognizing context-free grammars. It is a bottom-up parsing algorithm that works by constructing a parse table for the input string.

What is the difference between a regular expression and a context-free grammar?

  1. Regular expressions can generate only regular languages, while context-free grammars can generate context-free languages.

  2. Regular expressions can generate only context-free languages, while context-free grammars can generate regular languages.

  3. Regular expressions can generate only context-sensitive languages, while context-free grammars can generate unrestricted languages.

  4. Regular expressions can generate only unrestricted languages, while context-free grammars can generate context-sensitive languages.


Correct Option: A
Explanation:

The main difference between regular expressions and context-free grammars is the type of languages they can generate. Regular expressions can generate only regular languages, while context-free grammars can generate context-free languages.

What is the Myhill-Nerode theorem?

  1. A theorem that states that every regular language is a deterministic language.

  2. A theorem that states that every context-free language is a deterministic language.

  3. A theorem that states that every context-sensitive language is a deterministic language.

  4. A theorem that states that every unrestricted language is a deterministic language.


Correct Option: A
Explanation:

The Myhill-Nerode theorem states that every regular language is a deterministic language. This means that any language that can be generated by a regular grammar can also be generated by a deterministic finite automaton.

What is the Kleene star operation?

  1. An operation that concatenates two strings together.

  2. An operation that repeats a string any number of times.

  3. An operation that reverses a string.

  4. An operation that complements a string.


Correct Option: B
Explanation:

The Kleene star operation is an operation that repeats a string any number of times, including zero times. It is represented by the symbol *.

- Hide questions