CS计算机代考程序代写 ocaml open MicroCamlTypes

open MicroCamlTypes
open Utils
open TokenTypes

(* Provided functions – DO NOT MODIFY *)

(* Matches the next token in the list, throwing an error if it doesn’t match the given token *)
let match_token (toks: token list) (tok: token) =
match toks with
| [] -> raise (InvalidInputException(string_of_token tok))
| h::t when h = tok -> t
| h::_ -> raise (InvalidInputException(
Printf.sprintf “Expected %s from input %s, got %s”
(string_of_token tok)
(string_of_list string_of_token toks)
(string_of_token h)))

(* Matches a sequence of tokens given as the second list in the order in which they appear, throwing an error if they don’t match *)
let match_many (toks: token list) (to_match: token list) =
List.fold_left match_token toks to_match

(* Return the next token in the token list as an option *)
let lookahead (toks: token list) =
match toks with
| [] -> None
| h::t -> Some h

(* Return the token at the nth index in the token list as an option*)
let rec lookahead_many (toks: token list) (n: int) =
match toks, n with
| h::_, 0 -> Some h
| _::t, n when n > 0 -> lookahead_many t (n-1)
| _ -> None

(* PASTE YOUR PARSERS FROM P4A HERE *)

let rec parse_expr toks = failwith “unimplemented”

let rec parse_mutop toks = failwith “unimplemented”