In
formal language theory
In logic, mathematics, computer science, and linguistics, a formal language is a set of string (computer science), strings whose symbols are taken from a set called "#Definition, alphabet".
The alphabet of a formal language consists of symbol ...
, deterministic context-free languages (DCFL) are a
proper subset
In mathematics, a set ''A'' is a subset of a set ''B'' if all elements of ''A'' are also elements of ''B''; ''B'' is then a superset of ''A''. It is possible for ''A'' and ''B'' to be equal; if they are unequal, then ''A'' is a proper subset ...
of
context-free language
In formal language theory, a context-free language (CFL), also called a Chomsky type-2 language, is a language generated by a context-free grammar (CFG).
Context-free languages have many applications in programming languages, in particular, mos ...
s. They are context-free languages that can be accepted by a
deterministic pushdown automaton. DCFLs are always unambiguous, meaning that they admit an
unambiguous grammar
In computer science, an ambiguous grammar is a context-free grammar for which there exists a string that can have more than one leftmost derivation or parse tree. Every non-empty context-free language admits an ambiguous grammar by introducing e.g ...
. There are non-deterministic unambiguous CFLs, so DCFLs form a proper subset of unambiguous CFLs.
DCFLs are of great practical interest, as they can be parsed in
linear time
In theoretical computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations ...
, and various restricted forms of DCFGs admit simple practical parsers. They are thus widely used throughout computer science.
Description
The notion of the DCFL is closely related to the
deterministic pushdown automaton (DPDA). It is where the language power of
pushdown automata
In the theory of computation, a branch of theoretical computer science, a pushdown automaton (PDA) is
a type of automaton that employs a stack.
Pushdown automata are used in theories about what can be computed by machines. They are more capab ...
is reduced to if we make them deterministic; the pushdown automata become unable to choose between different state-transition alternatives and as a consequence cannot recognize all context-free languages.
Unambiguous grammar
In computer science, an ambiguous grammar is a context-free grammar for which there exists a string that can have more than one leftmost derivation or parse tree. Every non-empty context-free language admits an ambiguous grammar by introducing e.g ...
s do not always generate a DCFL. For example, the language of even-length
palindrome
A palindrome (Help:IPA/English, /ˈpæl.ɪn.droʊm/) is a word, palindromic number, number, phrase, or other sequence of symbols that reads the same backwards as forwards, such as ''madam'' or ''racecar'', the date "Twosday, 02/02/2020" and th ...
s on the alphabet of 0 and 1 has the unambiguous context-free grammar S → 0S0 , 1S1 , ε. An arbitrary string of this language cannot be parsed without reading all its letters first, which means that a pushdown automaton has to try alternative state transitions to accommodate for the different possible lengths of a semi-parsed string.
Properties
Deterministic context-free languages can be recognized by a
deterministic Turing machine
A Turing machine is a mathematical model of computation describing an abstract machine that manipulates symbols on a strip of tape according to a table of rules. Despite the model's simplicity, it is capable of implementing any computer algor ...
in polynomial time and
O(log
2 ''n'') space; as a corollary, DCFL is a subset of the complexity class
SC.
The set of deterministic context-free languages is closed under the following operations:
*
complement
*
inverse homomorphism
*
right quotient with a regular language
*pre: pre(
) is the subset of all strings having a proper prefix that also belongs to
.
*min: min(
) is the subset of all strings that do not have a proper prefix in
.
*max: max(
) is the subset of all strings that are not the prefix of a longer string in
.
The set of deterministic context-free language is ''not'' closed under the following operations:
*
union
*
intersection
In mathematics, the intersection of two or more objects is another object consisting of everything that is contained in all of the objects simultaneously. For example, in Euclidean geometry, when two lines in a plane are not parallel, their ...
*
concatenation
In formal language theory and computer programming, string concatenation is the operation of joining character strings end-to-end. For example, the concatenation of "snow" and "ball" is "snowball". In certain formalizations of concatenati ...
*
Kleene star
In mathematical logic and theoretical computer science, the Kleene star (or Kleene operator or Kleene closure) is a unary operation on a Set (mathematics), set to generate a set of all finite-length strings that are composed of zero or more repe ...
*
ε-free morphism
*
Mirror image
A mirror image (in a plane mirror) is a reflection (physics), reflected duplication of an object that appears almost identical, but is reversed in the direction perpendicular to the mirror surface. As an optical phenomenon, optical effect, it r ...
Importance
The languages of this class have great practical importance in computer science as they can be parsed much more efficiently than nondeterministic context-free languages. The complexity of the program and execution time of a deterministic pushdown automaton is vastly less than that of a nondeterministic one. In the naive implementation, the latter must make copies of the stack every time a nondeterministic step occurs. The best known algorithm to test membership in any context-free language is
Valiant's algorithm, taking O(
2.378) time, where is the length of the string. On the other hand, deterministic context-free languages can be accepted in O() time by an
LR() parser.
This is very important for
computer language
A computer language is a formal language used to communicate with a computer. Types of computer languages include:
* Software construction#Construction languages, Construction language – all forms of communication by which a human can Comput ...
translation because many computer languages belong to this class of languages.
See also
*
Context free language
*
Deterministic pushdown automaton
*
Deterministic context-free grammar In formal grammar theory, the deterministic context-free grammars (DCFGs) are a proper subset of the context-free grammars. They are the subset of context-free grammars that can be derived from deterministic pushdown automata, and they generate the ...
*
Simple deterministic language
References
{{Formal languages and grammars
Formal languages