-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTypes.hs
More file actions
87 lines (67 loc) · 1.97 KB
/
Types.hs
File metadata and controls
87 lines (67 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
module Types where
import Text.Megaparsec.Pos
-- | Types
data Type = TAtom | TInt | TString| TList | TVar TypeVar | TDef TypeName [TypeVar]
deriving(Show, Eq)
type Line = Int
--
-- * Basic Object of Type Declaration
--
-- | A list of the type declaration
type TypeDic = [(Dec,Line)]
type PredicateT = (PredName, [Type])
type FunctorT = (FuncName,[Type],Type)
data Dec = PredD PredicateT | FuncD FunctorT
deriving(Show)
-- | Names
type VarName = String -- upper case
type AtomName = String -- lower case
type PredName = String -- lower case
type FuncName = String -- lower case
--
-- * User defined type
--
type TypeDef = [(DefinedType,Line)]
type TypeName = String -- upper case
type TypeVar = String -- lower case start with _
type ConstructorName = String -- lower case
type Cons = (ConstructorName,[Type])
data DefinedType = TypeT TypeName Type
| DataT TypeName [TypeVar] [Cons]
deriving(Show)
--
-- * Basic Object of Prolog Program
--
-- | A set of Prolog Predicate
type Prog = [(Rule,Line)]
type PredFunA = (String, [Argument])
-- | Rules in Prolog, Head + Body
data Rule = Head PredFunA Body
deriving(Show)
data Argument = Atom AtomName
| LitI Int
| LitS String
| List [Argument]
| Var VarName
| Func PredFunA
| OperA OptA Argument Argument
deriving(Show)
-- | Body is a list of BodyElem
type Body = [BodyElem]
-- | Operation includes Mathematic Operation and comparasion
data OptA = Sub | Add | Div | Mult| Mod
deriving(Show)
-- | Operation includes Mathematic Operation and comparasion
data OptC = Eq | Neq | Lt | Leq | Gt | Gtq
deriving(Show)
-- | Element of Body:
data BodyElem = Pred PredFunA
| Is Argument Argument
| OperC OptC Argument Argument
| And BodyElem BodyElem
deriving(Show)
--
-- entire prolog program
--
data Prolog = PL (TypeDef, TypeDic, Prog)
deriving (Show)