From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id CCF2FBBC1 for ; Fri, 14 Mar 2008 16:01:31 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtwAAIgw2kdA6bjlkmdsb2JhbACRAAEBAQEHBAQJChaRIYZz X-IronPort-AV: E=Sophos;i="4.25,501,1199660400"; d="scan'208";a="23774864" Received: from wr-out-0506.google.com ([64.233.184.229]) by mail4-smtp-sop.national.inria.fr with ESMTP; 14 Mar 2008 16:01:31 +0100 Received: by wr-out-0506.google.com with SMTP id c30so2975034wra.21 for ; Fri, 14 Mar 2008 08:01:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:x-enigmail-version:content-type:content-transfer-encoding; bh=2FhLsWrcOBZZhxZZFWkEz+iH0oFoZUYMH7Sb2MR1Tx4=; b=c0FmSM7Vv+N+l4yAeY1BdUBok/Dljx10GQ/NfbGCLQJ31KHo52A0m7QHB8JaIV4b/SWG29CAEo02S+eAMjpw0FcipI1aYQrskfTfQOwf9jZZKmyU25wUNkT0ZDxaj985HXZGbTHyhY7TS7yDofYD33tpn+rwyc+IiDvXc1jDHnA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:x-enigmail-version:content-type:content-transfer-encoding; b=A6GFENSifCllFkqrdJ/fAiHYb5Em2uk9jxhQk8B7AyPOkKoiNu7w3H0I1k2YV8uyCeuCDAnpwTKTgYwMuv2xUUhZQUwGmKIxHTMOv9Qv9j9BN+irtJcEdqWo1e2RP2qjcMc7IZjh9/Xd7jp8nfOstuMgPgrzxxLeIKseyv3fg1Q= Received: by 10.140.144.4 with SMTP id r4mr6596801rvd.15.1205506889080; Fri, 14 Mar 2008 08:01:29 -0700 (PDT) Received: from ?192.168.0.10? ( [80.104.113.181]) by mx.google.com with ESMTPS id a38sm60294rnc.4.2008.03.14.08.01.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 14 Mar 2008 08:01:24 -0700 (PDT) Message-ID: <47DA9322.9000606@gmail.com> Date: Fri, 14 Mar 2008 16:00:50 +0100 From: patrik osgnach User-Agent: Thunderbird 2.0.0.12 (X11/20080308) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: ocamlyacc and empty objects X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ocamlyacc:01 ocamlyacc:01 mll:01 'a'-'z':01 'a'-'z':01 sig:01 lexbuf:01 sig:01 printf:01 lexing:01 struct:01 val:01 mutable:01 arity:01 arity:01 Hi, I'm doing some experiments with ocamlyacc and ocamlex. these are the sources lex.mll ------------------------ { open String open Par let rec string2list str = match str with | "" -> [] | _ -> try (let pos = index str ',' in (sub str 0 pos)::(string2list (sub str (pos+1) ((length str)-(pos+1))))) with Not_found -> str::[] ;; } let num = ['0'-'9'] | ['1'-'9']['0'-'9']+ let name = ['a'-'z']['a'-'z' 'A'-'W' 'Y'-'Z' '0'-'9']* let sigtype = "active" | "passive" | "atomic" let sigelem = sigtype ' ' name ':' num let sigset = '[' sigelem (',' sigelem)* ']' let Sig = "Signature " sigset ';' rule token = parse | [' ' '\t'] { token lexbuf } | '\n' { NEWLINE } | Sig as snl { SIGNATURE (string2list(sub snl (index snl '['+1) (index snl ']'- index snl '[' -1 ))) } | name as nm { NAME(nm) } | eof { NEWLINE } ------------------ par.mly ------------------ %{ open Printf open Lexing open String type sigdata = string*string*int module Signature = struct type t = string * int let compare (sig1, n1) (sig2, n2) = if sig1 < sig2 then - 1 else if sig1 > sig2 then 1 else 0 end;; module SignatureSet = Set.Make(Signature);; class signatures = object (self) val mutable s = SignatureSet.empty method addsign sign n = s <- SignatureSet.add (sign, n) s method removesign sign = s <- SignatureSet.remove (sign, 0) s method arity (sign : string) = List.assoc sign (SignatureSet.elements s) method getsigns = SignatureSet.elements s end;; let sign = new signatures;; let rec signaturedata data = match data with | [] -> [] | head::tail -> (sub head 0 (index head ' '),sub head (index head ' ' +1) (index head ':' - index head ' ' -1), int_of_string (sub head (index head ':' +1) (length head - index head ':' -1)))::signaturedata tail ;; let rec makeSigSet data = match data with | [] -> () | (t, n, a)::tail -> sign#addsign n a; makeSigSet tail ;; %} %token SIGNATURE %token NAME %token NEWLINE %start boh %type boh %% boh: SIGNATURE NEWLINE bg NEWLINE{ makeSigSet (signaturedata $1);string_of_int (sign#arity "server") ^ $3} ; bg: | NAME {(*string_of_int (sign#arity "server")*) "a" } ; ------------------- there is also a simple main module which reads from a file and starts the parser. this is the source file ----------------- Signature [active server:2]; blablabla ----------------- sing is a simple set of string*int pairs and it contains only the pair ("server", 2). my problem is: the first time I call getsigns method (after boh:) I get a "2" (which is correct), second time (under bg:) I get a Not_found exception. Do you know why? thanks for help patrik (sorry for my bad english)