Sprachklasse | Grammatik | Maschine | Wortproblem | Abgeschlossenheit | |||||
---|---|---|---|---|---|---|---|---|---|
L_1 \cap L_2 | L_1 \cup L_2 | L_1 \cdot L_2 | L^* | L^R | L^c | ||||
regulär | Chomsky-Typ 3 | endlicher Automat | linear | ja | ja | ja | ja | ja | ja |
kontextfrei | Chomsky-Typ 2 | Kellerautomat | polynomiell | nein | ja | ja | ja | ja | nein |
kontextsensitiv | Chomsky-Typ 1 | linear beschränkte Turingmaschine | PSPACE-vollständig | ja | ja | ja | ja | ja | ja |
entscheidbar | (kein Analogon) | Entscheider (Turingmaschine, die auf jeder Eingabe hält) | entscheidbar | ja | ja | ja | ja | ja | ja |
semi-entscheidbar | Chomsky-Typ 0 | Akzeptor (Turingmaschine, die nicht notwendigerweise hält, wenn sie nicht akzeptiert) | semi-entscheidbar | ja | ja | ja | ja | ja | nein |
Sei G =( T, V, S, P) eine kontextfreie Grammatik. Eine Variable A \in V heißt nutzlos, wenn es für kein w \in T^* eine Ableitungsfolge S \to^* \alpha A \beta \to^* w gibt, in der A vorkommt.
Es gilt L(G) = \emptyset genau dann wenn S nutzlos ist.
ROUTINE EliminateUselessVariables1 INPUT G = (T, V, S, P) ;; kontextfreie Grammatik OUTPUT V_1 ;; sodass V_1 = \{ A \in V: \exists w \in T^*: A \to^* w \} P_1 BEGIN P_1 \gets P V_1 \gets \{ A \in V: \exists w \in T^*: (A, w) \in P_1 \} Q \gets V_1 WHILE Q \neq \emptyset DO FOREACH A \in Q DO Q \gets Q \setminus \{ A \} FOREACH (B, \alpha_1 A \alpha_2) \in P_1 DO \tilde{P} \gets \{ (B, \alpha_1 w \alpha_2): \exists w \in T^*: (A, w)\in P_1 \} P_1 \gets P_1 \cup \tilde{P} \setminus \{ (B, \alpha_1 A \alpha_2) \} IF \tilde{P} \neq \emptyset AND \alpha_1, \alpha_2 \in T^* AND B \not\in V_1 THEN V_1 \gets V_1 \cup \{ B \} Q \gets Q \cup \{ B \} FI DONE DONE DONE END
ROUTINE EliminateUselessVariables2 INPUT G_1 = (T, V_1, S, P_1) ;; kontextfreie Grammatik mit einigermaßen nützlichen Variablen V_1 OUTPUT V_2 ;; sodass V_2 = \{ A \in V_1: \exists \alpha_1, \alpha_2 \in (V_1 \cup T)^*: S \to^* \alpha_1 A \alpha_2 \} BEGIN V_2 \gets \{ S \} DO change \gets 0 FOREACH A \in V_2 DO FOREACH (A, \alpha_1 B \alpha_2) \in P_1 DO IF B \not\in V_2 THEN V_2 \gets V_2 \cup \{ B \} change \gets change + 1 FI DONE DONE WHILE change > 0 DONE END
ROUTINE EliminateUselessVariables INPUT G = (T, V, S, P) ;; kontextfreie Grammatik OUTPUT G' = (T, V', S, P') ;; kontextfreie Grammatik ohne nutzlose Variablen außer S BEGIN CALL EliminateUselessVariables1(G, V_1, P_1); IF S \not\in V_1 THEN V' \gets \{ S \} P' \gets \emptyset ELSE G_1 \gets (T, V_1, S, P_1) CALL EliminateUselessVariables2(G_1, V_2); V' \gets V_2 P' \gets \{ (A, \alpha) \in P: A \in V_2 \land \alpha \neq A \} FI G' \gets (T, V', S, P') END
Sei G = (T, V, S, P) eine kontextfreie Grammatik. G ist in Greibach-Normalform (GNF) genau dann wenn für alle (\alpha, \beta) \in P gilt, dass
Außerdem ist „manchmal“ der Spezialfall \alpha = S und \beta = \epsilon erlaubt, wenn S nie auf der rechten Seite einer Produktion steht.
Für jede kontextfreie Grammatik G_1 = (T, V_1, S_1, P_1) mit \epsilon \not\in L(G_1) existiert eine kontextfreie Grammatik G_2 = (T, V_2, S_2, P_2) in Greibach-Normalform, sodass L(G_1) = L(G_2).
Um eine kontextfreie Grammatik ohne nutzlose Variablen in eine äquivalente Grammatik in Greibach-Normalform zu überführen, wechseln sich folgende Schritte ab, bis sich die Grammatik nicht mehr verändert:
Wenn auf der rechten Seite einer Produktion ein Terminal a vorkommt, das nicht das erste Zeichen ist, ersetze es durch ein neues Nichtterminal X_a und füge die Produktion X_a \to a hinzu.
Streiche Produktionen A \to B \gamma, deren rechte Seite mit einem Nichtterminal B \neq A beginnt, und nimm dafür A \to \beta_1 \gamma | … | \beta_n \gamma für alle Produktionen B \to \beta_1 | … | \beta_n hinzu.
Streiche für jedes Nichtterminal A alle Produktionen A \to A \gamma_1 | … | A \gamma_n zugunsten von A \to \alpha_1 Y_\gamma | … | \alpha_m Y_\gamma für alle Produktionen A \to \alpha_1 | … | \alpha_m wo die \alpha_j nicht mit A beginnen, und einem neuen Nichtterminal Y_\gamma. Nimm schließlich Y_\gamma \to \gamma_1 | … | \gamma_n und Y_\gamma \to \gamma_1 Y_\gamma | … | \gamma_n Y_\gamma hinzu.