{- Copyright 2008 Debris This file is part of rcc. rcc is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. rcc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with rcc; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: rcc.hs,v 0.1 2008/07/04 08:16 debris $ -} -- Import main libraries. -- Environment, and the parsec monad. module Main where import System.Environment import Text.ParserCombinators.Parsec hiding (spaces) -- main application entry point. -- parse input expression on args. main :: IO () main = do args <- getArgs putStrLn (rccParseExpression (args !! 0)) -- Symbols definition. -- oneOf should be working by defining symbols to be any -- of the instances we mention in the string attached. rccSymbols :: Parser Char rccSymbols = oneOf "!$%&|*+-/:<=>?@^_~#" -- Spaces definition. -- spaces should not be taken in consideration, so we use -- the skipMany1 function to skip them out of the parser. rccSpaces :: Parser () rccSpaces = skipMany1 space -- Type definitions. -- types are currently somekind limited but they should -- be enough to perform some computation. data Type = AtomicType String | BooleanType Bool | DoubleType Double | IntegerType Integer | ListType [Type] | PairType [Type] Type | StringType String -- Parse input expression. -- checks for errors using symbols found. rccParseExpression :: String -> String rccParseExpression input = case parse (rccSpaces >> rccSymbols) "" input of Left err -> "Syntax error: Symbol expected at" ++ show err Right val -> "Found value"