Open twesterhout opened 6 years ago
Not sure about this? Need you input?
typo in scanner. Needs to be scanAirthOp
` data TokenCompareOp = Error | CompareOp [Char]
scanCompareOp :: [Char] -> TokenCompareOp
scanCompareOp input = s0 input
where
s0 [s : r]
| s =~ "['!' | '=']" = s1 [s] r
| s =~ "['<' | '>']" = s2 [s] r
| otherwise = Error
s1 t [s : r]
| s == '=' = s3 (t++[s]) r
| otherwise = Error
s2 t [s : r]
| s =~ ['=' | ''] = s3 (t++[s]) r
| otherwise = Error
s3 t input = TokenCompareOp t
`
` data TokenLogicalOp = Error | LogicalOp [Char]
scanLogicalOp :: [Char] -> TokenLogicalOp scanLogicalOp input = s0 input where s0 [s : r] | s == '&' = s1 [s] r | s == '|' = s2 [s] r | otherwise = Error s1 t [s : r] | s == '&' = s3 (t++[s]) r | otherwise = Error s2 t [s : r] | s == '|' = s3 (t++[s]) r | otherwise = Error s3 t input = TokenLogicalOp t `
And how am I supposed to figure out which operator I have?
Also, if you're writing such small code snippets, why not test them in ghci?
` data TokenArithmeticOp = Error | ArithmeticOp
scanArithOp :: Char -> TokenOperator scanner input | input =~ "['+' | '-' | '*' | '/' | '%' ]" = ArithmeticOp | otherwise = Error `