AS_BASIC_CSL.hs revision f54cad0338da90c6789bb9baae1caec50d994b3a
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian Maeder{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
5ba323da9f037264b4a356085e844889aedeac23Christian MaederModule : $Header$
c58a94c44b76b072ace930f2126c889c0b64cb2aChristian MaederDescription : Abstract syntax for CSL
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederCopyright : (c) Dominik Dietrich, Ewaryst Schulz, DFKI Bremen 2010
ea03c5d09694b4a966fbd19d46cfa5772648d95fChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian MaederMaintainer : Ewaryst.Schulz@dfki.de
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaederStability : experimental
4b0a4c7dea0f67a233dcc42ce9bb18d36de109aeChristian MaederPortability : portable
ea03c5d09694b4a966fbd19d46cfa5772648d95fChristian MaederThis file contains the abstract syntax for CSL as well as pretty printer for it.
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maeder ( EXPRESSION (..) -- datatype for numerical expressions (e.g. polynomials)
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder , EXTPARAM (..) -- datatype for extended parameters (e.g. [I=0])
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder , BASIC_ITEM (..) -- Items of a Basic Spec
f8c07dc6526e0134d66885d461a30abadc2c6038Christian Maeder , BASIC_SPEC (..) -- Basic Spec
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder , SYMB_ITEMS (..) -- List of symbols
dc6b48bb46df8e56da3491c98476e6da0d1d5d1dChristian Maeder , SYMB (..) -- Symbols
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder , SYMB_MAP_ITEMS (..) -- Symbol map
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian Maeder , SYMB_OR_MAP (..) -- Symbol or symbol map
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder , OPNAME (..) -- predefined operator names
c00adad2e9459b422dee09e3a2bddba66b433bb7Christian Maeder , OPID (..) -- identifier for operators
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder , ConstantName (..) -- names of user-defined constants
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder , OP_ITEM (..) -- operator declaration
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder , VAR_ITEM (..) -- variable declaration
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , Domain (..) -- domains for variable declarations
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , GroundConstant (..) -- constants for domain formation
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , AssDefinition (..) -- A function or constant definition
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , getDefiniens -- accessor function for AssDefinition
502ed7ed7fecd10b6d0c83cdd48a244ec45e840aChristian Maeder , getArguments -- accessor function for AssDefinition
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , isFunDef -- predicate for AssDefinition
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian Maeder , isInterval -- predicate for EXPRESSION
c00adad2e9459b422dee09e3a2bddba66b433bb7Christian Maeder , mkDefinition -- constructor for AssDefinition
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder , updateDefinition -- updates the definiens
502ed7ed7fecd10b6d0c83cdd48a244ec45e840aChristian Maeder , InstantiatedConstant(..) -- for function constants we need to store the
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder -- instantiation
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder , CMD (..) -- Command datatype
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder , OperatorState (..) -- Class providing operator lookup
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder , mapExpr -- maps function over EXPRESSION arguments
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , mkVar -- Variable constructor
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian Maeder , mkOp -- Simple Operator constructor
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , mkPredefOp -- Simple Operator constructor for predefined ops
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , mkAndAnalyzeOp
23f8d286586ff38a9e73052b2c7c04c62c5c638fChristian Maeder , toElimConst -- Constant naming for elim constants, see Analysis.hs
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder , OpInfo (..) -- Type for Operator information
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , BindInfo (..) -- Type for Binder information
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian Maeder , operatorInfo -- Operator information for pretty printing
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder -- and static analysis
23f8d286586ff38a9e73052b2c7c04c62c5c638fChristian Maeder , operatorInfoMap -- allows efficient lookup of ops by printname
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder , operatorInfoNameMap -- allows efficient lookup of ops by opname
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian Maeder , mergeOpArityMap -- for combining two operator arity maps
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder , getOpInfoMap
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder , getOpInfoNameMap
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , lookupOpInfoForParsing
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian Maeder , lookupBindInfo
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , APInt, APFloat -- arbitrary precision numbers
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder , printExpression
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , printAssDefinition
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , printConstantName
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , ExpressionPrinter (..)
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , OpInfoNameMap
5ba323da9f037264b4a356085e844889aedeac23Christian Maederimport qualified Data.Map as Map
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder-- Arbitrary precision numbers
975642b989852fc24119c59cf40bc1af653608ffChristian Maedertype APInt = Integer
1d589334ba6b4a4cbfb35307a7a732261e77b0cdChristian Maeder-- TODO: use an arbitrary precision float here:
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder-- The use of Other floats (such as Double) requires an instance for
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder-- ShATermConvertible in Common.ATerm.ConvInstances
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maedertype APFloat = Double
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder-- | A simple operator constructor from given operator name and arguments
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaedermkOp :: String -> [EXPRESSION] -> EXPRESSION
9348e8460498ddfcd9da11cd8b5794c06023e004Christian MaedermkOp s el = Op (OpUser $ SimpleConstant s) [] el nullRange
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder-- | A variable constructor
9348e8460498ddfcd9da11cd8b5794c06023e004Christian MaedermkVar :: String -> EXPRESSION
9348e8460498ddfcd9da11cd8b5794c06023e004Christian MaedermkVar = Var . mkSimpleId
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder-- | A simple operator constructor from given operator id and arguments
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaedermkPredefOp :: OPNAME -> [EXPRESSION] -> EXPRESSION
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedermkPredefOp n el = Op (OpId n) [] el nullRange
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder-- | Lookup the string in the given 'OperatorState'
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian MaedermkAndAnalyzeOp :: OperatorState st => st -> String -> [EXTPARAM] -> [EXPRESSION]
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder -> Range -> EXPRESSION
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaedermkAndAnalyzeOp st s eps exps rg =
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder let err msg = "mkAndAnalyzeOp: At operator " ++ s ++ "\n" ++ msg
502ed7ed7fecd10b6d0c83cdd48a244ec45e840aChristian Maeder -- an error-message producing function
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder g msg | not $ null eps = Just $ err msg
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maeder ++ "* No extended parameters allowed\n"
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian Maeder | null msg = Nothing
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder | otherwise = Just $ err msg
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian Maeder opOrErr mOp x = case x of
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder Just msg -> error msg
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder _ -> let oi = fromJust mOp
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder in (foldNAry oi, OpId $ opname oi)
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder (fnary, op) =
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder case lookupOperator st s (length exps) of
628310b42327ad76ce471caf0dde6563d6fa6307Christian Maeder Left False -> (False, OpUser $ SimpleConstant s)
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder -- if registered it must be registered with the given arity or
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder -- as flex-op, otherwise we don't accept it
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian Maeder Left True -> opOrErr Nothing $ g "* Wrong arity\n"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder Right opinfo -> opOrErr (Just opinfo) $ g ""
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder e | fnary && length exps > 2 =
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder then foldl f (f (exps!!0) (exps!!1)) $ drop 2 exps
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder else error $ "mkAndAnalyzeOp: cannot fold application with "
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder ++ "extended parameters "
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian Maeder ++ show (pretty $ Op op eps exps rg)
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian Maeder | otherwise = Op op eps exps rg
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder f e' e'' = Op op [] [e', e''] rg
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedermapExpr :: (EXPRESSION -> EXPRESSION) -> EXPRESSION -> EXPRESSION
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder Op oi epl args rg -> Op oi epl (map f args) rg
5ba323da9f037264b4a356085e844889aedeac23Christian Maeder List exps rg -> List (map f exps) rg
aff01ee50b66032469c232e00c945d1fd4f57d1bChristian Maeder-- * CSL Basic Data Structures
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder-- | operator symbol declaration
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder deriving Show
5ba323da9f037264b4a356085e844889aedeac23Christian Maeder-- | variable symbol declaration
5ba323da9f037264b4a356085e844889aedeac23Christian Maederdata VAR_ITEM = Var_item [Id.Token] Domain Id.Range
5ba323da9f037264b4a356085e844889aedeac23Christian Maeder deriving Show
ffd01020a4f35f434b912844ad6e0d6918fadffdChristian Maedernewtype BASIC_SPEC = Basic_spec [AS_Anno.Annoted (BASIC_ITEM)]
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder deriving Show
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maederdata GroundConstant = GCI APInt | GCR APFloat deriving (Eq, Ord, Show)
c9892acbf03a509d874ac6d79b9a2cb09042e0dcChristian Maeder-- | A finite set or an interval. True = closed, False = opened
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maederdata Domain = Set [GroundConstant]
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder | IntVal (GroundConstant, Bool) (GroundConstant, Bool)
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder deriving (Eq, Ord, Show)
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder-- | A constant or function definition
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maederdata AssDefinition = ConstDef EXPRESSION | FunDef [String] EXPRESSION
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder deriving (Eq, Ord, Show)
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaederupdateDefinition :: EXPRESSION -> AssDefinition -> AssDefinition
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaederupdateDefinition e' (ConstDef _) = ConstDef e'
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaederupdateDefinition e' (FunDef l _) = FunDef l e'
b49276c9f50038e0bd499ad49f7bd6444566a834Christian MaedermkDefinition :: [String] -> EXPRESSION -> AssDefinition
9348e8460498ddfcd9da11cd8b5794c06023e004Christian MaedermkDefinition l e = if null l then ConstDef e else FunDef l e
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedergetDefiniens :: AssDefinition -> EXPRESSION
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedergetDefiniens (ConstDef e) = e
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedergetDefiniens (FunDef _ e) = e
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedergetArguments :: AssDefinition -> [String]
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedergetArguments (FunDef l _) = l
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedergetArguments _ = []
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaederisFunDef :: AssDefinition -> Bool
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaederisFunDef (FunDef _ _) = True
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaederisFunDef _ = False
afa6848d579d235c9677e1ab477916df8e5ae11aChristian MaederisInterval :: EXPRESSION -> Bool
afa6848d579d235c9677e1ab477916df8e5ae11aChristian MaederisInterval (Interval _ _ _) = True
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaederisInterval _ = False
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maederdata InstantiatedConstant = InstantiatedConstant
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder { constName :: ConstantName
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder , instantiation :: [EXPRESSION] } deriving (Show, Eq, Ord)
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maederinstance Pretty InstantiatedConstant where
f8c07dc6526e0134d66885d461a30abadc2c6038Christian Maeder pretty (InstantiatedConstant { constName = cn, instantiation = el }) =
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder if null el then pretty cn
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder else pretty cn <> (parens $ sepByCommas $ map pretty el)
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder-- | basic items: an operator or variable declaration or an axiom
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maederdata BASIC_ITEM =
f8c07dc6526e0134d66885d461a30abadc2c6038Christian Maeder Op_decl OP_ITEM
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder | Var_decls [VAR_ITEM]
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder | Axiom_item (AS_Anno.Annoted CMD)
f8c07dc6526e0134d66885d461a30abadc2c6038Christian Maeder deriving Show
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder-- | Extended Parameter Datatype
f8c07dc6526e0134d66885d461a30abadc2c6038Christian Maederdata EXTPARAM = EP Id.Token String APInt deriving (Eq, Ord, Show)
f8c07dc6526e0134d66885d461a30abadc2c6038Christian Maeder -- arithmetic operators
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder OP_mult | OP_div | OP_plus | OP_minus | OP_neg | OP_pow
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder -- roots, trigonometric and other operators
f8c07dc6526e0134d66885d461a30abadc2c6038Christian Maeder | OP_fthrt | OP_sqrt | OP_abs | OP_max | OP_min | OP_sign
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder | OP_cos | OP_sin | OP_tan | OP_Pi
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder -- special CAS operators
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder | OP_minimize | OP_minloc | OP_maximize | OP_maxloc | OP_factor
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder | OP_divide | OP_factorize | OP_int | OP_rlqe | OP_simplify | OP_solve
f8c07dc6526e0134d66885d461a30abadc2c6038Christian Maeder -- comparison predicates
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder | OP_neq | OP_lt | OP_leq | OP_eq | OP_gt | OP_geq | OP_convergence
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder | OP_reldistLe
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder -- containment predicate
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder -- special CAS constants
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder | OP_undef | OP_failure
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder -- boolean constants and connectives
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder | OP_false | OP_true | OP_not | OP_and | OP_or | OP_impl
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder -- quantifiers
f8c07dc6526e0134d66885d461a30abadc2c6038Christian Maeder | OP_ex | OP_all
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder deriving (Eq, Ord)
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maederinstance Show OPNAME where
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder show = showOPNAME
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaedershowOPNAME :: OPNAME -> String
f8c07dc6526e0134d66885d461a30abadc2c6038Christian MaedershowOPNAME x =
afa6848d579d235c9677e1ab477916df8e5ae11aChristian Maeder OP_neq -> "!="
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder OP_mult -> "*"
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder OP_plus -> "+"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_minus -> "-"
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder OP_neg -> "-"
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder OP_div -> "/"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_leq -> "<="
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_geq -> ">="
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_Pi -> "Pi"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_pow -> "^"
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder OP_abs -> "abs"
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder OP_sign -> "sign"
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder OP_all -> "all"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_and -> "and"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_convergence -> "convergence"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_cos -> "cos"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_divide -> "divide"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_ex -> "ex"
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder OP_factor -> "factor"
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder OP_factorize -> "factorize"
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder OP_fthrt -> "fthrt"
9348e8460498ddfcd9da11cd8b5794c06023e004Christian Maeder OP_impl -> "impl"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_int -> "int"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_max -> "max"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_maximize -> "maximize"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_maxloc -> "maxloc"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_min -> "min"
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder OP_minimize -> "minimize"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_minloc -> "minloc"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_not -> "not"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_or -> "or"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_reldist -> "reldist"
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder OP_reldistLe -> "reldistLe"
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder OP_rlqe -> "rlqe"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_simplify -> "simplify"
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder OP_sin -> "sin"
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder OP_solve -> "solve"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_sqrt -> "sqrt"
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder OP_tan -> "tan"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_false -> "false"
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder OP_true -> "true"
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder OP_in -> "in"
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder OP_undef -> "undef"
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder OP_failure -> "fail"
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maederdata OPID = OpId OPNAME | OpUser ConstantName deriving (Eq, Ord, Show)
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder-- | We differentiate between simple constant names and indexed constant names
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder-- resulting from the extended parameter elimination.
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maederdata ConstantName = SimpleConstant String | ElimConstant String Int
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder deriving (Eq, Ord, Show)
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedersimpleName :: OPID -> String
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedersimpleName (OpId n) = showOPNAME n
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedersimpleName (OpUser (SimpleConstant s)) = s
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedersimpleName (OpUser x) = error "simpleName: ElimConstant not supported: " ++ show x
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maederinstance Show OPID where
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder show (OpId n) = show n
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian Maeder show (OpUser s) = show s
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maederinstance Show ConstantName where
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder show (SimpleConstant s) = s
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder show (ElimConstant s i) = if i > 0 then s ++ "__" ++ show i else s
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedertoElimConst :: ConstantName -> Int -> ConstantName
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedertoElimConst (SimpleConstant s) i = ElimConstant s i
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedertoElimConst ec _ = error $ "toElimConst: already an elim const " ++ show ec
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder-- | Datatype for expressions
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maederdata EXPRESSION =
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder | Op OPID [EXTPARAM] [EXPRESSION] Id.Range
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder -- TODO: don't need lists anymore, they should be removed soon
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder | List [EXPRESSION] Id.Range
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder | Interval APFloat APFloat Id.Range
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder | Double APFloat Id.Range
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maeder deriving (Eq, Ord, Show)
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder-- | If the expression list is a variable list the list of the variable names
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder-- is returned.
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedertoArgList :: [EXPRESSION] -> [String]
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedertoArgList [] = []
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian MaedertoArgList (Var tok:l) = tokStr tok : toArgList l
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian MaedertoArgList (x:_) = error $ "toArgList: unsupported as argument " ++ show (pretty x)
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder-- TODO: add Range-support to this type
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maederdata CMD = Ass EXPRESSION EXPRESSION
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder | Cmd String [EXPRESSION]
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder | Sequence [CMD] -- program sequence
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder | Cond [(EXPRESSION, [CMD])]
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder | Repeat EXPRESSION [CMD] -- constraint, statements
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder deriving (Show, Eq, Ord)
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maeder-- | symbol lists for hiding
0be2d0cfd911d313e7e941edbc77f95052c8c19bChristian Maederdata SYMB_ITEMS = Symb_items [SYMB] Id.Range
newtype SYMB = Symb_id Id.Token
data SYMB_MAP_ITEMS = Symb_map_items [SYMB_OR_MAP] Id.Range
| Symb_map SYMB SYMB Id.Range
-- * Predefined Operators: info for parsing/printing and static analysis
type ArityMap = Map.Map Int OpInfo
type OpInfoArityMap a = Map.Map a ArityMap
getOpInfoMap pf oinfo = foldl f Map.empty oinfo
(Map.fromList [(arity oi, oi)]) m
getOpInfoNameMap oinfo = foldl f Map.empty oinfo
(Map.fromList [(arity oi, oi)]) m
case Map.lookup op oiMap of
case Map.lookup arit oim of
case Map.lookup (-1) oim of
case Map.lookup op oinm of
case Map.lookup arit oim of
case Map.lookup (-1) oim of
case Map.lookup op oinm of
case Map.lookup arit oim of
-- more flexible w.r.t. the output of 'ConstantName'.