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.3 required=5.0 tests=AWL,DNS_FROM_RFC_POST, 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 0E9F0BC37 for ; Thu, 14 May 2009 02:11:00 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjgBAK/+CkrRVcitimdsb2JhbACCU5QFPwEBAQoJDAcPBaYEgRKPeQEDAQODfwU X-IronPort-AV: E=Sophos;i="4.41,191,1241388000"; d="scan'208";a="39931173" Received: from wf-out-1314.google.com ([209.85.200.173]) by mail4-smtp-sop.national.inria.fr with ESMTP; 14 May 2009 02:10:59 +0200 Received: by wf-out-1314.google.com with SMTP id 24so569491wfg.15 for ; Wed, 13 May 2009 17:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=nc/E+RPey7Yc66BqD/dl/oeo//PgDgmNIFwkiyRzQI8=; b=F1EJoscqRumtDd5cO+sFiieNe/FCZicugtJe8Zt9wjG1XPxUz0yYHQqSvjTS/NPpPZ 6RpIb8lshaySWKvbmmmK4vId5dQaltD1wSWkxgyHOm8TbcG1rPRpIfUq37Rtdw1Z2Mrn b26QQNBdthm/esvJBbkexJYIG+uAjeHVq8Yy0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=fi6zaOGknbvXVGkHG8wu1vVvnFfJOeAUmU7mBDsBT58hj5fpChKDfeYtlIM983+NK1 TZRJNr15ATiLwo6aMIVAVnpmB42gyGKGDcsgIbqOztPGWowH5KcLO7kjaVzp1atocRs1 B2LlqTS2rer9/jeaFZfq+fLeqQre24FO75h4Y= MIME-Version: 1.0 Received: by 10.142.185.21 with SMTP id i21mr581765wff.311.1242259857340; Wed, 13 May 2009 17:10:57 -0700 (PDT) In-Reply-To: <9da743ed0905131643t98cd36co1f00498434be3c3c@mail.gmail.com> References: <9da743ed0905131643t98cd36co1f00498434be3c3c@mail.gmail.com> Date: Wed, 13 May 2009 17:10:57 -0700 Message-ID: <9da743ed0905131710w5563de39i60f1d60c071ff515@mail.gmail.com> Subject: Re: Toplevel function question From: Joel Christner To: caml-list , Joel Christner Content-Type: multipart/alternative; boundary=000e0cd215b883fb080469d4295c X-Spam: no; 0.00; toplevel:01 syntax:01 lexbuf:01 lexing:01 stdin:01 expr:01 lexbuf:01 expr:01 iter:01 ocamlc:01 toplevel:01 syntax:01 beginner's:01 beginner's:01 stdin:01 --000e0cd215b883fb080469d4295c Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Simpler representation - tried compiling this and got the same syntax error - at a line number that was after the EOF. Thanks in advance for any help!! let add_text variablelist text = variablelist.contents <- text::variablelist.contents let originalprogramcontents = ref [""] let _ = let lexbuf = Lexing.from_channel stdin in let rec storeoriginalprogram = let expr = lexbuf in match expr with | EOF -> () | _ -> (add_text originalprogramcontents expr); storeoriginalprogram in let parseprogram = List.iter (fun n -> print_string n; print_string "\n";) originalprogramcontents $ ocamlc -c toplevel.ml File "toplevel.ml", line 17, characters 1-1: Syntax error On Wed, May 13, 2009 at 4:43 PM, Joel Christner wrote: > 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 > > --000e0cd215b883fb080469d4295c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Simpler representation - tried compiling this and got the same syntax error= - at a line number that was after the EOF.=A0 Thanks in advance for any he= lp!!

let add_text variablelist text =3D
=A0 variablelist.contents= <- text::variablelist.contents

let originalprogramcontents =3D ref [""]

let _ =3D =A0 let lexbuf =3D Lexing.from_channel stdin in
=A0 let rec storeorigin= alprogram =3D
=A0=A0=A0 let expr =3D lexbuf in
=A0=A0=A0 match expr w= ith
=A0=A0=A0 | EOF=A0=A0 -> ()
=A0=A0=A0 | _=A0=A0=A0=A0 -> (add_text originalprogramcontents expr); st= oreoriginalprogram
=A0 in let parseprogram =3D List.iter
=A0=A0=A0 (= fun n -> print_string n; print_string "\n";) originalprogramco= ntents

$ ocamlc -c toplevel.ml File "toplevel.ml", line 17, c= haracters 1-1:
Syntax error

=A0=A0=A0


On Wed, May 13, 2009 at 4:43 PM, Joel Christner <joel.christner@gmail.com= > wrote:
Hello,

I h= ope you guys don't mind another beginner's question, I'm waitin= g on approval from the Yahoo! group moderator for the beginner's sectio= n.

I'm trying to implement a toplevel function that will accept input = from stdin (someone running the program will do ./programname < someinpu= tfile), store it to a ref string list, and then once stored, iteratively ev= aluate 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&q= uot;, line 203, characters 2-2:
Syntax error
make: *** [program.cmo] = Error 2

But my program is only 202 lines long.

Any ideas on h= ow I might go about making this work?

Thanks
Joel


--000e0cd215b883fb080469d4295c--