caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Problem when parsing
@ 2001-03-02 10:46 Laurent Reveillere
  2001-03-02 13:02 ` Jean-Christophe Filliatre
  2001-03-02 13:21 ` Markus Mottl
  0 siblings, 2 replies; 4+ messages in thread
From: Laurent Reveillere @ 2001-03-02 10:46 UTC (permalink / raw)
  To: caml-list

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)


If I replace the following rule in the parser :
	
translation_unit:  
     external_declaration   { () }
  |  translation_unit external_declaration   { () }
 
;                                                                             	


by

translation_unit:  
     external_declaration   { () }
 
;                                                                             	

the test file is parsed with no problem.
The test file is just "int x;"


Any idea ...


I know that this error is raised by lex_engine in byterun/lexing.c but I
do not understand why !!!

-- 
Laurent
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Problem when parsing
  2001-03-02 10:46 [Caml-list] Problem when parsing Laurent Reveillere
@ 2001-03-02 13:02 ` Jean-Christophe Filliatre
  2001-03-02 13:07   ` Laurent Reveillere
  2001-03-02 13:21 ` Markus Mottl
  1 sibling, 1 reply; 4+ messages in thread
From: Jean-Christophe Filliatre @ 2001-03-02 13:02 UTC (permalink / raw)
  To: Laurent Reveillere; +Cc: caml-list


Laurent Reveillere writes:
 > 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)

This exception is raised by the lexer when input does not match any of
the lexer rules.  So it has probably to do with  your lexer rules, not
with your parser rules.

Hope this helps,
-- 
Jean-Christophe FILLIATRE
  mailto:Jean-Christophe.Filliatre@lri.fr
  http://www.lri.fr/~filliatr
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Problem when parsing
  2001-03-02 13:02 ` Jean-Christophe Filliatre
@ 2001-03-02 13:07   ` Laurent Reveillere
  0 siblings, 0 replies; 4+ messages in thread
From: Laurent Reveillere @ 2001-03-02 13:07 UTC (permalink / raw)
  To: Jean-Christophe Filliatre; +Cc: caml-list

Jean-Christophe Filliatre wrote:
> 
> Laurent Reveillere writes:
>  > 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)
> 
> This exception is raised by the lexer when input does not match any of
> the lexer rules.  So it has probably to do with  your lexer rules, not
> with your parser rules.
> 
> Hope this helps,
> --
> Jean-Christophe FILLIATRE
>   mailto:Jean-Christophe.Filliatre@lri.fr
>   http://www.lri.fr/~filliatr


Yes, I fixed the problem. The error came from the fact that I forgot a
rule for eof in my lexer. Still, I would like to know why the eof
special char is not match by a rule like
	 | _ -> raise (Failure "unknown token") 


-- 
Lauren
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Problem when parsing
  2001-03-02 10:46 [Caml-list] Problem when parsing Laurent Reveillere
  2001-03-02 13:02 ` Jean-Christophe Filliatre
@ 2001-03-02 13:21 ` Markus Mottl
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Mottl @ 2001-03-02 13:21 UTC (permalink / raw)
  To: Laurent Reveillere; +Cc: caml-list

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)
[snip]

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.

Regards,
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


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

end of thread, other threads:[~2001-03-02 13:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-02 10:46 [Caml-list] Problem when parsing Laurent Reveillere
2001-03-02 13:02 ` Jean-Christophe Filliatre
2001-03-02 13:07   ` Laurent Reveillere
2001-03-02 13:21 ` Markus Mottl

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