caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pietro Abate <Pietro.Abate@anu.edu.au>
To: ocaml ml <caml-list@inria.fr>
Subject: parsing problem.
Date: Wed, 24 Jan 2007 10:59:40 +1100	[thread overview]
Message-ID: <20070123235940.GA32163@pulp.rsise.anu.edu.au> (raw)

hi all,
I've a file that is composed of two parts: a language specification and
a program that is written using the language specified in the first
part. My goal is to parse the language spec, create a parser that uses
this language, parse the rest of the file and output ocaml code (this
should be a preprocessor).

At the moment I'm using camlp4 to read the language specification,
extend a simple fixed grammar on the fly and to parse the rest of the
file using the grammar that I've extended with the language
specification. For example if my fix grammar is a simple generic
calculator language and I want to add more operators to the language
I'll write something along these lines:

_+_ , 2
_*_ , 1
-_  , 0

and then then the second part of the file will look like

1 + 2 * -3 

and I expect that this line will be parsed accordingly to the operators
declared at the beginning.

Obviously this approach is not going to take me very far way. In the
moment I need to specify a different grammar (say to write equations)
I've to change the parser in the preprocessor.

What I really want is to write the grammar and lexer specification in
the first part of my file and then use a parser generator to create a
parser to interpret the second part of the file. The catch is that I'd
like to do it in one pass. Using Lex/Yacc technology this is not
possible (I think) as you need to write two input files in order to
generate a parser library. I'm wondering if this is possible using a
generic parser combinators library.

The idea would be to link a generic parser library and bootstrap my
custom parser by feeding it with the grammar specification and then use
this parser within or together with camlp4 to parse the rest of the
file.

The result of this pre-processing step should be ocaml code that I'll
just need to compile.
input -> campl4 extension + generic parser library -> ocaml code

Is there a (small !) library to achieve this ?

I had a quick look at 

Ocfgc (http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=492) can it be
used in this way ? 

Ostap
(http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=513) seems also promising, 
but I'm not sure if it is possible to plug it in this way.

ulex ? menhir ?  dypgen ?

thanks :)
pietro

-- 
++ Blog: http://blog.rsise.anu.edu.au/?q=pietro
++ 
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
   See http://www.fsf.org/philosophy/no-word-attachments.html


             reply	other threads:[~2007-01-23 23:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-23 23:59 Pietro Abate [this message]
2007-01-24 21:53 ` using camlp4 api [WAS: Re: [Caml-list] parsing problem.] Pietro Abate
2007-01-24 22:37   ` Martin Jambon
2007-01-25  9:36     ` Nicolas Pouillard

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=20070123235940.GA32163@pulp.rsise.anu.edu.au \
    --to=pietro.abate@anu.edu.au \
    --cc=caml-list@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).