Ocaml Syntax Error Else
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring
Ocaml Syntax Error Pattern Expected
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask ocaml syntax error operator expected Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join syntax error on else if them; it only takes a minute: Sign up OCaml “else” Syntax error up vote 2 down vote favorite I'm learning OCaml for the first time, and I am having a bit of trouble with an extraordinarily vague "Syntax error".
Syntax Error On Else Token
When defining the function generateboxes like so: let rec generateboxes a b = if a = (add1 b) then (force_newline ()); (print_sting "Done!") else if [1] = (Array.get finalarray a) then (populatebox (numbertoposition a) a); (generateboxes (add1 a) b) else (generateboxes (add1 a) b);; The complier gives the error message: "Syntax error" and it points to the first else. Is there anything glaringly wrong with my code for it to output such a message? (I realize the code is
Syntax Error On Else Delete This Token
out of context, but if its a syntax error then it shouldn't matter). ocaml syntax-error if-statement share|improve this question edited Nov 1 '12 at 10:22 Pascal Cuoq 58.6k5101194 asked Oct 28 '12 at 18:52 RJ Antonello 558 2 I recommend you put no more than one "thing" per line and use a text editor that performs automatic indentation. Emacs with caml-mode, tuareg-mode or typerex is great for that. All you have to do is press the tab key once to indent the current line properly. That would have explained your syntax error right away. –Martin Jambon Oct 29 '12 at 0:06 add a comment| 1 Answer 1 active oldest votes up vote 6 down vote accepted let rec generateboxes a b = if a = add1 b then (force_newline (); print_sting "Done!") else if [1] = Array.get finalarray a then (populatebox (numbertoposition a) a; generateboxes (add1 a) b) else generateboxes (add1 a) b;; If you have more than one statement in a then or an else clause, you need to put them inside parentheses. Alternatively, you can put begin ... end around them: let rec generateboxes a b = if a = add1 b then begin force_newline (); print_sting "Done!" end else if [1] = Array.get finalarray a then begin populatebox (numbertoposition a) a; generateboxes (add1 a) b end else generateboxes (add1 a) b;; (Note that I have also removed a few unnecessary parent
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn syntax error on else delete this token java more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users
Syntax Error Else Unexpected
Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping syntax error else python each other. Join them; it only takes a minute: Sign up Ocaml: Syntax Error up vote 1 down vote favorite I'm trying to figure out why this is not working, I get Error: Syntax Error. Did I miss http://stackoverflow.com/questions/13111913/ocaml-else-syntax-error a ";" somewhere ? let way_tags_to_hashtbl way = let hashtbl = Hashtbl.create 1 in let rec way_tags_to_hashtbl_partial list = match list with | a::list' -> Hashtbl.add hashtbl (a.k, a.v); way_tags_to_hashtbl_partial list' | a::[] -> Hashtbl.add hashtbl (a.k, a.v) | [] -> []; way_tags_to_hashtbl_partial way.wtag; hashtbl ;; <------ ERROR HERE Thank you. ocaml share|improve this question asked Jan 3 '12 at 16:09 Jane 5726 1 p.s. let rec way_tags_to_hashtbl_partial list = match list with can be http://stackoverflow.com/questions/8715044/ocaml-syntax-error written as let rec way_tags_to_hashtbl_partial = function –newacct Jan 4 '12 at 3:44 p.p.s the a::[] case will never be reached, because a::list' already covers it –newacct Jan 4 '12 at 3:45 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted I think you're missing an in about two lines up: let way_tags_to_hashtbl way = let hashtbl = Hashtbl.create 1 in let rec way_tags_to_hashtbl_partial list = match list with | a::list' -> Hashtbl.add hashtbl (a.k, a.v); way_tags_to_hashtbl_partial list' | a::[] -> Hashtbl.add hashtbl (a.k, a.v) | [] -> [] in (* !!! HERE !!! *) way_tags_to_hashtbl_partial way.wtag; hashtbl ;; I don't have ocaml installed on this machine, can't check... share|improve this answer answered Jan 3 '12 at 16:12 Amadan 91.6k885133 Thank you it works ! you're awesome. –Jane Jan 3 '12 at 16:25 @amadan : if you want to check some ocaml code, you can use the [online toplevel][1], you don't need to install anything. [1]: try.ocamlpro.com –cago Jan 30 '12 at 12:46 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy a
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn http://stackoverflow.com/questions/2507770/syntax-error-beyond-end-of-program more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Syntax error beyond end of program up vote 3 syntax error down vote favorite 1 I am experimenting with writing a toy compiler in ocaml. Currently, I am trying to implement the offside rule for my lexer. However, I am having some trouble with the ocaml syntax (the compiler errors are extremely un-informative). The code below (33 lines of it) causes an error on line 34, beyond the end of the source code. I am unsure what is causing syntax error on this error. open Printf let s = (Stack.create():int Stack.t); let rec check x = ( if Stack.is_empty s then Stack.push x s else if Stack.top s < x then ( Stack.push x s; printf "INDENT\n"; ) else if Stack.top s > x then ( printf "DEDENT\n"; Stack.pop s; check x; ) else printf "MATCHED\n"; ); let main () = ( check 0; check 4; check 6; check 8; check 5; ); let _ = Printexc.print main () Ocaml output: File "lexer.ml", line 34, characters 0-0: Error: Syntax error Can someone help me work out what the error is caused by and help me on my way to fixing it? ocaml share|improve this question asked Mar 24 '10 at 12:57 a_m0d 6,766114071 add a comment| 2 Answers 2 active oldest votes up vote 8 down vote accepted The trailing ; after the definitions of main, check and s are erroneous. Replace these 3 occurences with ;; as follows: let s = (Stack.create():int Stack.t);; let rec check x = ( (* ...sequence of imperative statements... *) );; let main () = ( (* ...sequence of imperative statements... *) );; ; is used in the following cases: to sequence imperative statements as a se