caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Ocamllex/Ocamlyacc feature request
@ 2003-05-28 21:03 Brian Hurt
  2003-05-29 10:16 ` Ken Wakita
  0 siblings, 1 reply; 6+ messages in thread
From: Brian Hurt @ 2003-05-28 21:03 UTC (permalink / raw)
  To: Ocaml Mailing List


Flex and Bison have an option to automatically output debugging
information to stdout in the generated code.

For flex, the option is -d, and documented thusly:

>       -d     makes the generated  scanner  run  in  debug  mode.
>              Whenever  a  pattern  is  recognized and the global
>              yy_flex_debug is non-zero (which is  the  default),
>              the  scanner  will  write  to  stderr a line of the
>              form:
>
>                  --accepting rule at line 53 ("the matched text")
>
>              The line number refers to the location of the  rule
>              in  the  file  defining the scanner (i.e., the file
>              that was fed to flex).  Messages are also generated
>              when  the  scanner  backs  up,  accepts the default
>              rule, reaches the  end  of  its  input  buffer  (or
>              encounters  a  NUL; at this point, the two look the
>              same as far as the scanner's concerned), or reaches
>              an end-of-file.

The Bison option is -t, and documented thusly:

>    Each step taken by the parser when `yydebug' is nonzero produces a
> line or two of trace information, written on `stderr'.  The trace
> messages tell you these things:
>
>    * Each time the parser calls `yylex', what kind of token was read.
>
>    * Each time a token is shifted, the depth and complete contents of
>      the state stack (*note Parser States::.).
>
>    * Each time a rule is reduced, which rule it is, and the complete
>      contents of the state stack afterward.

These are incredibly usefull for debugging your parsers.

Brian


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Ocamllex/Ocamlyacc feature request
  2003-05-28 21:03 [Caml-list] Ocamllex/Ocamlyacc feature request Brian Hurt
@ 2003-05-29 10:16 ` Ken Wakita
  2003-05-29 12:03   ` Damien
  2003-06-04  9:19   ` [Caml-list] Syntax error Lukasz Lew
  0 siblings, 2 replies; 6+ messages in thread
From: Ken Wakita @ 2003-05-29 10:16 UTC (permalink / raw)
  To: Brian Hurt; +Cc: Ocaml Mailing List

You can turn the parser trace facility on by:
setenv OCAMLRUNPARAM "p"

Read the OCAMLRUNPARAM section in:
http://caml.inria.fr/ocaml/htmlman/manual024.html

Ken Wakita

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Ocamllex/Ocamlyacc feature request
  2003-05-29 10:16 ` Ken Wakita
@ 2003-05-29 12:03   ` Damien
  2003-05-29 13:07     ` Luc Maranget
  2003-06-04  9:19   ` [Caml-list] Syntax error Lukasz Lew
  1 sibling, 1 reply; 6+ messages in thread
From: Damien @ 2003-05-29 12:03 UTC (permalink / raw)
  Cc: Ocaml Mailing List

Hello,

OCAMLRUNPARAM seems pretty fine for debugging purposes, 
what about "end-user error reporting" :

could the special terminal 'error' have some useful parameters ?

>type token_error_t = {
>chars: int*int;
>lexeme: string;
>token: token;
>expected: token list;
>}
>"%token <token_error_t> error"
would allow
>toto:
>| ... | ...
>| error { failwith (arf $1) }
>;

then, is there a "nice method" to insert error terminals in a
grammar, in order to get a parser :
	- without s/r or r/r conflicts
	- that never raise "Parsing.parse_error" : all error cases are
	identified and raise "My_informative_parse_error"
?

till now, I've always used the "try until no conflict" method, which
isn't really "nice"

could ocamlyacc decide whether a grammar is "exhaustive", like ocaml
does for pattern-matching ?


thanks,
damien

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Ocamllex/Ocamlyacc feature request
  2003-05-29 12:03   ` Damien
@ 2003-05-29 13:07     ` Luc Maranget
  0 siblings, 0 replies; 6+ messages in thread
From: Luc Maranget @ 2003-05-29 13:07 UTC (permalink / raw)
  To: Damien; +Cc: Ocaml Mailing List

> 

> does for pattern-matching ?
> 
> 
> thanks,
> damien
> 


Well, such a test is probalbly needed for both lex and yacc !


In the ocamllex case, this is quite easy as regards theory, since the
test can be  performed on automata.

The same may apply to yacc automata.

--Luc

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* [Caml-list] Syntax error
  2003-05-29 10:16 ` Ken Wakita
  2003-05-29 12:03   ` Damien
@ 2003-06-04  9:19   ` Lukasz Lew
  2003-06-04 17:25     ` Stefan Heimann
  1 sibling, 1 reply; 6+ messages in thread
From: Lukasz Lew @ 2003-06-04  9:19 UTC (permalink / raw)
  To: caml-list

Hi.

I am using Genlex and ocaml streams and parsers. And when I catch 
exception Stream.Error "", I can not generate other message than "syntax error".

How can I obtain informations about line number or character number, 
where the error ocurred ?

In ocaml examples at http://caml.inria.fr/Examples/oc.tar.gz, function 
pos_in is used, but it returns always number of last character in stream.

Do you have any ideas?
And how ocamlyacc deals with this problem?

Regards,
Lukasz Lew

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Syntax error
  2003-06-04  9:19   ` [Caml-list] Syntax error Lukasz Lew
@ 2003-06-04 17:25     ` Stefan Heimann
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Heimann @ 2003-06-04 17:25 UTC (permalink / raw)
  To: caml-list

Hi,

On Wed, Jun 04, 2003 at 11:19:47AM +0200, Lukasz Lew wrote:
> Hi.
> 
> I am using Genlex and ocaml streams and parsers. And when I catch 
> exception Stream.Error "", I can not generate other message than "syntax error".
> 
> How can I obtain informations about line number or character number, 
> where the error ocurred ?
> 
> In ocaml examples at http://caml.inria.fr/Examples/oc.tar.gz, function 
> pos_in is used, but it returns always number of last character in stream.

I don't have a good solution for this, just a hack. 

I have something like 'let lineno = ref 1' in the lexer and increment
the lineno everytime a '\n' is read. In the parser I have written the
parse_error function like that:

let parse_error s = raise Parse_error

My main program looks like that:

(* raises End_of_file if i is too large *)
let rec get_line i cin =
  begin
    assert (i >= 1);
    let l = input_line cin in
      if i == 1 then l
      else get_line (i - 1) cin
  end

let _ =
  let fname = Sys.argv.(1) in
  let lexbuf = Lexing.from_channel (open_in fname) in
    try
      let gr = Ebnf_parser.grammar Ebnf_lexer.token lexbuf in
        print_string (Grammar.string_of_grammar gr)
    with Parsing.Parse_error ->
      begin
        prerr_string (fname ^ ":" ^ (string_of_int !Ebnf_lexer.lineno)
                      ^ ": ");
        prerr_string ("Syntax error on token `" 
                      ^ (Lexing.lexeme lexbuf) ^ "'.");
        prerr_newline ();
        try let l = get_line !Ebnf_lexer.lineno (open_in fname) in
          prerr_string l;
          prerr_newline ();
        with End_of_file -> ()
      end

Maybe this helps...

Bye,
  Stefan

-- 
Stefan Heimann
http://www.stefanheimann.net :: personal website.
http://cvsshell.sf.net       :: CvsShell, a console based cvs client.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2003-06-04 17:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-28 21:03 [Caml-list] Ocamllex/Ocamlyacc feature request Brian Hurt
2003-05-29 10:16 ` Ken Wakita
2003-05-29 12:03   ` Damien
2003-05-29 13:07     ` Luc Maranget
2003-06-04  9:19   ` [Caml-list] Syntax error Lukasz Lew
2003-06-04 17:25     ` Stefan Heimann

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