caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* ocamllex -ocamlyacc pb
@ 2004-10-26 15:54 Daniel Marre
  2004-10-26 16:26 ` [Caml-list] " Jean-Christophe Filliatre
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Daniel Marre @ 2004-10-26 15:54 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1128 bytes --]

Bonjour,

Je tente de passer de CamlLight vers Ocaml le lexer et le parser de 
l'exemple ASL (A Small Language) présent chapitre 12 du document déjà 
ancien de Michel Mauny. Je l'utilise avec succès depuis pas mal de temps 
, il est très intéressant pour illustrer la mise en place d'un 
interprète, la gestion de l'environnement et l'emploi des types 
fonctionnels.

Le passage des fichiers mll et mly de caml vers ocaml devraient se 
limiter au renommage des types et symboles non terminaux mais ça coince. 
: j'ai un pb avec la notion de type qualifié pour le %type

Si quelqu'un peut m'apporter un peu de lumière, je le remercie par avance.

Bien cordialement.

Daniel.



résultats de compiles :

ocamllex lexer.mll
12 states, 332 transitions, table size 1400 bytes
ocamlyacc -v parser.mly
6 shift/reduce conflicts.
ocamlc parser.mli
File "parser.mli", line 19, characters 48-61:
Unbound type constructor plftypes__plf


-- 
Daniel Marre

Maître de Conférences
INSA - DGEI                        www.insa-toulouse.fr
125 AV. de Rangueil - 31077     - Toulouse (France)
Daniel.Marre@insa-toulouse.fr     (33)5.61.55.98.24 


[-- Attachment #2: ASLParser-ocaml.txt --]
[-- Type: text/plain, Size: 1703 bytes --]

      
(* plftypes.ml Syntaxe abstraite pour plf *)
(* ************************************** *)

type plf = Const of int
         | Var   of string
	 | Cond  of plf * plf * plf
	 | Appl  of plf * plf
	 | Abs   of string * plf
	 | Let   of string * plf * plf
;;
exception Erreur_de_syntaxe;;
     

{
  (* lexer.mll Analyse lexicale pour PLF *)
  (* *********************************** *)

#use "parser.ml";;

exception Fin_inopinee;;

let mots_cles = 
  [ "let"  , LET ;
    "be"   , BE ;
    "in"   , IN ;
    "if"   , IF ;
    "then" , THEN ;
    "else" , ELSE ;
    "fi"   , FI 
  ] ;;
}

rule token = parse
  [' ' '\t']		{ token lexbuf }
| ['\n']   		{ token lexbuf }
| ['0'-'9']+ 		{ INT (int_of_string(get_lexeme lexbuf)) }
| ['a'-'z' 'A'-'Z']+	{ let s = get_lexeme lexbuf
                          in try assoc s mots_cles with Not_found -> IDENT s }
| ['+' '-' '*' '/' '=']	{ IDENT (get_lexeme lexbuf) }
| "\\"			{ LAMBDA }
| "."			{ POINT }
| "("			{ PARENG }
| ")"			{ PAREND }
| ";"			{ PVIRGULE }
| eof			{ raise Fin_inopinee }


%{
   (* parser.mly Grammaire du langage PLF *)
   (* *********************************** *)

#use "plftypes";;
%}

%token <int> INT
%token <string> IDENT
%token LET BE IN IF THEN ELSE FI
%token PARENG PAREND LAMBDA POINT PVIRGULE EOL

%start debut
%type <plftypes__plf> debut 

%%
debut :	
	expr  PVIRGULE			{ $1 };

expr0 :
        INT				{ Const $1 }
      | IDENT 				{ Var $1 } 
      | PARENG expr PAREND		{ $2 };
expr :
        expr0				{ $1 } 
      | IF expr THEN expr ELSE expr FI	{ Cond ($2,$4,$6) }
      | LAMBDA IDENT POINT expr 	{ Abs ($2,$4) }
      | LET IDENT BE expr IN expr       { Let ($2,$4,$6) }
      | expr expr0			{ Appl ($1,$2) } ;


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

* Re: [Caml-list] ocamllex -ocamlyacc pb
  2004-10-26 15:54 ocamllex -ocamlyacc pb Daniel Marre
@ 2004-10-26 16:26 ` Jean-Christophe Filliatre
  2004-10-26 16:32 ` Michel Mauny
  2004-10-26 16:36 ` Olivier Pérès
  2 siblings, 0 replies; 4+ messages in thread
From: Jean-Christophe Filliatre @ 2004-10-26 16:26 UTC (permalink / raw)
  To: Daniel Marre; +Cc: caml-list


Daniel Marre writes:

 > Le passage des fichiers mll et mly de caml vers ocaml devraient se 
 > limiter au renommage des types et symboles non terminaux mais ça coince. 
 > : j'ai un pb avec la notion de type qualifié pour le %type

 > %type <plftypes__plf> debut 

C'est de la syntaxe Caml Light ; il faut écrire

  %type <Plftypes.plf> debut

(et d'autre part les #use ... devraient être remplacés par des open)

-- 
Jean-Christophe


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

* Re: [Caml-list] ocamllex -ocamlyacc pb
  2004-10-26 15:54 ocamllex -ocamlyacc pb Daniel Marre
  2004-10-26 16:26 ` [Caml-list] " Jean-Christophe Filliatre
@ 2004-10-26 16:32 ` Michel Mauny
  2004-10-26 16:36 ` Olivier Pérès
  2 siblings, 0 replies; 4+ messages in thread
From: Michel Mauny @ 2004-10-26 16:32 UTC (permalink / raw)
  To: Daniel Marre; +Cc: caml-list

Daniel Marre wrote/écrivait (Tue, Oct 26, 2004 at 05:54:14PM +0200):

> Si quelqu'un peut m'apporter un peu de lumière, je le remercie par avance.

C'est parce qu'il reste un peu de CamlLight dans parser.mly. Il te
faut changer

    %type <plftypes__plf> debut 
en
    %type <Plftypes.plf> debut 

et compiler plftypes.ml avant de compiler parser.ml (pour créer
l'interface de Plftypes). (Je n'ai pas testé plus que cela.)

Cordialement,

-- Michel Mauny


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

* Re: [Caml-list] ocamllex -ocamlyacc pb
  2004-10-26 15:54 ocamllex -ocamlyacc pb Daniel Marre
  2004-10-26 16:26 ` [Caml-list] " Jean-Christophe Filliatre
  2004-10-26 16:32 ` Michel Mauny
@ 2004-10-26 16:36 ` Olivier Pérès
  2 siblings, 0 replies; 4+ messages in thread
From: Olivier Pérès @ 2004-10-26 16:36 UTC (permalink / raw)
  To: Daniel Marre, Caml-list

Daniel Marre a écrit :
> Je tente de passer de CamlLight vers Ocaml le lexer et le parser de 
> l'exemple ASL (A Small Language)
[...]
> résultats de compiles :
[...]
> File "parser.mli", line 19, characters 48-61:
> Unbound type constructor plftypes__plf
[...]
> %start debut
> %type <plftypes__plf> debut 

    Avec Objective Caml il faut remplacer __ (souligné souligné) par . 
(point) pour l'accès à un module.

    Olivier.


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

end of thread, other threads:[~2004-10-26 16:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-26 15:54 ocamllex -ocamlyacc pb Daniel Marre
2004-10-26 16:26 ` [Caml-list] " Jean-Christophe Filliatre
2004-10-26 16:32 ` Michel Mauny
2004-10-26 16:36 ` Olivier Pérès

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).