Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
lfa:lab03-dfa-regexp [2021/10/09 19:38] pdmatei |
lfa:lab03-dfa-regexp [2021/10/16 18:57] (current) pdmatei |
||
|---|---|---|---|
| Line 31: | Line 31: | ||
| \\ | \\ | ||
| - | ===== 4.2. Regex implementation ===== | + | ===== 4.2. Writing Regular Expressions ===== |
| + | |||
| + | **4.2.1.** Write a regular expression for the language of arithmetic expressions containing +, * and numbers. | ||
| + | **Hint:** you can abbreviate $ 0 \cup 1 \cup ... \cup 9 $ by $ [0-9] $ | ||
| + | |||
| + | **4.2.2.** Write a regular expression for $ L = \{ \omega \text{ in } \text{{0,1}} ^* \text{ | EVERY sequence of two or more consecutive zeros appears before ANY sequence of two or more consecutive ones} \} $ | ||
| + | |||
| + | **4.2.3.** Write a DFA for $ L(( 10 \cup 0) ^* ( 1 \cup \epsilon )) $ | ||
| + | |||
| + | **4.2.4.** Write a regular expression which generates the accepted language of A: | ||
| + | |||
| + | {{:lfa:graf1.png?200|}} | ||
| + | |||
| + | **4.2.5.** Simplify the regular expression you found. | ||
| + | |||
| + | **4.2.6.** Describe as precisely as possible the language generated by $math[(1 \cup 1(01^*0)1)^*] | ||
| + | |||
| + | |||
| + | ===== 4.3. Regex implementation (Python) ===== | ||
| ==== Inheritance and isinstance ==== | ==== Inheritance and isinstance ==== | ||
| Line 78: | Line 96: | ||
| </code> | </code> | ||
| - | **4.2.1.** Write a class hierarchy for Regular Expressions, and add the ''__str__'' function for each of them. Implement a constructor which reads a Regular Expression in **Prenex form**, from a string. The prenex form is illustrated below via examples: | + | **4.3.1.** Write a class hierarchy for Regular Expressions, and add the ''__str__'' function for each of them. Implement a constructor which reads a Regular Expression in **Prenex form**, from a string. The prenex form is illustrated below via examples: |
| <code Python> | <code Python> | ||
| Line 119: | Line 137: | ||
| </hidden> | </hidden> | ||
| + | ===== 4.4. Regex implementation (Haskell) ===== | ||
| - | ===== 4.3. Writing Regular Expressions ===== | + | **4.4.1.** Implement the ADT ''Regex''. |
| - | + | ||
| - | + | ||
| - | **4.3.1.** Write a regular expression for the language of arithmetic expressions containing +, * and numbers. | + | |
| - | **Hint:** you can abbreviate $ 0 \cup 1 \cup ... \cup 9 $ by $ [0-9] $ | + | |
| - | + | ||
| - | **4.3.2.** Write a regular expression for $ L = \{ \omega \text{ in } \text{{0,1}} ^* \text{ | every sequence of consecutive zeros appears before ANY sequence of consecutive ones} \} $ | + | |
| - | + | ||
| - | **4.3.3.** Write a DFA for $ L(( 10 \cup 0) ^* ( 1 \cup \epsilon )) $ | + | |
| - | + | ||
| - | **4.3.4.** Write a regular expression which generates the accepted language of A: | + | |
| - | + | ||
| - | {{:lfa:graf1.png?200|}} | + | |
| - | + | ||
| - | **4.3.5.** Simplify the regular expression you found. | + | |
| - | **4.3.6.** Describe as precisely as possible the language generated by $math[(1 \cup 1(01^*0)1)^*] | + | **4.4.2.** Enrol the type in class ''Show''. |
| + | **4.4.3.** Write a function which takes a string containing a regex in prenex form (see the Python exercises) and returns a ''Regex''. ***Hint:** use two mutually recursive functions and see the hints regarding the stack from the Python implementation section. | ||