Skip to content
Snippets Groups Projects
Commit 9074d0ce authored by Augustin Jaujay's avatar Augustin Jaujay
Browse files

question 9 finie

parent 589b4a25
No related branches found
No related tags found
No related merge requests found
(* 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)
......
(* 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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment