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=3.8 required=5.0 tests=DNS_FROM_RFC_POST,HTML_10_20, HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 0F025BC37 for ; Thu, 14 May 2009 01:43:10 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuUCAKf3CkrRVcipimdsb2JhbACCITKUBT8BAQEKCQwHDwWmHIESj3gBAwEDg38F X-IronPort-AV: E=Sophos;i="4.41,191,1241388000"; d="scan'208";a="39930503" Received: from wf-out-1314.google.com ([209.85.200.169]) by mail4-smtp-sop.national.inria.fr with ESMTP; 14 May 2009 01:43:09 +0200 Received: by wf-out-1314.google.com with SMTP id 24so565288wfg.15 for ; Wed, 13 May 2009 16:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=873EE/bNnNO5c/jNZ+1xIqKCd1DaxKk/fi0b0fk4qk0=; b=Mp73uD7GpwAIaSIJlIeTLYFFOAfcrzJJGJB6nZriJQ3mEtofdxC0uzgwEbkNHgJuYi tJxiHoSXA4D7y4HzJ7+BUHKglZbmuoHIaxnoIp0DSspUD1/w8V864mS/3F9HkZc07Ifr dkn9PbGxnbEZpvjOTnUcpnmjItH3jyDNRpBP0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=N5Kfdm7/lHLMd/pGqrhqA0zmgri+oE8CiH41Ez7xC6TFfiBY0vzeSt1fmtq3941VLM SECk0DV1v6TqkKHFf4nJpQ0+kitC6LOJ0nL+EuUVV/cwvZWUslfWIir9DKfrAsoeth12 Mb6t9B9bevTDJUstTpDK5z00NUqS5EWT2vcW4= MIME-Version: 1.0 Received: by 10.142.200.20 with SMTP id x20mr531248wff.192.1242258187759; Wed, 13 May 2009 16:43:07 -0700 (PDT) Date: Wed, 13 May 2009 16:43:07 -0700 Message-ID: <9da743ed0905131643t98cd36co1f00498434be3c3c@mail.gmail.com> Subject: Toplevel function question From: Joel Christner To: caml-list , Joel Christner Content-Type: multipart/alternative; boundary=000e0cd1490a0032b20469d3c69b X-Spam: no; 0.00; toplevel:01 beginner's:01 beginner's:01 toplevel:01 stdin:01 lexbuf:01 lexing:01 stdin:01 expr:01 parser:01 expr:01 lexbuf:01 iter:01 parser:01 syntax:01 --000e0cd1490a0032b20469d3c69b Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hello, I hope you guys don't mind another beginner's question, I'm waiting on approval from the Yahoo! group moderator for the beginner's section. I'm trying to implement a toplevel function that will accept input from stdin (someone running the program will do ./programname < someinputfile), store it to a ref string list, and then once stored, iteratively evaluate each item in the list individually. What I've put together is: let _ = let lexbuf = Lexing.from_channel stdin in let rec storeoriginalprogram = let expr = Parser.expr Scanner.token lexbuf in match expr with | EOF -> () | _ -> add_text originalprogramcontents expr; storeoriginalprogram in let parseprogram = List.iter (fun n -> eval expr) originalprogramcontents where... - Parser and Scanner are already built and working great - When a line of text comes in, it calls 'add_text' which adds the expr into the 'originalprogramcontents' ref string list, and then recursively calls itself to get the next line - let originalprogramcontents = ref [""] - let add_text variablelist text = variablelist.contents <- text::variablelist.contents - Then when finished reading from stdin, iteratively executes 'eval' against each line in the ref string list called 'originalprogramcontents' For some reason (probably a stupid mistake on my part) it's giving me a syntax error and pointing to a line of code that is AFTER the end of my program: $ make ocamlc -c program.ml File "program.ml", line 203, characters 2-2: Syntax error make: *** [program.cmo] Error 2 But my program is only 202 lines long. Any ideas on how I might go about making this work? Thanks Joel --000e0cd1490a0032b20469d3c69b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello,

I hope you guys don't mind another beginner's questio= n, I'm waiting on approval from the Yahoo! group moderator for the begi= nner's section.

I'm trying to implement a toplevel function = that will accept input from stdin (someone running the program will do ./pr= ogramname < someinputfile), store it to a ref string list, and then once= stored, iteratively evaluate each item in the list individually.

What I've put together is:

let _ =3D
=A0 let lexbuf =3D = Lexing.from_channel stdin in
=A0 let rec storeoriginalprogram =3D
=A0= =A0=A0 let expr =3D Parser.expr Scanner.token lexbuf in
=A0=A0=A0 match = expr with
=A0=A0=A0 | EOF=A0=A0 -> ()
=A0=A0=A0 | _=A0=A0=A0=A0 -> add_text originalprogramcontents expr; stor= eoriginalprogram
=A0 in let parseprogram =3D List.iter
=A0=A0=A0 (fu= n n -> eval expr) originalprogramcontents

where...
- Parser an= d Scanner are already built and working great
- When a line of text comes in, it calls 'add_text' which adds the = expr into the 'originalprogramcontents' ref string list, and then r= ecursively calls itself to get the next line
=A0=A0 - let originalprogra= mcontents =3D ref [""]
=A0=A0 - let add_text variablelist text =3D variablelist.contents <- tex= t::variablelist.contents
- Then when finished reading from stdin, iterat= ively executes 'eval' against each line in the ref string list call= ed 'originalprogramcontents'

For some reason (probably a stupid mistake on my part) it's giving = me a syntax error and pointing to a line of code that is AFTER the end of m= y program:

$ make
ocamlc -c program= .ml
File "program.ml", line 203, ch= aracters 2-2:
Syntax error
make: *** [program.cmo] Error 2

But= my program is only 202 lines long.

Any ideas on how I might go abou= t making this work?

Thanks
Joel

--000e0cd1490a0032b20469d3c69b--