Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Daniel Marre <Daniel.Marre@insa-toulouse.fr>
To: caml-list@inria.fr
Subject: ocamllex -ocamlyacc pb
Date: Tue, 26 Oct 2004 17:54:14 +0200	[thread overview]
Message-ID: <417E7326.6060206@insa-toulouse.fr> (raw)

[-- 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) } ;


             reply	other threads:[~2004-10-26 15:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-26 15:54 Daniel Marre [this message]
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

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=417E7326.6060206@insa-toulouse.fr \
    --to=daniel.marre@insa-toulouse.fr \
    --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