Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] parsing: old and new ways
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Philippe Esperet <philippe.esperet@w...>
Subject: [Caml-list] parsing: old and new ways
%--------------------
/dosc/esperet/tex/email/@ocaml9.tex Fri Dec 14 2001 20:36:20
caml-list@inria.fr

Trying to parse the grammar S->aSa|bSb|c
with the old stream syntax, I get

# mirror_parse (Stream.of_string "abcba");;
- : string = "abba"

but with the new camlp4 syntax, the natural translation fails:

# Grammar.Entry.parse mirror (Stream.of_string "abcba");;
Exception:
Stdpp.Exc_located ((0, 5), Stream.Error "illegal begin of mirror").

What am I missing?

Best regards


[old code]
let rec mirror_parse=parser
| [<''a';s=mirror_parse;''a'>] -> "a"^s^"a"
| [<''b';s=mirror_parse;''b'>] -> "b"^s^"b"
| [<''c'>]                     -> "";;

[brand new code]
let gram_mirror=Grammar.create (Plexer.make ());; 
let mirror=Grammar.Entry.create gram_mirror "mirror";;

EXTEND
  mirror:
  [   [  "a" ; x=mirror ; "a" -> "a"^x^"a"
       | "b" ; x=mirror ; "b" -> "b"^x^"b"
       | "c"                  ->  ""]
  ];
END;;
-- 
esperet@gage.polytechnique.fr
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr