caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] parsing: old and new ways
@ 2001-12-14 19:44 Philippe Esperet
  2001-12-14 20:57 ` Daniel de Rauglaudre
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Esperet @ 2001-12-14 19:44 UTC (permalink / raw)
  To: caml-list

%--------------------
/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


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

* Re: [Caml-list] parsing: old and new ways
  2001-12-14 19:44 [Caml-list] parsing: old and new ways Philippe Esperet
@ 2001-12-14 20:57 ` Daniel de Rauglaudre
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel de Rauglaudre @ 2001-12-14 20:57 UTC (permalink / raw)
  To: caml-list

Hi,

On Fri, Dec 14, 2001 at 08:44:27PM +0100, Philippe Esperet wrote:

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

The problem is the lexer you use. You took "Plexer.make ()" which
considers "abcba" as a token, therefore not matching the keywords
"a", "b" or "c".

To get the same result you should give the string "a b c b a" as
input...

... or use another lexer, not "Plexer.make ()", which would return
each input character as token. It should be easy. If you need help
to write it, ask me.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
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


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

end of thread, other threads:[~2001-12-14 20:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-14 19:44 [Caml-list] parsing: old and new ways Philippe Esperet
2001-12-14 20:57 ` Daniel de Rauglaudre

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