Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Pietro Abate <Pietro.Abate@anu.edu.au>
To: caml-list@inria.fr
Subject: [Caml-list] genlex ...
Date: Mon, 7 Jul 2003 20:13:44 +1000	[thread overview]
Message-ID: <20030707101344.GA13301@anu.edu.au> (raw)

Hi all,
I'm re-writing the parser of my application and I'd like to write a kind
of generic parser that can parse a language that I can change dynamically... 
In other words... My application is composed by a library, a set of
modules that are compiled separately and dynamically loaded and an
application that get the name of a module, a file and it parses the file
differently regarding the definions that it loads from the dynamic
module.

My point is that I want to have a generic parser that given a set of
keyword is able to parse different input.

so far I realized that I cannot do that with lex/yacc as they need a
compilation step (I could generate the lex/yacc file from the dynamic
module, but I think it's too messy...). But I can use Genlex.

Since I'm using Dynlink it's strightforward to load at runtime a
different set of keyword and initialized the lexer as :
let flexer = make_lexer Stub.variable_keyword_list

but at this point I don't know how to use the Genlex.parser to feed it
with my generic rules (every connective is declared as left assoc or non
assoc and the generic language is a calculator-like one ... )

I'd like to write something like

expr:
	| LBRACK expr RBRACK         { $2 } 
	| expr (keyword buf) expr    { Tree(keyword_lookup buf,$1,$3)
	| (keyword buf) expr         { Leaf(keyword_lookup buf,$2)
	| IDENT                      { Var($1)

where (keyword buf) is a function that returns 'Kwd if buf is a keyword
or fails ... Or using Genlex.parser as :

let rec parse_level1 = parser
	[< e1 = parse_level0; e = parse_level11 e1 >] -> e
and parse_level11 e1 = parser
	[< (keyword buf); e2 = parse_level1 >] ->
	| [< >] -> e1
and parse_level0 = parser
	[< (keyword buf); e = parse_level0 >] ->
	 ....
 
is it possible ? does anybody can give me a small example ?

tnx,
P

-- 
Civilization advances by extending the number
of important operations which we can perform 
without thinking. (Alfred North Whitehead)

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


             reply	other threads:[~2003-07-07 10:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-07 10:13 Pietro Abate [this message]
2003-07-08  0:34 ` Pietro Abate

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=20030707101344.GA13301@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