乔姆斯基层次结构:LR(k)文法与确定性CFG的差异及相关疑问
Hey there! Let's unpack your questions about the Chomsky hierarchy, LR(k) grammars, and Turing machine variants—since it sounds like your intro CS class touched on these but left some key gaps.
First, let's recap the Chomsky hierarchy you learned in class, formatted clearly:
recursively enumerable - all Turing machines recursive - deciders/TMs that halt on every input context sensitive - Linear-bounded non-deterministic Turing machine context free - nondeterministic PDA deterministic context free - deterministic PDA LR(k) grammar - deterministic PDA regular - DFAs/NFAs
LR(k) Grammars vs. Deterministic Context-Free Grammars
You're spot-on that LR(k) grammars are a subset of deterministic CFgs (DCFGs). Here's the concrete breakdown of their differences:
- All LR(k) grammars are DCFGs, but not the other way around: Every LR(k) grammar generates a deterministic context-free language (DCFL), meaning it can be recognized by a deterministic PDA. However, there are DCFGs that aren't LR(k) for any k. This happens when a DCFG has structural conflicts (like shift-reduce or reduce-reduce conflicts) that can't be resolved even by looking ahead k symbols. That said, every DCFL can be represented by some LR(k) grammar—you just might need to rewrite the original grammar to eliminate those conflicts.
- LR(k) is focused on parseability: The "LR" stands for Left-to-right input scan, Rightmost derivation (reverse), and "(k)" refers to looking ahead k input symbols to decide parsing actions (shift or reduce). LR(k) grammars are specifically built to work with efficient, automated deterministic parsers (the kind used in compilers for languages like C or Java). So while all DCFGs are unambiguous and map to DPDAs, LR(k) grammars are the subset that enables straightforward, guesswork-free deterministic parsing.
Linear-Bounded Non-Deterministic Turing Machines (LBNTMs) vs. Deciders
Let's start with clear definitions, then dive into their differences:
- Deciders: These are Turing machines that always halt, no matter the input. For any input, they'll eventually either accept it (if it's part of the language) or reject it (if it's not)—no infinite loops allowed. Deciders recognize the class of recursive languages.
- LBNTMs: These are non-deterministic Turing machines with a strict space limit: they can only use a linear amount of tape relative to the input length (e.g., if the input is n symbols long, the machine can use at most c*n tape cells, where c is a fixed constant). They recognize context-sensitive languages (CSLs).
Key differences between the two:
- Space constraints: Deciders have no inherent space limit—they can use as much tape as needed for computation. LBNTMs are locked to linear space relative to the input.
- Determinism: Deciders are typically deterministic (though non-deterministic deciders exist, the term usually refers to deterministic ones). LBNTMs are explicitly non-deterministic (thanks to the Immerman-Szelepcsényi theorem, we know non-deterministic linear space equals deterministic linear space, so CSLs can also be recognized by deterministic linear-bounded Turing machines, which are deciders too).
- Language scope: Recursive languages (recognized by deciders) include context-sensitive languages (recognized by LBNTMs) as a proper subset. In other words, every CSL is recursive, but there are recursive languages that aren't context-sensitive.
- Halt behavior: By definition, deciders must halt. For LBNTMs, since their space is bounded, even non-deterministic paths can't loop forever (there's a finite number of possible states and tape configurations), so all paths will eventually halt.
内容的提问来源于stack exchange,提问作者maddie
相关产品推荐
相关产品推荐

