- Theoretical Computer Science
- Theoretical Computer Science - Quizzes
- Formal Languages and Grammars
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: Aliensbrain Bot | |
Tags: formal languages grammars syntax semantics chomsky hierarchy |
What is a formal language?
-
A set of strings that can be generated by a grammar
-
A set of strings that can be recognized by a finite automaton
-
A set of strings that can be parsed by a context-free grammar
-
A set of strings that can be translated by a compiler
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?
-
A classification of formal languages based on their generative power
-
A classification of formal languages based on their recognition power
-
A classification of formal languages based on their parsing power
-
A classification of formal languages based on their translation power
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?
-
Regular grammar
-
Context-free grammar
-
Context-sensitive grammar
-
Unrestricted grammar
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?
-
Regular grammars can generate only finite languages, while context-free grammars can generate infinite languages.
-
Regular grammars can generate only regular languages, while context-free grammars can generate context-free languages.
-
Regular grammars can generate only context-free languages, while context-free grammars can generate context-sensitive languages.
-
Regular grammars can generate only context-sensitive languages, while context-free grammars can generate unrestricted languages.
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?
-
For any regular language L, there exists a constant n such that every string in L of length at least n can be pumped.
-
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.
-
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.
-
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.
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?
-
Every context-free language is a regular language.
-
Every regular language is a context-free language.
-
Every context-free language is a context-sensitive language.
-
Every context-sensitive language is an unrestricted language.
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?
-
Context-sensitive grammars can generate only context-sensitive languages, while unrestricted grammars can generate unrestricted languages.
-
Context-sensitive grammars can generate only unrestricted languages, while unrestricted grammars can generate context-sensitive languages.
-
Context-sensitive grammars can generate only context-free languages, while unrestricted grammars can generate context-sensitive languages.
-
Context-sensitive grammars can generate only regular languages, while unrestricted grammars can generate context-free languages.
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?
-
A context-free grammar in which every production rule is of the form A -> aB or A -> a
-
A context-free grammar in which every production rule is of the form A -> BC or A -> a
-
A context-free grammar in which every production rule is of the form A -> aBC or A -> a
-
A context-free grammar in which every production rule is of the form A -> BC or A -> aB
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?
-
An algorithm for parsing context-free grammars
-
An algorithm for generating context-free grammars
-
An algorithm for recognizing context-free grammars
-
An algorithm for translating context-free grammars
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?
-
An algorithm for parsing context-free grammars
-
An algorithm for generating context-free grammars
-
An algorithm for recognizing context-free grammars
-
An algorithm for translating context-free grammars
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?
-
Deterministic context-free grammars can generate only deterministic languages, while non-deterministic context-free grammars can generate non-deterministic languages.
-
Deterministic context-free grammars can generate only non-deterministic languages, while non-deterministic context-free grammars can generate deterministic languages.
-
Deterministic context-free grammars can generate only context-free languages, while non-deterministic context-free grammars can generate context-sensitive languages.
-
Deterministic context-free grammars can generate only context-sensitive languages, while non-deterministic context-free grammars can generate unrestricted languages.
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?
-
An algorithm for parsing context-free grammars
-
An algorithm for generating context-free grammars
-
An algorithm for recognizing context-free grammars
-
An algorithm for translating context-free grammars
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?
-
Regular expressions can generate only regular languages, while context-free grammars can generate context-free languages.
-
Regular expressions can generate only context-free languages, while context-free grammars can generate regular languages.
-
Regular expressions can generate only context-sensitive languages, while context-free grammars can generate unrestricted languages.
-
Regular expressions can generate only unrestricted languages, while context-free grammars can generate context-sensitive languages.
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?
-
A theorem that states that every regular language is a deterministic language.
-
A theorem that states that every context-free language is a deterministic language.
-
A theorem that states that every context-sensitive language is a deterministic language.
-
A theorem that states that every unrestricted language is a deterministic language.
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?
-
An operation that concatenates two strings together.
-
An operation that repeats a string any number of times.
-
An operation that reverses a string.
-
An operation that complements a string.
The Kleene star operation is an operation that repeats a string any number of times, including zero times. It is represented by the symbol *.