A deterministic pushdown automaton (DPDA) is a -tuple , where , , , and are all finite sets, and
is the set of states,
is the input alphabet,
is the stack alphabet,
is the transition function,
is the start state, and
is the set of accept states.
For every , , and , exactly one of the values is not :
;
, an -stack move;
, an -input move;
, an -stack and -input move.
A language is called deterministic context-free if a DPDA recognizes it.
DPDAs are often described with two different acceptance modes: by final state and by empty stack. We assume acceptance by final state. Acceptance by empty stack is strictly less powerful, only recognizing prefix-free DCFLs.
Deterministic CFG
A deterministic context-free grammar (DCFG) is a CFG such that every valid string has a forced handle.
If we restrict our attention to prefix-free languages, they are equivalent to DPDAs in their descriptive power. By adding an endmarker to a language, we ensure the resulting language is prefix-free.
Dotted Rules
A dotted rule is a rule in a CFG augmented with a dot () between two of the symbols found on its RHS. For example, rule containing symbols has dotted rules:
DK-Test
Every CFG has a corresponding NFA and DFA, typically denoted and respectively, that can identify handles. That is, and accept input if and only if is the prefix of some valid string and ends with a handle of . is constructed from using the standard power set construction.
's states correspond to the dotted rules of . It has a special start state with an -move to for every rule involving start variable . Subsequent transitions are of one of two forms:
A shift-move appears for every terminal/variable and every rule :
An -move appears for all rules and :
The accept states are all corresponding to a completed rule. They have no outgoing transitions.
Generalizations of the -test can be used to determine if a grammar is an grammar or not. This is known as a -test with lookahead or just -test.
LR() grammars are equivalent to DPDAs in power. For every , an LR() grammar can be converted to a DPDA and hence is also equivalent to LR(). For this reason, If is omitted, it is assumed .
Closure Operations
Let and be deterministic context free languages over alphabet . Such languages are closed under the following:
Complementation:
Endmark:
In fact, is a DCFL if and only if is a DCFL.
Furthermore, the intersection of a DCFL with a regular language is deterministic context-free.