From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA03693; Sat, 3 Apr 2004 15:57:35 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA03463 for ; Sat, 3 Apr 2004 15:57:34 +0200 (MET DST) Received: from oceanite.ens-lyon.fr (oceanite.ens-lyon.fr [140.77.1.22]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i33DvXYM003362 for ; Sat, 3 Apr 2004 15:57:33 +0200 Received: from localhost (oceanite.ens-lyon.fr [127.0.0.1]) by oceanite.ens-lyon.fr (Postfix) with ESMTP id A6054320221 for ; Sat, 3 Apr 2004 15:57:20 +0200 (CEST) Received: from oceanite.ens-lyon.fr ([127.0.0.1]) by localhost (oceanite [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 17397-10 for ; Sat, 3 Apr 2004 15:57:20 +0200 (CEST) Received: from sparshong.is-a-geek.org (unknown [140.77.129.104]) by oceanite.ens-lyon.fr (Postfix) with SMTP id 650593200D5 for ; Sat, 3 Apr 2004 15:57:20 +0200 (CEST) Date: Sat, 3 Apr 2004 15:56:08 +0200 From: Florent Bouchez To: caml-list@pauillac.inria.fr Subject: [Caml-list] segmentation fault at parsing Message-Id: <20040403155608.20f26120@sparshong.is-a-geek.org> X-Mailer: Sylpheed version 0.9.9claws (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at ens-lyon.fr X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; ens-lyon:01 re-raise:01 re-raise:01 3.07:01 printf:01 eprintf:01 printf:01 eprintf:01 stderr:01 ocamlc:01 mli:01 ocamlc:01 foo:01 bin:01 cmo:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 48 Hi, I have a problem in using the error recovery mode of ocamlyacc: the dummy parser included here reads from "integer.input" a list of integers, defined like this: "integer 42". I want the user to know his error: error in integer writing or else, but the parsing must continue. But, where I catch the corresponding error token, in the rule Int, the rule must return (int * int), and I don't want to return an arbitrary value that would be kept. Instead I prefer to re-raise a Parsing.Parse_error, so that the preceding rule can discard this attempt. The problem is than the Exception is quit of ignored : the "Int:" rule returns something of value 0 => if the rule returns something of type "int" instead of "int * int", there is a 0 in the integer list. But if the type is a more complicated type, then something horrible happens and I get a "zsh: segmentation fault ./test". Is it forbidden to re-raise a Parse_error in the action part of a rule that matches the symbol "error" ? I use "Objective Caml version 3.07+2" Here are the sources --------- parser.mly, the most important : %token EOF %token INTEGER %token INT %token WORD %start main %type <(int*int) list> main %% main: | IntList EOF { $1 } ; ; IntList: | IntList Int { $2 :: $1 } | Int { [$1] } | error { Printf.eprintf "---- Some error\n" ; [] } ; Int: | INTEGER INT { $2,$2 } | INTEGER error { Printf.eprintf "++++ This is not an integer\n" ; raise Parsing.Parse_error } ; -------------- lexer.mll: { open Parser } rule token = parse | [' ' '\t' '\n'] { token lexbuf } | '#' { comment lexbuf } | "integer" { INTEGER } | ['0'-'9']+ as i { INT (int_of_string i) } | ['a'-'z']+ as w { WORD w } | eof { EOF } and comment = parse | '\n' {token lexbuf } | _ {comment lexbuf } ------------ test.ml, the main program: open Lexer open Parser let _ = let fd = open_in_bin "integer.input" in let lexbuf = Lexing.from_channel fd in try let l = Parser.main Lexer.token lexbuf in flush stderr ; print_string "Parsing done:\n" ; List.iter (fun (a,b) -> print_int a ; print_string "\n" ) l ; print_string "[]\n" ; with e -> Printf.eprintf "Exception !\n" ; raise e -------- Makefile: all: ocamllex lexer.mll ocamlyacc -v parser.mly ocamlc -g -c parser.mli ocamlc -g -c lexer.ml ocamlc -g -c parser.ml ocamlc -g -c test.ml ocamlc -g -o test lexer.cmo parser.cmo test.cmo --------- integer.input: integer 1 foo integer 3 integer 4 # if you put an '#' at the beginning of the following line, it's OK integer bar integer 2 integer 5 Thanks Florent Bouchez ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners