twesterhout / splc

Simple Programming Language Compiler developed as part of the Compiler Construction course at Radboud University
MIT License
0 stars 0 forks source link

Recognising operators #6

Open twesterhout opened 6 years ago

Rera93 commented 6 years ago

` data TokenArithmeticOp = Error | ArithmeticOp

scanArithOp :: Char -> TokenOperator scanner input | input =~ "['+' | '-' | '*' | '/' | '%' ]" = ArithmeticOp | otherwise = Error `

Rera93 commented 6 years ago

Not sure about this? Need you input?

Rera93 commented 6 years ago

typo in scanner. Needs to be scanAirthOp

Rera93 commented 6 years ago

` 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 `

Rera93 commented 6 years ago

` 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 `

twesterhout commented 6 years ago

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?