Question: In Haskell data RE a -- regular expressions over an alphabet defined by 'a' = Empty -- empty regular expression | Sym a -- match

In Haskell

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 1) -- one or more repetitions of a regular expression deriving (Show)
Define two functions which analyze regular expressions defined using this type. - matchEmpty :: RE a -> Bool This function returns true if the regular expression matches an empty string. Note that the type does not include any constraints on the alphabet. Among other things, this means that will not be able to use the matches function we defined in class, as it requires 'a' to be an instance of Eq. Some examples: matchEmpty (Sym 'a') = False matchEmpty (Rep (Sym 'a' :+: Sym 'b')) = True matchEmpty (Rep1 (Sym 'a' :|: Empty)) = True - 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: firstMatch (Sym 'a') = ['a'] firstMatch (Rep (Sym 'a' :|: Sym 'b')) = ['a', 'b'] firstMatch (Sym 1 :+: Sym 2) = [1] firstMatch ((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!