<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/07/a271f4688bedcc68d89571a4f7b2cc1f"
  from="Pietro Abate &lt;Pietro.Abate@a...&gt;"
  author="Pietro Abate"
  date="2003-07-07T10:13:34"
  subject="[Caml-list] genlex ..."
  prev="2003/07/bb08176385e0e3626d7033d67ea11fa8"
  next="2003/07/e1912edad162e6ed5f99c25fd144116f"
  next-in-thread="2003/07/16456967beea1ab5004955e83b294d89"
  prev-thread="2003/07/ce2eb56d389991d2a9c2107a035618d4"
  next-thread="2003/07/d4567e135396aa37ca95126cae72c96f"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] genlex ...">
<msg 
  url="2003/07/a271f4688bedcc68d89571a4f7b2cc1f"
  from="Pietro Abate &lt;Pietro.Abate@a...&gt;"
  author="Pietro Abate"
  date="2003-07-07T10:13:34"
  subject="[Caml-list] genlex ...">
<msg 
  url="2003/07/16456967beea1ab5004955e83b294d89"
  from="Pietro Abate &lt;Pietro.Abate@a...&gt;"
  author="Pietro Abate"
  date="2003-07-08T00:34:05"
  subject="Re: [Caml-list] genlex ...">
</msg>
</msg>
</thread>

<contents>
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
	[&lt; e1 = parse_level0; e = parse_level11 e1 &gt;] -&gt; e
and parse_level11 e1 = parser
	[&lt; (keyword buf); e2 = parse_level1 &gt;] -&gt;
	| [&lt; &gt;] -&gt; e1
and parse_level0 = parser
	[&lt; (keyword buf); e = parse_level0 &gt;] -&gt;
	 ....
 
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

</contents>

</message>

