7

For a formal language $L \subseteq \Sigma^{*}$ I define the set Pref(L) to be:

$\text{pref}(L) = \{\alpha \in \Sigma^{*} : \exists \beta \in \Sigma^{*} \text{ such that } \alpha \beta \in L\}$

ie. the set of all (not necessarily proper) prefixes of words in $L$. I know that if $L$ is context-free then pref(L) is context-free but if $L$ is deterministic context-free then is pref(L) deterministic context-free?

I am sure this is known but I cannot find the answer anywhere and it's not in Hopcroft and Ullman.

Ran G.
  • 20,884
  • 3
  • 61
  • 117
Sam Jones
  • 1,151
  • 7
  • 17

3 Answers3

9

DCFL are known to be closed under quotient with regular languages, but the quotient of $L$ with $\Sigma^{*}$ is precisely $\text{pref}(L)$ so yes, if $L$ is a DCFL then $\text{pref}(L)$ is a DCFL.

Raphael
  • 73,212
  • 30
  • 182
  • 400
Sam Jones
  • 1,151
  • 7
  • 17
1

DCFLs have LR(0) grammars, and LR parsers have the property that they report the error on the first symbol that can't be legally there. So the strategy would be simply to run the LR parser and accept whatever doesn't give an error before ending the string. (Way overkill, there must be a "simpler" way to prove it, but this convinces me that the result is in fact true. Building a DPDA for the prefixes isn't so easy, a DPDA could just fall into some kind of loop eating up the string without any chance of accepting at the end; to prove it directly by that route you'd have to make sure somehow that if there are legal moves from the current state, there is a path that leads to ultimate acceptance with some remainder, and that looks messy.)

vonbrand
  • 14,204
  • 3
  • 42
  • 52
-1

According the concept of context free language very context can be represented in the form of "CHOMSKY NORMAL FORM".so if in the rule we made change like if A->BC change it to the A->BC/B now this type of replacement will generate the context free language of prefix language of the given