Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Re: re-entrance of ocamlyacc parsers
@ 1997-06-04 18:57 David Gurr
  0 siblings, 0 replies; 4+ messages in thread
From: David Gurr @ 1997-06-04 18:57 UTC (permalink / raw)
  To: bravier; +Cc: caml-list


You might want to look at Camlp4 and the new parsers it uses.  These new
parsers are extensible and so you could add your new parse line to the
existing ocaml parser as a modular extension.  Further more since 
the import function can be implemented as a preprocessing step it would
IMHO make sense to use camlp4 to do so rather than hacking the compiler.

-D

gurr@snap.med.ge.com





^ permalink raw reply	[flat|nested] 4+ messages in thread
* re-entrance of ocamlyacc parsers
@ 1997-06-04  7:05 Thierry Bravier
  1997-06-06 11:48 ` Thierry Bravier
  1997-06-12 14:39 ` Xavier Leroy
  0 siblings, 2 replies; 4+ messages in thread
From: Thierry Bravier @ 1997-06-04  7:05 UTC (permalink / raw)
  To: caml-list

Sorry, this mail was first sent to caml-light@pauillac.inria.fr

========================================================================
English version:

Dear ocamlers,

I am currently writing an ocamlyacc/lex parser for a tiny language.

I would like to be able to call the ocamlyacc-generated code
recursively from an ocamlyacc semantic action.

This would be helpful, for instance, in the case of an
external module interface import clause as in :

phrase:
| ...
| IMPORT IDENT SEMI
   { Import (compile_file $2) }

Let us call `yacc_start' and `lex_start' the functions created
by ocamlyacc and ocamllex.

1) I wonder how I can define a function `compile_file'
   that ends up calling `yacc_start' recursively.

   Maybe generating a function `yacc_start' defined with
   `let rec' instead of `let' would do (as with ocamllex).

   I could then write :
prase:
| ...
| IMPORT IDENT SEMI
   { Import (compile_file_with_parser yacc_start $2) }

   am I mistaken ?

2) Anyway, I noticed that the ocamlyacc-generated code
   (see stdlib/parsing.ml) uses a global value `env' (which can
   be emptied with `clear_parser ()').

   Does this forbid `yacc_start' re-entrance ?

   I mean, will the inner call to `yacc_start' corrupt `env' value
   for the outer call to work properly ?

   Or can I just see `env' as an implementation issue not to
   be considered by module `Parsing' users ?

Thank you.
Any help is welcome.

========================================================================
Version francaise :

Chers adeptes d'ocaml,

Je realise actuellement le compilateur d'un petit langage en
ocamlyacc/lex.

J'aimerais pouvoir appeler recursivement le code cree par ocamlyacc
depuis une action semantique.

Cela me serait utile, par exemple dans le cas d'une directive
d'importation d'un module externe comme dans :

phrase:
| ...
| IMPORT IDENT SEMI
   { Import (compile_file $2) }

Si l'on appelle `yacc_start' et `lex_start' les fonctions fournies par
by ocamlyacc et ocamllex ...

1) Je me demande comment ecrire la fonction `compile_file'
   qui finalement appelle `yacc_start' recursivement.

   Peut-etre peut-on y parvenir en modifiant ocamlyacc
   pour definir la fonction `yacc_start' avec `let rec'
   au lieu de `let' (comme le fait deja ocamllex).

   Je pourrais alors ecrire :
prase:
| ...
| IMPORT IDENT SEMI
   { Import (compile_file_with_parser yacc_start $2) }

   Ou fais-je fausse route ?

2) Quoiqu'il en soit, j'ai remarque que le code cree par ocamlyacc
   (Cf stdlib/parsing.ml) utilise une valeur globale `env' (qui
   peut etre videe par `clear_parser ()').

   Cela exclut-il toute re-entrance de `yacc_start' ?

   En somme, l'appel interieur de `yacc_start' va-t-il
   rendre la valeur de `env' inutilisable, apres son retour, dans
   l'appel exterieur ?

   Ou peut-on supposer que `env' n'est qu'un detail cache de realisation
   qui doit etre ignore des utilisateurs du module `Parsing' ?

Merci.
Toute aide est la bienvenue.


-- 
Thierry Bravier                Dassault Aviation - DGT / DTN / ELO / EAV
78, Quai Marcel Dassault              F-92214 Saint-Cloud Cedex - France
Telephone : (33) 01 47 11 53 07          Telecopie : (33) 01 47 11 52 83
E-Mail :                     mailto:thierry.bravier@dassault-aviation.fr





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

end of thread, other threads:[~1997-06-12 18:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-06-04 18:57 re-entrance of ocamlyacc parsers David Gurr
  -- strict thread matches above, loose matches on Subject: below --
1997-06-04  7:05 Thierry Bravier
1997-06-06 11:48 ` Thierry Bravier
1997-06-12 14:39 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox