Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Context-sensitive grammar
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Examples == === ''a<sup>n</sup>b<sup>n</sup>c<sup>n</sup>'' === The following context-sensitive grammar, with start symbol ''S'', generates the canonical non-[[context-free language]] { ''a<sup>n</sup>b<sup>n</sup>c<sup>n</sup>'' | ''n'' β₯ 1 } :{{cn|date=January 2022}} {| |- | 1. || || ''S'' || β || ''a'' || ''B'' || ''C'' |- | 2. || || ''S'' || β || ''a'' || ''S'' || ''B'' || ''C'' |- | 3. || ''C'' || ''B'' || β || ''C'' || ''Z'' |- | 4. || ''C'' || ''Z'' || β || ''W'' || ''Z'' |- | 5. || ''W'' || ''Z'' || β || ''W'' || ''C'' |- | 6. || ''W'' || ''C'' || β || ''B'' || ''C'' |- | 7. || ''a'' || ''B'' || β || ''a'' || ''b'' |- | 8. || ''b'' || ''B'' || β || ''b'' || ''b'' | |- | 9. || ''b'' || ''C'' || β || ''b'' || ''c'' |- |10. || ''c'' || ''C'' || β || ''c'' || ''c'' |} <!--- # ''S'' β ''aSBC'' # ''S'' β ''aBC'' # ''CB'' β ''HB'' # ''HB'' β ''HC'' # ''HC'' β ''BC'' # ''aB'' β ''ab'' # ''bB'' β ''bb'' # ''bC'' β ''bc'' # ''cC'' β ''cc'' ---> Rules 1 and 2 allow for blowing-up ''S'' to ''a''<sup>''n''</sup>''BC''(''BC'')<sup>''n''β1</sup>; rules 3 to 6 allow for successively exchanging each ''CB'' to ''BC'' ([[Revesz' trick|four rules]] are needed for that since a rule ''CB'' β ''BC'' wouldn't fit into the scheme Ξ±''A''Ξ² β Ξ±Ξ³Ξ²); rules 7β10 allow replacing a non-terminal ''B'' or ''C'' with its corresponding terminal ''b'' or ''c'', respectively, provided it is in the right place. A generation chain for ''{{not a typo|aaabbbccc}}'' is: : ''S'' : β<sub>2</sub> {{not a typo|'''aSBC'''}} : β<sub>2</sub> {{not a typo|''a'''aSBC'''BC''}} : β<sub>1</sub> {{not a typo|''aa'''aBC'''BCBC''}} : β<sub>3</sub> {{not a typo|''aaaB'''CZ'''CBC''}} : β<sub>4</sub> {{not a typo|''aaaB'''WZ'''CBC''}} : β<sub>5</sub> {{not a typo|''aaaB'''WC'''CBC''}} : β<sub>6</sub> {{not a typo|''aaaB'''BC'''CBC''}} : β<sub>3</sub> {{not a typo|''aaaBBC'''CZ'''C''}} : β<sub>4</sub> {{not a typo|''aaaBBC'''WZ'''C''}} : β<sub>5</sub> {{not a typo|''aaaBBC'''WC'''C''}} : β<sub>6</sub> {{not a typo|''aaaBBC'''BC'''C''}} : β<sub>3</sub> {{not a typo|''aaaBB'''CZ'''CC''}} : β<sub>4</sub> {{not a typo|''aaaBB'''WZ'''CC''}} : β<sub>5</sub> {{not a typo|''aaaBB'''WC'''CC''}} : β<sub>6</sub> {{not a typo|''aaaBB'''BC'''CC''}} : β<sub>7</sub> {{not a typo|''aa'''ab'''BBCCC''}} : β<sub>8</sub> {{not a typo|''aaa'''bb'''BCCC''}} : β<sub>8</sub> {{not a typo|''aaab'''bb'''CCC''}} : β<sub>9</sub> {{not a typo|''aaabb'''bc'''CC''}} : β<sub>10</sub> {{not a typo|''aaabbb'''cc'''C''}} : β<sub>10</sub> {{not a typo|''aaabbbc'''cc'''''}} : === ''a<sup>n</sup>b<sup>n</sup>c<sup>n</sup>d<sup>n</sup>'', etc. === More complicated grammars can be used to parse { ''a<sup>n</sup>b<sup>n</sup>c<sup>n</sup>d<sup>n</sup>'' | ''n'' β₯ 1 }, and other languages with even more letters. Here we show a simpler approach using non-contracting grammars:{{cn|date=January 2022}} Start with a kernel of regular productions generating the sentential forms <math>(ABCD)^{n}abcd</math> and then include the non contracting productions <math>p_{Da} : Da\rightarrow aD</math>, <math>p_{Db} : Db\rightarrow bD</math>, <math>p_{Dc} : Dc\rightarrow cD</math>, <math>p_{Dd} : Dd\rightarrow dd</math>, <math>p_{Ca} : Ca\rightarrow aC</math>, <math>p_{Cb} : Cb\rightarrow bC</math>, <math>p_{Cc} : Cc\rightarrow cc</math>, <math>p_{Ba} : Ba\rightarrow aB</math>, <math>p_{Bb} : Bb\rightarrow bb</math>, <math>p_{Aa} : Aa\rightarrow aa</math>. === ''a<sup>m</sup>b<sup>n</sup>c<sup>m</sup>d<sup>n</sup>'' === A non contracting grammar (for which there is an equivalent CSG) for the language <math>L_{Cross} = \{ a^mb^nc^{m}d^{n} \mid m \ge 1, n \ge 1 \}</math> is defined by :<math>p_0 : S \rightarrow RT</math>, :<math>p_1 : R\rightarrow aRC | aC</math>, :<math>p_3 : T\rightarrow BTd | Bd</math>, :<math>p_5 : CB\rightarrow BC</math>, :<math>p_6 : aB\rightarrow ab</math>, :<math>p_7 : bB\rightarrow bb</math>, :<math>p_8 : Cd\rightarrow cd</math>, and :<math>p_9 : Cc\rightarrow cc</math>. With these definitions, a derivation for <math>a^3b^2c^3d^2</math> is: <math>S \Rightarrow_{p_0} RT \Rightarrow_{p^{2}_{1}p_{2}} a^3C^3T \Rightarrow_{p_{3}p_{4} } a^3C^3B^2d^2 \Rightarrow_{p^{6}_{5} } a^3B^2C^3d^2 \Rightarrow_{p_{6}p_{7} } a^3b^2C^3d^2 \Rightarrow_{p_{8}p^{2}_{9}} a^3b^2c^3d^2 </math>.{{citation needed|date=November 2018}} === ''a''<sup>2<sup>''i''</sup></sup> === A noncontracting grammar for the language { ''a''<sup>2<sup>''i''</sup></sup> | ''i'' β₯ 1 } is constructed in Example 9.5 (p. 224) of (Hopcroft, Ullman, 1979):<ref>They obtained the grammar by systematic transformation of an [[unrestricted grammar]], given in Exm. 9.4, viz.: # <math>S\rightarrow ACaB</math>, # <math>Ca\rightarrow aaC</math>, # <math>CB\rightarrow DB</math>, # <math>CB\rightarrow E</math>, # <math>aD\rightarrow Da</math>, # <math>AD\rightarrow AC</math>, # <math>aE\rightarrow Ea</math>, # <math>AE\rightarrow \varepsilon</math>. In the context-sensitive grammar, a string enclosed in square brackets, like <math>[ACaB]</math>, is considered a single symbol (similar to e.g. <code><name-part></code> in [[BackusβNaur form#Example|BackusβNaur form]]). The symbol names are chosen to resemble the unrestricted grammar. Likewise, rule groups in the context-sensitive grammar are numbered by the unrestricted-grammar rule they originated from.</ref> # <math>S\rightarrow [ACaB]</math> # <math>\begin{cases} \ [Ca]a\rightarrow aa[Ca] \\ \ [Ca][aB]\rightarrow aa[CaB] \\ \ [ACa]a\rightarrow [Aa]a[Ca] \\ \ [ACa][aB]\rightarrow [Aa]a[CaB] \\ \ [ACaB]\rightarrow [Aa][aCB] \\ \ [CaB]\rightarrow a[aCB] \end{cases}</math> # <math>[aCB]\rightarrow [aDB]</math> # <math>[aCB]\rightarrow [aE]</math> # <math>\begin{cases} \ a[Da]\rightarrow [Da]a \\ \ [aDB]\rightarrow [DaB] \\ \ [Aa][Da]\rightarrow [ADa]a \\ \ a[DaB]\rightarrow [Da][aB] \\ \ [Aa][DaB]\rightarrow [ADa][aB] \end{cases}</math> # <math>[ADa]\rightarrow [ACa]</math> # <math>\begin{cases} \ a[Ea]\rightarrow [Ea]a \\ \ [aE]\rightarrow [Ea] \\ \ [Aa][Ea]\rightarrow [AEa]a \end{cases}</math> # <math>[AEa]\rightarrow a</math>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)