English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Problem when parsing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-03-02 (13:21)
From: Markus Mottl <mottl@m...>
Subject: Re: [Caml-list] Problem when parsing
On Fri, 02 Mar 2001, Laurent Reveillere wrote:
> I wrote a small parser for iso C which does nothing (for now).
> The lexer and parser files are well compiled by ocamllex and ocamlyacc.
> But when I run the generated program, I have the following error :
> Fatal error: uncaught exception Failure(lexing: empty token)

The problem is that your parser rules are recursive, and you do not
handle EOF (end-of-file) in the lexer.

This means that the parser will demand a new token, because the recursive
parser rule says that there could be more of them. The lexer, however,
doesn't return further ones, because it doesn't know how to handle EOF.

There is a special pattern called "eof" (without the double-quotes) that
you can use in the lexer to match EOF. You can introduce a new token
"EOF" in the parser and return this one from the scanner when required.
You'll need parser rules that handle the EOF-token, of course.  Then your
problem should go away.

Markus Mottl

Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr