YaK:: Haskell : Toy List Translator [Changes]   [Calendar]   [Search]   [Index]   [PhotoTags]   
[mega_changes]
[photos]

Haskell: Toy List Translator


module Main where
import Monad
import System.Environment
import Control.Monad.Error
import Text.ParserCombinators.Parsec

-- ghc --make p.hs  &&  ./p '((#)(())(((:)))(.))' one two three

main :: IO ()
main = do
  args <- getArgs
  putStrLn $ args !! 0
  putStrLn $ foldl (++) "" args
  putStrLn $ foldl (\a b -> a ++ "," ++ b) "" args
  putStrLn $ translateList (args !! 0)
  return ()

translateList :: String -> String
translateList input =
  case parse parseList "LIST" input of
    Left err -> "ERROR{" ++ show err ++ "}"
    Right s -> "GOOD{" ++ show s ++ "}"

symbolStr :: Parser String
symbolStr = liftM (\c -> [c,c,c]) symbol

symbol :: Parser Char
symbol = oneOf "!$%|*+-/:<=?>@#,^"

parseDot :: Parser String
parseDot = (char '.') >> (return ")")

parseLists :: Parser String
parseLists = do
  -- z <- (try parseList) <|> parseDot
  z <- (try parseList) <|> symbolStr <|> parseDot
  return z


parseList :: Parser String
parseList = do
  char '('
  inner <- many parseLists
  char ')'
  return $ "<" ++ (foldl (++) "" inner) ++ ">"
  • translateList.hs
  • translateGo.hs
  • (unless otherwise marked) Copyright 2002-2014 YakPeople. All rights reserved.
    (last modified 2010-11-07)       [Login]
    (No back references.)