我的代码目前看起来像这样。它应该在事先给我们的正则表达式定义中显示可能的第一个符号。我应该把这些打印出来作为一个列表。例如,如果答案应该是 [1,2],它会出现 [1,2] 但当答案应该是 ['1','2'] 时,它会出现“12”或当它应该是 ['a', 'b'] 时,它会出现“ab”。我究竟做错了什么?
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]
firstMatches Empty = []
firstMatches (Sym a)= a:list
firstMatches(Rep(a))=firstMatches a
firstMatches(Rep1(a))=firstMatches a
firstMatches (Empty :+: b)= firstMatches b
firstMatches (a :+: _) = firstMatches a
firstMatches (a :|: b)= firstMatches a ++ firstMatches b