0

I've been staring at this code for a while now and can't figureout why I'm getting a syntax error:

let rec e_closure (m:nfa_t) (l:int list) = match m with
    | (_, _, (ts:transition list)) -> 
        List.sort_uniq (List.fold_left 
                            (fun (lst:int list) (state:int) -> 
                                List.fold_left 
                                    (fun (lst2:int list) (t:transition) -> 
                                        match t with 
                                        | ((start:int), (letter:char option), (end:int)) -> (if ((start = a) && (isEpilson letter)) then end::lst2 else lst2) 
                                        | _ -> raise (NFAError "e_closure match failure (nested)")) lst ts) l l)
    | _ -> raise (NFAError "e_closure match failure")
;;

Without getting into too much detail about this convoluted code, it's function is to return a list of the epsilon-closures of a state given a NFA (Non-deterministic Finite Automata). It's excepted types are annotated in the code.

The error message I get is on line 8, stating Error: Syntax error: operator expected.

I suspect that knowing the functionality of the code is irelevant, but here it is nevertheless:

isEpsilon is a function that returns true if the transition matches None.

NFAError is an user defined error.

The user defined types are:

type char option = None | Some of char
type transition = int * char option * int
type nfa_t = int * int list * transition list

An example of each type in the order listed above:

None
(1, None, 2)
(1, [2;3], [(1, None, 2); (1, Some 'a', 3)])

An example of using the function e_closure:

e_closure (1, [2,3], [(1, None, 2); (1, Some 'a', 3)]) [1] = [1;2]

That is, the function looks at the list [(1, None, 2); (1, Some 'a', 3)], returns an int list containing every element in its second parameter and every epsilon transition of all the elements of that parameter. In this case, since the second parameter is [1], it will return [1;2], the transition (1, Some 'a', 3) is not an epsilon transition, so it's not included.

The code uses the function fold_left and sort_uniq found in Ocaml's native module List.

1
  • Note the coloring of end in the syntax highlighting. Commented Mar 30, 2017 at 11:09

1 Answer 1

2

You're using end as an identifier but it is a keyword in OCaml.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, I'm not even shocked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.