Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
9aedb141
Commit
9aedb141
authored
Dec 04, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
funclang series5: Added expr2string function for ass12.
parent
f1ee4828
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
funclang-taddeus/series5/ass12.ml
funclang-taddeus/series5/ass12.ml
+61
-0
No files found.
funclang-taddeus/series5/ass12.ml
0 → 100644
View file @
9aedb141
type
monop
=
Neg
|
Not
type
binop
=
Add
|
Sub
|
Mul
|
Div
|
Mod
(* arithmetic operators *)
|
Eq
|
Ne
|
Lt
|
Le
|
Gt
|
Ge
(* relational operators *)
|
And
|
Or
(* logic operators *)
type
expr
=
Num
of
int
(* integer constant *)
|
Bool
of
bool
(* boolean constant *)
|
Var
of
string
(* variable *)
|
MonopAp
of
monop
*
expr
(* unary operator application *)
|
BinopAp
of
binop
*
expr
*
expr
(* binary operator application *)
|
Cond
of
expr
*
expr
*
expr
(* conditional expression *)
|
Fun
of
string
*
expr
(* function abstraction *)
|
FunAp
of
expr
*
expr
(* function application *)
|
Let
of
string
*
expr
*
expr
(* variable binding *)
|
LetRec
of
string
*
expr
*
expr
(* recursive variable binding *)
let
rec
expr2string
=
let
monop2string
=
function
Neg
->
"-"
|
Not
->
"not "
in
let
binop2string
=
function
Add
->
"+"
|
Sub
->
"-"
|
Mul
->
"*"
|
Div
->
"/"
|
Mod
->
"mod"
|
Eq
->
"="
|
Ne
->
"!="
|
Lt
->
"<"
|
Le
->
"<="
|
Gt
->
">"
|
Ge
->
">="
|
And
->
"&&"
|
Or
->
"||"
in
function
Num
i
->
string_of_int
i
|
Bool
b
->
string_of_bool
b
|
Var
v
->
v
|
MonopAp
(
op
,
e
)
->
monop2string
(
op
)
^
expr2string
(
e
)
|
BinopAp
(
op
,
e1
,
e2
)
->
expr2string
(
e1
)
^
" "
^
binop2string
(
op
)
^
" "
^
expr2string
(
e2
)
|
Cond
(
cond
,
e1
,
e2
)
->
"if "
^
expr2string
(
cond
)
^
" then "
^
expr2string
(
e1
)
^
" else "
^
expr2string
(
e2
)
|
Fun
(
arg
,
e
)
->
"fun "
^
arg
^
" -> "
^
expr2string
(
e
)
|
FunAp
(
e1
,
e2
)
->
"("
^
expr2string
(
e1
)
^
" "
^
expr2string
(
e2
)
^
")"
|
Let
(
var
,
e1
,
e2
)
->
"let "
^
var
^
" = "
^
expr2string
(
e1
)
^
" in "
^
expr2string
(
e2
)
|
LetRec
(
var
,
e1
,
e2
)
->
"let rec "
^
var
^
" = "
^
expr2string
(
e1
)
^
" in "
^
expr2string
(
e2
)
;;
(* let a = 1 in b *)
print_endline
(
expr2string
(
Let
(
"a"
,
(
Num
1
)
,
(
Var
"b"
))));;
(* a + 3 *)
print_endline
(
expr2string
(
BinopAp
(
Add
,
Var
"a"
,
Num
3
)));;
(* -a *)
print_endline
(
expr2string
(
MonopAp
(
Neg
,
Var
"a"
)));;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment