Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
javawlp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
impresshs
javawlp
Commits
6942b5aa
Verified
Commit
6942b5aa
authored
7 years ago
by
Ogilvie, D.H. (Duncan)
Browse files
Options
Downloads
Patches
Plain Diff
implemented LogicIR.Expr and LogicIR.Fold
parent
2254d3e5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/LogicIR/Expr.hs
+60
-0
60 additions, 0 deletions
src/LogicIR/Expr.hs
src/LogicIR/Fold.hs
+43
-0
43 additions, 0 deletions
src/LogicIR/Fold.hs
with
103 additions
and
0 deletions
src/LogicIR/Expr.hs
0 → 100644
+
60
−
0
View file @
6942b5aa
module
LogicIR.Expr
where
-- Based on my (Duncan's) previous work: https://github.com/mrexodia/wp/blob/master/Wp.hs
-- Numeral unary operators
data
NUnop
=
NNeg
|
NNot
deriving
(
Show
,
Eq
,
Read
)
-- Numeral binary operators
data
NBinop
=
NAdd
|
NSub
|
NMul
|
NDiv
|
NRem
|
NShl
|
NShr
|
NAnd
|
NOr
|
NXor
deriving
(
Show
,
Eq
,
Read
)
-- Numeral expressions
data
NExpr
=
NConst
Int
-- Integer constant
|
NVar
String
-- Named integer variable
|
NUnop
NUnop
NExpr
-- Unary operator
|
NBinop
NExpr
NBinop
NExpr
-- Binary operators
|
NArray
String
NExpr
-- Integer array access
deriving
(
Show
,
Eq
,
Read
)
-- Reference: https://en.wikipedia.org/wiki/First-order_logic#Logical_symbols
-- Logical operators
data
LBinop
=
LAnd
-- Conjunction
|
LOr
-- Disjunction
|
LImpl
-- Implication
|
LBicond
-- Biconditional (TODO: remove?)
deriving
(
Show
,
Eq
,
Read
)
-- Quantifier operators
data
QOp
=
QAll
|
QAny
deriving
(
Show
,
Eq
,
Read
)
-- Comparison operators
data
COp
=
CEqual
|
CLess
|
CGreater
|
CLeq
|
CGeq
deriving
(
Show
,
Eq
,
Read
)
-- Logical expressions
data
LExpr
=
LConst
Bool
-- True/False
|
LVar
String
-- Named boolean variable
|
LNot
LExpr
-- Logical negation/not
|
LBinop
LExpr
LBinop
LExpr
-- Logical operator
|
LComp
NExpr
COp
NExpr
-- Integer comparison
|
LQuant
QOp
[
String
]
LExpr
-- Logical quantifier
|
LArray
String
NExpr
-- Logical array access (TODO: remove?)
deriving
(
Show
,
Eq
,
Read
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/LogicIR/Fold.hs
0 → 100644
+
43
−
0
View file @
6942b5aa
module
LogicIR.Fold
where
import
LogicIR.Expr
-- Fold algrbra for numeral expressions
type
NExprAlgebra
r
=
(
Int
->
r
,
-- NConst
String
->
r
,
-- NVar
NUnop
->
r
->
r
,
-- NUnop
r
->
NBinop
->
r
->
r
,
-- NBinop
String
->
r
->
r
-- NArray
)
-- Fold for numeral expressions
foldNExpr
::
NExprAlgebra
r
->
NExpr
->
r
foldNExpr
(
const
,
var
,
unop
,
binop
,
array
)
=
fold
where
fold
e
=
case
e
of
NConst
n
->
const
n
NVar
n
->
var
n
NUnop
o
e
->
unop
o
(
fold
e
)
NBinop
a
o
b
->
binop
(
fold
a
)
o
(
fold
b
)
NArray
n
e
->
array
n
(
fold
e
)
-- Fold algebra for logical expressions
type
LExprAlgebra
r
=
(
Bool
->
r
,
-- LConst
String
->
r
,
-- LVar
r
->
r
,
-- LNot
r
->
LBinop
->
r
->
r
,
-- LBinop
NExpr
->
COp
->
NExpr
->
r
,
-- LComp
QOp
->
[
String
]
->
r
->
r
,
-- LQuant
String
->
NExpr
->
r
-- LArray
)
-- Fold for logical expressions
foldLExpr
::
LExprAlgebra
r
->
LExpr
->
r
foldLExpr
(
const
,
var
,
not
,
binop
,
comp
,
quant
,
array
)
=
fold
where
fold
e
=
case
e
of
LConst
c
->
const
c
LVar
n
->
var
n
LNot
e
->
not
(
fold
e
)
LBinop
a
o
b
->
binop
(
fold
a
)
o
(
fold
b
)
LComp
a
o
b
->
comp
a
o
b
LQuant
o
vs
e
->
quant
o
vs
(
fold
e
)
LArray
n
e
->
array
n
e
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment