From: Thierry Bravier <bravier@dassault-aviation.fr>
To: caml-list@pauillac.inria.fr
Subject: re-entrance of ocamlyacc parsers
Date: Wed, 04 Jun 1997 09:05:16 +0200 [thread overview]
Message-ID: <339513AC.4B89@dassault-aviation.fr> (raw)
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
next reply other threads:[~1997-06-04 7:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-06-04 7:05 Thierry Bravier [this message]
1997-06-06 11:48 ` Thierry Bravier
1997-06-12 14:39 ` Xavier Leroy
1997-06-04 18:57 David Gurr
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=339513AC.4B89@dassault-aviation.fr \
--to=bravier@dassault-aviation.fr \
--cc=caml-list@pauillac.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