Thanks.
Just for the record, in case anyone hits this thread at a later date,
Lsymbol is defined all the way back in Chapter 6 of the book. Chapter 11
shows the code to parse via camlp4 instead of manually. Although it
mentions that the BASIC interpreter from Chaper 6 will be re-implemented, it
doesn't explicitly note the defs are needed before the code snippet listed
below is presented.
-Grant
_____
From: ocaml_beginners%40yahoogroups.com">ocaml_beginners
yahoogroups.com
[mailto: ocaml_beginners%40yahoogroups.com">ocaml_beginners
yahoogroups.com] On Behalf Of Jonathan Roewen
Sent: Sunday, January 28, 2007 3:24 PM
To: ocaml_beginners%40yahoogroups.com">ocaml_beginners
yahoogroups.com
Subject: Re: "ocaml_beginners"::[] match ... with parser syntax?
I don't see any statements opening a module which may define the type
constructor Lsymobl =P
I assume it's something like type t = Lsymbol of string | Lint of int ...
For instance, if this were in a module, say, types.ml, that's been
compiled already, then you need an 'open Types' statement (this brings
symbols in the named module into scope).
In the toplevel, you can also use the directive #use "filename";;
where filename is path to an ocaml source file. This does textual
inclusion, and the code is evaluated by the toplevel, results printed,
and bindings created.
Jonathan
On 1/29/07, Grant Olson <olsongt
verizon. <mailto:olsongt%40verizon.net>
net> wrote:
> Thanks.
>
>
>
> Okay, I'm starting the interpreter with "ocaml -I +camlp4 camlp4o.cma"
This
> gets me a little further but now I get the following error:
>
>
>
> Objective Caml version 3.09.0
>
>
>
> Camlp4 Parsing version 3.09.0
>
>
>
> # let rec spaces s =
>
> match s with parser
>
> [<'' ' ; rest >] -> spaces rest
>
> | [<''t' ; rest >] -> spaces rest
>
> | [<''n' ; rest >] -> spaces rest
>
> | [<>] -> ();;
>
> val spaces : char Stream.t -> unit = <fun>
>
> # let rec lexer s =
>
> spaces s;
>
> match s with parser
>
> [< ''(' >] -> [< 'Lsymbol "(" ; lexer s >]
>
> | [< '')' >] -> [< 'Lsymbol ")" ; lexer s >]
>
> | [< ''+' >] -> [< 'Lsymbol "+" ; lexer s >]
>
> | [< ''-' >] -> [< 'Lsymbol "-" ; lexer s >]
>
> | [< ''*' >] -> [< 'Lsymbol "*" ; lexer s >]
>
> | [< ''/' >] -> [< 'Lsymbol "/" ; lexer s >]
>
> | [< ''0'..'9' as c;
>
> i,v = lexint (Char.code c - Char.code('0')) >]
>
> -> [<'Lint i ; lexer v>]
>
> and lexint r s =
>
> match s with parser
>
> [< ''0'..'9' as c >]
>
> -> let u = (Char.code c) - (Char.code '0') in lexint (10*r + u) s
>
> | [<>] -> r,s;;
>
> Characters 78-89:
>
> [< ''(' >] -> [< 'Lsymbol "(" ; lexer s >]
>
> ^^^^^^^^^^^
>
> Unbound constructor Lsymbol
>
> #
>
>
>
> _____
>
> From: ocaml_beginners
<mailto:ocaml_beginners%40yahoogroups.com>
yahoogroups.com
> [mailto:ocaml_beginners
<mailto:ocaml_beginners%40yahoogroups.com>
yahoogroups.com] On Behalf Of Jonathan Roewen
> Sent: Wednesday, January 24, 2007 7:53 PM
> To: ocaml_beginners
<mailto:ocaml_beginners%40yahoogroups.com>
yahoogroups.com
> Subject: Re: "ocaml_beginners"::[] match ... with parser syntax?
>
>
>
> Need to load/compile with camlp4o.cma. Parser syntax is no longer
> enabled by default.
>
> On 1/25/07, Grant Olson <olsongt
verizon. <mailto:olsongt%40verizon.net>
> net> wrote:
> > I'm working through the translation of the O'Reilly book, and I'm
> currently
> > at the chapter on lexing and parsing. The code from the following
section
> > doesn't seem to work for me:
> >
> > http://caml.
> <http://caml.
<fonctions">http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora105.html#
fonctions
> inria.fr/pub/docs/oreilly-book/html/book-ora105.html#
fonctions
> 3> inria.fr/pub/docs/oreilly-book/html/book-ora105.html#
fonctions3
> > 50
> >
> > I've tried both typing it in manually, and cut-n-pasting from the html.
> Has
> > the syntax changed in ocaml 3.0? Did latex botch something, like showing
a
> > single tick instead of a backtick? Or am I just doing something stupid
on
> my
> > system?
> >
> > I'm evaluating with M-C-x in tuareg-mode if that makes a difference.
> >
> > Any help or pointers to reference materials would be appreciated,
> >
> > Grant
> >
> >
> >
> > Archives up to November 11, 2006 are also downloadable at
> http://www.connetti <http://www.connetti
<http://www.connettivo.net/cntprojec