From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_WHOIS,HTML_MESSAGE autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id B1C23BC6B for ; Tue, 27 Nov 2007 21:22:43 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAEULTEfAXQImh2dsb2JhbACCPjWMSwEBAQgKKQ X-IronPort-AV: E=Sophos;i="4.23,220,1194217200"; d="scan'208";a="4675571" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 27 Nov 2007 21:22:43 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id lARKMhhd025562 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 27 Nov 2007 21:22:43 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAEULTEfRSbJglmdsb2JhbACCPjWMSwEBAQEHBAYREQc X-IronPort-AV: E=Sophos;i="4.23,220,1194217200"; d="scan'208";a="4992176" Received: from web60113.mail.yahoo.com ([209.73.178.96]) by mail1-smtp-roc.national.inria.fr with SMTP; 27 Nov 2007 21:22:42 +0100 Received: (qmail 36094 invoked by uid 60001); 27 Nov 2007 20:22:41 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=rcBV4Yr0ut1uAW4G2Vqmje0aHlxskvwA5MMDbmcZW7iFBXhkFvj2vIYIA5xGvatlJraAqk9BUAgYau70mdbkT4IaTp1mVkBx5Z9EyLTK8Gh+oYvlpEdfL4lh27NtLb2VuVmbrnSDRf+uihBRMsnUNzxT33R6qPkp5UU+QiIMQhk=; X-YMail-OSG: t7FnUvUVM1n9KmfmVeoMxxOHYs_DlnMLjGx6ycRe98WD1sLBohZq5.EYQJjZRYDWfTc5a1lhzm4YAF1OoIX_tJyegQ0keZt6gaKYbZkgjROEEWG33QuOZLKjZIJPkCg- Received: from [66.100.224.174] by web60113.mail.yahoo.com via HTTP; Tue, 27 Nov 2007 12:22:41 PST Date: Tue, 27 Nov 2007 12:22:41 -0800 (PST) From: echinuz echinuz Subject: Possible Parsing Bug with camlp4 To: caml-list@inria.fr MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1342996818-1196194961=:35404" Content-Transfer-Encoding: 8bit Message-ID: <557897.35404.qm@web60113.mail.yahoo.com> X-Miltered: at discorde with ID 474C7C93.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bug:01 camlp:01 camlp:01 expr:01 syntax:01 syntax:01 expr:01 lexer:01 printf:01 printf:01 self-:01 parses:01 ocaml:01 cmo:01 val:01 --0-1342996818-1196194961=:35404 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Consider the following simple calculator using camlp4: --------------------------------------------------------------------- $ cat pa_calc_quote.ml open Camlp4.PreCast;; let expr_of_string = Syntax.Gram.parse_string Syntax.expr_eoi;; type alg= | Add of alg*alg | Sub of alg*alg | Mul of alg*alg | Div of alg*alg | Pow of alg*alg | Int of int ;; module AlgGram = MakeGram(Lexer);; let expression = AlgGram.Entry.mk "expression";; let expression_eoi = AlgGram.Entry.mk "expression_eoi";; Camlp4_config.antiquotations := false;; EXTEND AlgGram GLOBAL: expression expression_eoi; expression_eoi: [[ e=expression; `EOI -> Printf.printf "eoi\n"; e]]; expression: [ "add" LEFTA [ x=SELF; "+"; y=SELF -> Printf.printf "add\n";<:expr< Add($x$,$y$) >> | x=SELF; "-"; y=SELF -> Printf.printf "sub\n";<:expr< Sub($x$,$y$) >>] | "mul" LEFTA [ x=SELF; "*"; y=SELF -> Printf.printf "mul\n";<:expr< Mul($x$,$y$) >> | x=SELF; "/"; y=SELF -> <:expr< Div($x$,$y$) >>] | "pow" RIGHTA [ x=SELF; "**"; y=SELF-> Printf.printf "pow\n";<:expr< Pow($x$,$y$) >>] | "simple" NONA [x=INT -> Printf.printf "int\n"; <:expr< Int $int:x$ >> |"("; x=SELF; ")" -> Printf.printf "par\n"; x | `ANTIQUOT(("" | "expression"),x) -> expr_of_string _loc x] ]; END;; let expand_alg_quot_expr loc _loc_name_opt quotation_contents = AlgGram.parse_string expression_eoi loc quotation_contents;; Syntax.Quotation.add "alg" Syntax.Quotation.DynAst.expr_tag expand_alg_quot_expr;; Syntax.Quotation.default := "alg";; --------------------------------------------------------------------- On the top level, the following program parses fine, despite the `EOI requirement: --------------------------------------------------------------------- $ ocaml -I +camlp4 camlp4of.cma ./pa_calc_quote.cmo Objective Caml version 3.10.0 Camlp4 Parsing version 3.10.0 # open Pa_calc_quote;; # let x= << 1+ >>;; int eoi val x : Pa_calc_quote.alg = Int 1 --------------------------------------------------------------------- Now, consider the same program above with addition commented out: --------------------------------------------------------------------- $ cat ./pa_calc_quote.ml open Camlp4.PreCast;; let expr_of_string = Syntax.Gram.parse_string Syntax.expr_eoi;; type alg= | Add of alg*alg | Sub of alg*alg | Mul of alg*alg | Div of alg*alg | Pow of alg*alg | Int of int ;; module AlgGram = MakeGram(Lexer);; let expression = AlgGram.Entry.mk "expression";; let expression_eoi = AlgGram.Entry.mk "expression_eoi";; Camlp4_config.antiquotations := false;; EXTEND AlgGram GLOBAL: expression expression_eoi; expression_eoi: [[ e=expression; `EOI -> Printf.printf "eoi\n"; e]]; expression: [ "add" LEFTA [ (*x=SELF; "+"; y=SELF -> Printf.printf "add\n";<:expr< Add($x$,$y$) >> | *)x=SELF; "-"; y=SELF -> Printf.printf "sub\n";<:expr< Sub($x$,$y$) >>] | "mul" LEFTA [ x=SELF; "*"; y=SELF -> Printf.printf "mul\n";<:expr< Mul($x$,$y$) >> | x=SELF; "/"; y=SELF -> <:expr< Div($x$,$y$) >>] | "pow" RIGHTA [ x=SELF; "**"; y=SELF-> Printf.printf "pow\n";<:expr< Pow($x$,$y$) >>] | "simple" NONA [x=INT -> Printf.printf "int\n"; <:expr< Int $int:x$ >> |"("; x=SELF; ")" -> Printf.printf "par\n"; x | `ANTIQUOT(("" | "expression"),x) -> expr_of_string _loc x] ]; END;; let expand_alg_quot_expr loc _loc_name_opt quotation_contents = AlgGram.parse_string expression_eoi loc quotation_contents;; Syntax.Quotation.add "alg" Syntax.Quotation.DynAst.expr_tag expand_alg_quot_expr;; Syntax.Quotation.default := "alg";; --------------------------------------------------------------------- The exact same quotation above, run on the top level, now produces a parsing error: --------------------------------------------------------------------- $ ocaml -I +camlp4 camlp4of.cma ./pa_calc_quote.cmo Objective Caml version 3.10.0 Camlp4 Parsing version 3.10.0 # open Pa_calc_quote;; # let x= << 1+ >>;; # let x= << 1+ >>;; While expanding quotation "alg" in a position of "expr": Parse error: illegal begin of expression_eoi --------------------------------------------------------------------- Is this behavior expected or is this a bug? --------------------------------- Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how. --0-1342996818-1196194961=:35404 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit      Consider the following simple calculator using camlp4:

---------------------------------------------------------------------
$ cat pa_calc_quote.ml
open Camlp4.PreCast;;

let expr_of_string = Syntax.Gram.parse_string Syntax.expr_eoi;;

type alg=
| Add of alg*alg
| Sub of alg*alg
| Mul of alg*alg
| Div of alg*alg
| Pow of alg*alg
| Int of int
;;

module AlgGram = MakeGram(Lexer);;
let expression = AlgGram.Entry.mk "expression";;
let expression_eoi = AlgGram.Entry.mk "expression_eoi";;
Camlp4_config.antiquotations := false;;

EXTEND AlgGram
GLOBAL: expression expression_eoi;
expression_eoi:
    [[ e=expression; `EOI -> Printf.printf "eoi\n"; e]];
expression:
    [ "add" LEFTA
        [ x=SELF; "+"; y=SELF -> Printf.printf "add\n";<:expr< Add($x$,$y$) >>
        | x=SELF; "-"; y=SELF -> Printf.printf "sub\n";<:expr< Sub($x$,$y$) >>]
    | "mul" LEFTA
        [ x=SELF; "*"; y=SELF -> Printf.printf "mul\n";<:expr< Mul($x$,$y$) >>
        | x=SELF; "/"; y=SELF -> <:expr< Div($x$,$y$) >>]
    | "pow" RIGHTA
        [ x=SELF; "**"; y=SELF-> Printf.printf "pow\n";<:expr< Pow($x$,$y$) >>]
    | "simple" NONA
        [x=INT -> Printf.printf "int\n"; <:expr< Int $int:x$ >>
        |"("; x=SELF; ")" -> Printf.printf "par\n"; x
        | `ANTIQUOT(("" | "expression"),x) -> expr_of_string _loc x]
    ];
END;;

let expand_alg_quot_expr loc _loc_name_opt quotation_contents =
    AlgGram.parse_string expression_eoi loc quotation_contents;;
Syntax.Quotation.add "alg" Syntax.Quotation.DynAst.expr_tag expand_alg_quot_expr;;
Syntax.Quotation.default := "alg";;
---------------------------------------------------------------------

On the top level, the following program parses fine, despite the `EOI requirement:

---------------------------------------------------------------------
$ ocaml -I +camlp4 camlp4of.cma ./pa_calc_quote.cmo
        Objective Caml version 3.10.0

        Camlp4 Parsing version 3.10.0

# open Pa_calc_quote;;
# let x= << 1+ >>;;
int
eoi
val x : Pa_calc_quote.alg = Int 1
---------------------------------------------------------------------

Now, consider the same program above with addition commented out:

---------------------------------------------------------------------
$ cat ./pa_calc_quote.ml
open Camlp4.PreCast;;

let expr_of_string = Syntax.Gram.parse_string Syntax.expr_eoi;;

type alg=
| Add of alg*alg
| Sub of alg*alg
| Mul of alg*alg
| Div of alg*alg
| Pow of alg*alg
| Int of int
;;

module AlgGram = MakeGram(Lexer);;
let expression = AlgGram.Entry.mk "expression";;
let expression_eoi = AlgGram.Entry.mk "expression_eoi";;
Camlp4_config.antiquotations := false;;

EXTEND AlgGram
GLOBAL: expression expression_eoi;
expression_eoi:
    [[ e=expression; `EOI -> Printf.printf "eoi\n"; e]];
expression:
    [ "add" LEFTA
        [ (*x=SELF; "+"; y=SELF -> Printf.printf "add\n";<:expr< Add($x$,$y$) >>
        | *)x=SELF; "-"; y=SELF -> Printf.printf "sub\n";<:expr< Sub($x$,$y$) >>]
    | "mul" LEFTA
        [ x=SELF; "*"; y=SELF -> Printf.printf "mul\n";<:expr< Mul($x$,$y$) >>
        | x=SELF; "/"; y=SELF -> <:expr< Div($x$,$y$) >>]
    | "pow" RIGHTA
        [ x=SELF; "**"; y=SELF-> Printf.printf "pow\n";<:expr< Pow($x$,$y$) >>]
    | "simple" NONA
        [x=INT -> Printf.printf "int\n"; <:expr< Int $int:x$ >>
        |"("; x=SELF; ")" -> Printf.printf "par\n"; x
        | `ANTIQUOT(("" | "expression"),x) -> expr_of_string _loc x]
    ];
END;;

let expand_alg_quot_expr loc _loc_name_opt quotation_contents =
    AlgGram.parse_string expression_eoi loc quotation_contents;;
Syntax.Quotation.add "alg" Syntax.Quotation.DynAst.expr_tag expand_alg_quot_expr;;
Syntax.Quotation.default := "alg";;
---------------------------------------------------------------------

The exact same quotation above, run on the top level, now produces a parsing error:

---------------------------------------------------------------------
$ ocaml -I +camlp4 camlp4of.cma ./pa_calc_quote.cmo
        Objective Caml version 3.10.0

        Camlp4 Parsing version 3.10.0

# open Pa_calc_quote;;
# let x= << 1+ >>;;
# let x= << 1+ >>;;
While expanding quotation "alg" in a position of "expr":
  Parse error: illegal begin of expression_eoi
---------------------------------------------------------------------

Is this behavior expected or is this a bug?


Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how. --0-1342996818-1196194961=:35404--