X-Git-Url: http://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/feec80c30d140c69f5d894bd09b6071247d0fbaa..d6ce1786f27a05efa53cabeca92fc8e744a4b239:/bundles/menhirLib/menhir-20120123/demos/calc/calc.ml diff --git a/bundles/menhirLib/menhir-20120123/demos/calc/calc.ml b/bundles/menhirLib/menhir-20120123/demos/calc/calc.ml new file mode 100644 index 0000000..cc54679 --- /dev/null +++ b/bundles/menhirLib/menhir-20120123/demos/calc/calc.ml @@ -0,0 +1,28 @@ +(**************************************************************************) +(* *) +(* Menhir *) +(* *) +(* François Pottier, INRIA Rocquencourt *) +(* Yann Régis-Gianas, PPS, Université Paris Diderot *) +(* *) +(* Copyright 2005-2008 Institut National de Recherche en Informatique *) +(* et en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0, with the change *) +(* described in file LICENSE. *) +(* *) +(**************************************************************************) + +let () = + let stdinbuf = Lexing.from_channel stdin in + while true do + (* Read line by line. *) + let linebuf = Lexing.from_string (Lexer.line stdinbuf) in + try + (* Run the parser on a single line of input. *) + Printf.printf "%d\n%!" (Parser.main Lexer.token linebuf) + with + | Lexer.Error msg -> + Printf.fprintf stderr "%s%!" msg + | Parser.Error -> + Printf.fprintf stderr "At offset %d: syntax error.\n%!" (Lexing.lexeme_start linebuf) + done