Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compilerLaLog
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
JAUJAY Augustin
compilerLaLog
Commits
9074d0ce
Commit
9074d0ce
authored
3 years ago
by
Augustin Jaujay
Browse files
Options
Downloads
Patches
Plain Diff
question 9 finie
parent
589b4a25
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pfx/basic/ast.ml
+2
-1
2 additions, 1 deletion
pfx/basic/ast.ml
pfx/basic/ast.mli
+1
-1
1 addition, 1 deletion
pfx/basic/ast.mli
pfx/basic/eval.ml
+1
-0
1 addition, 0 deletions
pfx/basic/eval.ml
with
4 additions
and
2 deletions
pfx/basic/ast.ml
+
2
−
1
View file @
9074d0ce
(* Question 4.1 *)
type
command
=
Push
of
int
|
Pop
|
Swap
|
Add
|
Sub
|
Mul
|
Div
|
Rem
|
Exec
|
Get
type
command
=
Push
of
int
|
Pop
|
Swap
|
Add
|
Sub
|
Mul
|
Div
|
Rem
|
Exec
|
Get
|
InstructionSeq
of
command
list
type
program
=
int
*
command
list
...
...
@@ -16,6 +16,7 @@ let string_of_command = function
|
Rem
->
"Rem"
|
Exec
->
"Exec"
|
Get
->
"Get"
|
InstructionSeq
_
->
"Instruction sequence"
let
string_of_commands
cmds
=
String
.
concat
" "
(
List
.
map
string_of_command
cmds
)
...
...
This diff is collapsed.
Click to expand it.
pfx/basic/ast.mli
+
1
−
1
View file @
9074d0ce
(* The type of the commands for the stack machine *)
type
command
=
Push
of
int
|
Pop
|
Swap
|
Add
|
Sub
|
Mul
|
Div
|
Rem
|
Exec
|
Get
type
command
=
Push
of
int
|
Pop
|
Swap
|
Add
|
Sub
|
Mul
|
Div
|
Rem
|
Exec
|
Get
|
InstructionSeq
of
command
list
(* The type for programs *)
type
program
=
int
*
command
list
...
...
This diff is collapsed.
Click to expand it.
pfx/basic/eval.ml
+
1
−
0
View file @
9074d0ce
...
...
@@ -61,6 +61,7 @@ let step state =
|
Rem
::
q
,
(
Int
x
)
::
(
Int
y
)
::
stack
->
Ok
(
q
,
(
Int
(
x
mod
y
))
::
stack
)
|
Get
::
q
,
(
Int
i
)
::
stack
->
Ok
(
q
,
(
List
.
nth
stack
i
)
::
stack
)
|
Exec
::
q
,
(
InstructionSeq
s
)
::
stack
->
Ok
(
s
@
q
,
stack
)
|
(
InstructionSeq
s
)
::
q
,
stack
->
Ok
(
q
,
(
InstructionSeq
s
)
::
stack
)
let
eval_program
(
numargs
,
cmds
)
args
=
let
rec
execute
=
function
...
...
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