caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] parsing OCaml code
@ 2005-07-19 17:05 Nathaniel J. Gaylinn
  2005-07-19 19:12 ` Eric Cooper
  2005-07-19 19:20 ` Sylvain LE GALL
  0 siblings, 2 replies; 3+ messages in thread
From: Nathaniel J. Gaylinn @ 2005-07-19 17:05 UTC (permalink / raw)
  To: OCaml Mailing List


I'm trying to figure out a nice way to parse OCaml code in a C++ program. 
All I need is a very basic parse tree for use in syntax highlighting and 
indenting OCaml code.

I would love to make use of some of the programs that already come with 
OCaml. For instance, ocamlc and camlp4 can both output OCaml parse trees 
already! The only problem is the formats that these programs output are 
(to my knowledge) completely undocumented.

If I don't use these programs, I could always try using Lex and Yacc to do 
the job, but I'm completely unfamiliar with these utilities and it would 
take me quite some time to write input for parsing OCaml.

Does anyone know where I could find reference to the various OCaml parse 
tree formats? Does anyone know where I could find Yacc grammar 
descriptions of OCaml, or would I have to write them myself? Does anyone 
have any other suggestions of how to tackle the parsing problem?

Thanks,

   -- Nate Gaylinn


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] parsing OCaml code
  2005-07-19 17:05 [Caml-list] parsing OCaml code Nathaniel J. Gaylinn
@ 2005-07-19 19:12 ` Eric Cooper
  2005-07-19 19:20 ` Sylvain LE GALL
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Cooper @ 2005-07-19 19:12 UTC (permalink / raw)
  To: caml-list

On Tue, Jul 19, 2005 at 01:05:58PM -0400, Nathaniel J. Gaylinn wrote:
> Does anyone know where I could find Yacc grammar descriptions of
> OCaml, or would I have to write them myself?

OCaml uses ocamlyacc and ocamllex for its front-end: see
.../parsing/parser.mly and lexer.mll.

ocamlyacc is very similar to yacc/bison; reuse of the grammar should
be straightforward.

ocamllex is similar to lex/flex, but it supports mutually recursive
rules instead of lex's explicit "start conditions", so you might have
a bit more work if you want to translate it.

-- 
Eric Cooper             e c c @ c m u . e d u


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] parsing OCaml code
  2005-07-19 17:05 [Caml-list] parsing OCaml code Nathaniel J. Gaylinn
  2005-07-19 19:12 ` Eric Cooper
@ 2005-07-19 19:20 ` Sylvain LE GALL
  1 sibling, 0 replies; 3+ messages in thread
From: Sylvain LE GALL @ 2005-07-19 19:20 UTC (permalink / raw)
  To: Nathaniel J. Gaylinn; +Cc: OCaml Mailing List

Hello,

On Tue, Jul 19, 2005 at 01:05:58PM -0400, Nathaniel J. Gaylinn wrote:
> 
> I'm trying to figure out a nice way to parse OCaml code in a C++ program. 
> All I need is a very basic parse tree for use in syntax highlighting and 
> indenting OCaml code.
> 
> I would love to make use of some of the programs that already come with 
> OCaml. For instance, ocamlc and camlp4 can both output OCaml parse trees 
> already! The only problem is the formats that these programs output are 
> (to my knowledge) completely undocumented.
> 
> If I don't use these programs, I could always try using Lex and Yacc to do 
> the job, but I'm completely unfamiliar with these utilities and it would 
> take me quite some time to write input for parsing OCaml.
> 
> Does anyone know where I could find reference to the various OCaml parse 
> tree formats? Does anyone know where I could find Yacc grammar 
> descriptions of OCaml, or would I have to write them myself? Does anyone 
> have any other suggestions of how to tackle the parsing problem?
> 

You should have a look to ocaml-ast-analyze
(http://www.carva.org/sylvain.le-gall/ocaml-ast-analyze.html). It is a
module build around camlp4 which can overridde the output of camlp4 (ie
it can replace pr_dump.cmo for example).

I use it to analyze ocaml code in order to find functions (which are
"s_", "f_"... ) followed by a string (s_ 'Coucou') and output only the
string ("msgstrid 'Coucou').

I think it is very useful to do analysis on Ocaml AST.

There is no documentation, but i am planning to write some.

Kind regard
Sylvain Le Gall


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-07-19 19:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-19 17:05 [Caml-list] parsing OCaml code Nathaniel J. Gaylinn
2005-07-19 19:12 ` Eric Cooper
2005-07-19 19:20 ` Sylvain LE GALL

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).