Question: Define a function which analyzes regular expressions defined using this type. data RE a -- regular expressions over an alphabet defined by 'a' = Empty

Define a function which analyzes regular expressions defined using this type.
data RE a -- regular expressions over an alphabet defined by 'a' = Empty -- empty regular expression | Sym a -- match the given symbol | RE a :+: RE a -- concatenation of two regular expressions | RE a :|: RE a -- choice between two regular expressions | Rep (RE a) -- zero or more repetitions of a regular expression | Rep1 (RE a) -- one or more repetitions of a regular expression deriving (Show)
 firstMatches :: RE a -> [a] Given a regular expression r, return a list of all symbols that occur first in some string in the language described by r. You are not required to eliminate duplicates (since nothing is known about the alphabet, doing so would be impossible), but the list should be finite. No particular order is required. Some examples: firstMatches (Sym 'a') = ['a'] firstMatches (Rep (Sym 'a' :|: Sym 'b')) = ['a', 'b'] firstMatches (Sym 1 :+: Sym 2) = [1] firstMatches ((Sym 1 :|: Empty) :+: Sym 2) = [1,2]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!