A Representation of Context-Free Grammars with the Help of Finite Digraphs Krasimir Yordzhev

A Representation of Context-Free Grammars with the Help of Finite Digraphs Krasimir Yordzhev

A representation of context-free grammars with the help of finite digraphs Krasimir Yordzhev Faculty of Mathematics and Natural Sciences, South-West University, Blagoevgrad, Bulgaria Email address: [email protected] Abstract: For any context-free grammar, we build a transition diagram, that is, a finite directed graph with labeled arcs, which describes the work of the grammar. This approach is new, and it is different from previously known graph models. We define the concept of proper walk in this transition diagram and we prove that a word belongs to a given context-free language if and only if this word can be obtained with the help of a proper walk. Keywords: Context-free grammar, Finite digraph, Transition diagram, Proper walk, Chomsky normal form where N and Σ are finite sets, N Σ = , which 1. Introduction are called, respectively, alphabet of nonterminals (or Context-free grammars are widely used to describe variables) and alphabet of terminals∩, where∅ Π is a the syntax of programming languages and natural finite subset of the Cartesian product (N Σ) × languages [1,2]. On the other hand, graph theory is a (N Σ) , and we will write u v if (u, v) ∗ Π good apparatus for the modeling of computing de- (see [3]).∗ We will call Π the set of productions∪ or vices and computational processes. So a lot of graph rules.∪ → ∈ algorithms have been developed [4,5]. The purpose Let Γ = (N, Σ, Π) be a formal grammar and let of this article is to show how for an arbitrary con- w, y (N Σ) . We will write w y, if there are text-free grammar, we can construct a finite digraph, z , z , u, v (N∗ Σ) , such that w = z uz , which describes the work of the grammar. As is well y = z∈ vz ∪and u ∗v is a production→ of Π. We will known, any finite state machine (deterministic or 1 2 1 2 write w ∈y, if∪ w = y, or there are w , w , … , w nondeterministic finite automaton) and any push- 1 2 such that w =→w and w w for all down automaton can be described by a transition 0 1 r i = 0,1, …⇒, r 1 . The sequence w w diagram, which is essentially a finite directed graph 0 i i+1 w is called a derivation of length →r. with labeled arcs [2]. The finite digraph, which we 0 1 For every −A N, a subset L(Γ, A)→ Σ →defined⋯ → will construct in this work and who will simulate a r given context-free grammar will be different from by ∗ previously known graph models [1,2]. ∈ ⊆ L( , A) = { | A } ∗ 2. The Main Definitions and Notations is called the languageΓ generatedα ∈ Σ by⇒ theα grammar Γ If with the start symbol A (see [3]). The formal grammar Γ = {N, Σ, Π} is called con- Σ = {x , x , … , x } text-free if all the productions of Π are of the form A , where A N, (N Σ) . The language 1 2 p is a finite set, then with Σ we will denote the free L is called context-free if there is∗ a context-free → ω ∈ ω ∈ ∪ monoid over Σ , ie the∗ set of all sequences grammar Γ = (N, Σ, Π) and a nonterminal A N, x x … x , including the empty one which we de- such that L = L(Γ, A). ∈ note with ε. Elements of Σ is called words, and Transition diagram is called a finite directed graph, i1 i2 in all of whose arcs are labelled by an element of a any subset of Σ (formal) language∗ . semigroup (see also [2]). Formal (or generative∗ ) grammar Γ is a triple If is a walk in a transition diagram, then the Γ = (N, Σ, Π), label of this walk l( ) is the product of the labels of π π 2 K. Yordzhev. A Representation of Context-free Grammars with the Help of Finite Digraphs the arcs that make up this walk, taken in passing the arcs. Let Γ = (N, Σ, Π) be a context-free grammar and let Figure 1. Production , , and the corresponding part of the transition diagram∗ ( ). = { | A N} = { | x }. 퐴 → 훼 퐴 ∈ 푁 훼 ∈ 훴 퐻 훤 We considerN′ A′the monoid∈ ΣT′ withx′ the∈ setΣ of gener- If the production is of the form ators , and with the defining rela- A B B … B , where Σ tions ( i = 0,1, … k ), A, B N ( j = 1,2, … , k ), then the∗ 0 1 1 2 2 k−1 k k i 푁 ∪ Σ ∪ 푁′ ∪ Σ′ corresponding→ α α partα ofα the transitionα diagram isα shown∈ j = , = , (1) in Figure 2 ∈ where , 퐴′퐴 , 휀 푥′푥 , 휀 and is the empty word (the identity of the monoid ). We set by definition퐴′ ∈ 푁′ 퐴( ∈)푁= 푥′ ,∈ Σ(′ 푥) ∈=Σ , if휀 = … , then will mean 푇… and = . 푥′ ′ 푥 퐴′ ′ ′ 퐴′ ′ 휔 푧1푧Let2 푧푘 ∈ 푇 휔′ 푧푘푧푘−1 푧1 휀′ 휀 = × = {( , ) | , }. ∗ ∗ In 푅 we Σintroduce푇 the휔 operation푧 휔 ∈ Σ'' ''푧 as∈ follows:푇 If ( , ), ( , ) , then 푅 ∘ 휔1( 푧1, 휔) 2 (푧2 ,∈ 푅) = ( , ). (2) It 휔is1 easy푧1 ∘ to휔 2see푧2 that 휔 1with휔2 푧 2this푧1 operation is a monoid with identity ( , ). 푅 Figure 2. Production … and 휀 휀 the corresponding part of the transition diagram ( ). 3. Finite Digraphs and Context-free 퐴 → 훼0퐵1훼1퐵2훼2 훼푘−1퐵푘훼푘 Grammars 퐻 훤 Definition 1. For the context-free grammar , we Definition 2. A walk H( ) will be called a construct a transition diagram H( ) with the set of proper walk if: V = {u , v | A N} Γ π ∈ Γ vertices and the set of arcs 1. For each A N the arcs from u to v (if E V × V which is made as follows:Γ A A there exist) are proper walks; ∈ A A 1. For each production A , where A N , ∈ ⊆ 2. Let , , … , be proper walks, A N and Σ there is an arc from u to v with a ( , ) let: bel ∗ (see Fig. 1); → α ∈ π1 π2 πk ∈ α ∈ A A • there is an arc from the vertex u to the 2. For each production A Bz, where A, B N, start vertex of ; α ε A Σ , z (N Σ) there is an arc from u to u • for every i = 1ρ,2, … , k 1 there are arcs ( , z) 1 with a∗ label ; ∗ → α ∈ from the finalπ vertex of to the start vertex of α ∈ ∈ ∪ A B 3. For each production A z B B z where ; − α i i A, B , B N, Σ , z , z (N Σ) , there is an σ • there is an arc fromπ the final vertex of 1 ′1 2 2 i+1 arc from v to u ∗ with a label→( , B ∗α′); π to the vertex v . 1 2 1 2 ∈ α ∈ ∈ ∪ If l( … τ ) = ( , ) for some 4. For eachB1 productionB2 A zB , where2 A, B N, k A z (N ) α α v v π , then the walk Σ , Σ there is an arc from to 1 1 2 2 k−1 k with a∗ label( , ′); ∗ → α ∈ ∗ ρπ σ π σ σ π τ α ε α ∈ ∈ ∪ B A α ∈ Σ = … 5. There are no other arcs in H(Γ) except de- α α scribed in 1 ÷ 4. 1 1 2 2 푘−1 푘 is the proper 휋walk휌 (see휋 휎 Figure휋 휎 3).휎 휋 휏 K. Yordzhev. A Representation of Context-free Grammars with the Help of Finite Digraphs 3 3. There are no other proper walks in ( ) ex- with a label ( , B ). cept described in 1 and 2. c) According to ′1, item′ 1 there is an arc from v 퐻 Γ i i+1 i to v with a labelα ( α, ). Bk We consider the walk ′ = …τ A k H( ). For this walk, αwe αhave:k π ρπ1σ1π2 σk−1πkτ ∈ l( Γ) = =π( , B … B ) ( , ) ( , B ) ( , ) ( , B ′ ′)( , ) 0 1 2 2 k k 1 1 2 1 α α α α ∘ β ε ∘ α ′ ′ α ′ 2 k−1 k k−1 k k = ( … ∘ β , εB ∘ ⋯ α… B α B …α α B ) ′ ′ ′ ′ ′ = (α,0β)1 α1 βkαk αk kαk−1 2α1α1 2 αk−1 kαk Sinceα ε , … are proper walks then by defi- Figure 3. A proper walk in ( ). nition 2 is a proper walk in H( ) with the start 1 2 k vertex uπ, theπ finalπ vertex v and labelled l( ) = 퐻 훤 ( , ). Theπ necessity is proved. Γ The following theorem is true. A A π αSufficiencyε . Let be a proper walk in H( ) with Theorem 1 Let = (N, , ) be a context-free the start vertex u , the final vertex v and a label grammar and let A N . Then L( , A) if and l( ) = ( , ). If theπ length of is equal to 1,Γ then only if there is a properΓ walkΣ inΠ H( ) with the start is an arc and this Ais possible if and onlyA if there is a vertex u , the final vertex∈ v andα with∈ aΓ label( , ). productionπ α εA , ie L( ,πA). π Γ A A Suppose that for all A N and for all proper walks Proof. Necessity. Let L( , A). Then thereα isε a with the start vertex→ α u ,α the∈ finalΓ vertex v , length less derivation A .The proof we will make by induc- than or equal to t and with∈ a label ( , ) is satisfied α ∈ Γ A A tion on the length of the derivation. L( , A). Let be a proper walk with the start ⇒ α Let a production A exists. Then according to vertex u , the final vertex v , labelαlεed ( , ) and Definition 1, item 1 there exists an arc u v with a lengthα ∈ Γt + 1 > 1.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us