1 / 20

Constructing an Equivalent Regular Grammar from a Regular Expression

Constructing an Equivalent Regular Grammar from a Regular Expression. First of all you must remember the definition of a regular expression and the theorem: for any regular expression e , there exists a regular grammar  G recognizing exactly the language described by  e . Algorithm.

karena
Download Presentation

Constructing an Equivalent Regular Grammar from a Regular Expression

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Constructing an Equivalent Regular Grammar from a Regular Expression

  2. First of all you must remember the definition of a regular expression and the theorem: for any regular expressione, there exists a regular grammar Grecognizing exactly the language described by e.

  3. Algorithm 1. if the regular expression is simply 0, we can show that G, with no production rules, is an equivalent regular grammar.

  4. Algorithm 2. if the regular expression is simply 1, we can show that G, with one production rule S (where S is the start symbol), is an equivalent regular grammar.

  5. Algorithm 3. if the regular expression is simply a (a being any terminal), we can show that G, with one production ruleS->a (where S is the start symbol), is an equivalent regular grammar.

  6. Algorithm 4. if the regular expression is of the form e+f, where both e and f are regular expressions, use this algorithm to contruct two regular grammars G1 and G2 equivalent to e and f respectively. Now use regular grammar union on these two grammars to construct a regular grammar G which is equivalent to e+f.

  7. Algorithm 5. if the regular expression is of the form ef, where both e and f are regular expressions, use this algorithm to contruct two regular grammars G1 and G2 equivalent to e and f respectively. Now use regular grammar catenation on these two grammars to construct a regular grammar G which is equivalent to ef.

  8. Algorithm 6. if the regular expression is of the form e*, where e is a regular expression, use this algorithm to construct a regular grammar G equivalent to e. Now use regular grammar Kleene star closure to construct a regular grammar G' which is equivalent to e*.

  9. Algorithm 7. if the regular expression is of the forme+, where e is a regular expression, use this algorithm to construct a regular grammar G equivalent to e. Now use regular grammar Kleene plus closure to construct a regular grammar G' which is equivalent to e+.

  10. Example 1 • Consider the regular expression (a + b)*a. We will now construct a regular grammar for this regular expression. For every terminal symbol a, we create a regular grammar with the rule S->a, start symbol S. We then apply the transformations to these regular grammars, progressively constructing the regular grammar.

  11. Example 1 • First consider the expression a + b. We create two regular grammars: S1-> aandS2-> bwhereS1 and S2 are the start symbols. Clearly, these grammars recognize the regular expressionsa and b respectively.

  12. Example 1 • Now, we apply the union transformation for regular grammars to get:S3->a | bS1->aS2->b where S3 is the start symbol. This grammar obviously recognizesa + b.

  13. Example 1 • Next, we consider the expression (a + b)*.We already have a regular grammar for (a + b),so now we apply the Kleene star transformation on the regular grammar:

  14. S4->a | b | ε S3-> a | b S1-> aS3 S2 -> bS3where S4 is the start symbol.

  15. Example 1 • Recall that we need a regular grammar that recognizes(a + b)*a. We thus consider again the regular expression a. Again, we create a regular grammar that describes the language:S5->awhere S5 is the start symbol.

  16. Example 1 • We now construct the catenation of the regular grammar describing (a + b)* together with this one. We simply apply the transformation that catenates two regular grammars, to get:

  17. Algorithm S4->a | b | ε S3->aS5 | bS5 S1->aS3 S2->bS3 S5->a where S4 is the start symbol.

  18. Algorithm • This regular grammar is equivalent to the regular expression (a + b)*a.

  19. Example 2 • Please check the website in the references.

  20. References • http://www.inrialpes.fr/vasy/people/Gordon.Pace/Research/Software/Relic/Transformations/RE/toRG.html

More Related