fork(1) download
  1. import Data.Char ( isSpace )
  2.  
  3. _sexpr "" = []
  4. _sexpr exp@(tok:exp_t)
  5. | id == "" = [tok]:sexpr exp_t
  6. | otherwise = id:sexpr exp_tt
  7. where
  8. (id,exp_tt) = break isSep exp
  9. isSep c = c `elem` "()" || isSpace c
  10.  
  11. sexpr = _sexpr . dropWhile isSpace
  12.  
  13. main = interact $ unlines . fmap (show . sexpr) . lines
Success #stdin #stdout 0s 4616KB
stdin
(+ 12 (* 3 4 (+ 1 2 3) 5) 1)
stdout
["(","+","12","(","*","3","4","(","+","1","2","3",")","5",")","1",")"]