caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Joel Christner <joel.christner@gmail.com>
To: caml-list <caml-list@yquem.inria.fr>,
	Joel Christner <joel.christner@gmail.com>
Subject: Toplevel function question
Date: Wed, 13 May 2009 16:43:07 -0700	[thread overview]
Message-ID: <9da743ed0905131643t98cd36co1f00498434be3c3c@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1670 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1968 bytes --]

             reply	other threads:[~2009-05-13 23:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-13 23:43 Joel Christner [this message]
2009-05-14  0:10 ` Joel Christner
2009-05-14  5:25   ` RE : [Caml-list] " MONATE Benjamin 205998
2009-05-14  7:52   ` Gregory BELLIER
2009-05-14 10:23   ` Cedric Auger
2009-05-14 10:29     ` Cedric Auger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9da743ed0905131643t98cd36co1f00498434be3c3c@mail.gmail.com \
    --to=joel.christner@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).