caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: bob zhang <bobzhang1988@gmail.com>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Weird behavior of Camlp4 Parser
Date: Thu, 24 Nov 2011 11:08:54 -0500	[thread overview]
Message-ID: <CANcqPu56XZYL5tsSfn7xqk_aoSOYzkjsCe9TNUVg1rW4Mp_hFw@mail.gmail.com> (raw)
In-Reply-To: <CAPFanBFwDUe=cORYisCH4itW7ZMtpTPVdKmvPB-7khkiiF6wsQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2019 bytes --]

Thanks for quick reply.
I have read Jake's camlp4 series carefully, unfortunately it does not cover
my case :-(

On Thu, Nov 24, 2011 at 10:47 AM, Gabriel Scherer <gabriel.scherer@gmail.com
> wrote:

> Camlp4 performs grammar factorizations that make its behavior non
> strictly LL(k).
>
> I never bothered to learn the exact semantics of Camlp4 grammar rules;
> they're complex and, I suspect, possibly fragile. If you avoid being
> clever with ambiguities, you can get away with the gory details.
>
> You should have a look at Jake Donham excellent blog series about Camlp4:
>
> http://ambassadortothecomputers.blogspot.com/2010/05/reading-camlp4-part-6-parsing.html
>
> 2011/11/24 bob zhang <bobzhang1988@gmail.com>:
> > Hi List,
> > I have came across a strange behavior of the camlp4 parser, (maybe not
> > that weird due to my limited knowledge of the parser)
> > The contrived mini-examples as follows :
> > module MGram = MakeGram(Lexer) ;;
> > EXTEND MGram
> > GLOBAL: m_expr ;
> > m_expr :
> > [[ "foo"; f -> print_endline "first"
> > | "foo" ; "bar"; "baz" -> print_endline "second"]
> > ];
> > f : [["bar"; "baz" ]]; END;;
> > MGram.parse_string m_expr (Loc.mk "<string>") "foo bar baz ";;
> > second (** choose the second branch, maybe the token rule has a higher
> > priority *)
> >
> > MGram.Entry.clear m_expr;;
> > EXTEND MGram
> > GLOBAL: m_expr ;
> > m_expr :
> > [[ "foo"; f -> print_endline "first"
> > | "foo" ; "bar"; "bax" -> print_endline "second"]
> > ];
> > f : [["bar"; "baz" ]]; END;;
> > - : unit = ()
> > # MGram.parse_string m_expr (Loc.mk "<string>") "foo bar baz ";;
> > first (** here choose the first branch, but the token rule can consume
> > one token, I thought this should fail *)
> >
> > Many Thanks
> >
> >
> > --
> > Caml-list mailing list.  Subscription management and archives:
> > https://sympa-roc.inria.fr/wws/info/caml-list
> > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> > Bug reports: http://caml.inria.fr/bin/caml-bugs
> >
> >
>



-- 
Best, bob

[-- Attachment #2: Type: text/html, Size: 3298 bytes --]

  reply	other threads:[~2011-11-24 16:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-24 15:22 bob zhang
2011-11-24 15:47 ` Gabriel Scherer
2011-11-24 16:08   ` bob zhang [this message]
2011-11-24 16:33 ` Joel Reymont
2011-11-24 17:31   ` bob zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANcqPu56XZYL5tsSfn7xqk_aoSOYzkjsCe9TNUVg1rW4Mp_hFw@mail.gmail.com \
    --to=bobzhang1988@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=gabriel.scherer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).