caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Anton Moscal <msk@mail.tepkom.ru>
To: Michal Moskal <malekith@pld-linux.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Ocamlyacc vs stream parser
Date: Wed, 28 May 2003 14:48:19 +0400	[thread overview]
Message-ID: <3ED493F3.1000400@post.tepkom.ru> (raw)
In-Reply-To: <20030523092657.GA4547@roke.freak>

Michal Moskal wrote:

>>One question:
>>  Why should I use parser keyword instead of ocamlyacc?
> 
> 
> ocamlyacc gives you better error reporting (about conflicts) and
> strictly bigger set of languages it can recognize. But keyword parser
> build with camlp4 libraries can be modified at runtime. It also provides
> some higher-level constructs like LIST0.
> 
There is another useful feature of camlp4 - you can manually write 
parsing function which can perform  lookahead to any number of tokens 
and use criteria of arbitrary complexity. This provides simply and 
efficient workaround for resolving ambiguities.

(or use some external information to implement context dependecies - for 
example - I can easily write rule type_identifier, which can succeed 
only if current lexem is name which was declared before as type name) -

Example: "guard" rule, which don't eat any tokens from input strean and 
succeed iff next two tokens are:
"[ <int number>"
or "[]"
or "[..."



let is_bound =
   Grammar.Entry.of_parser gram "[is_bound]"
     (fun strm ->
       match Stream.npeek 2 strm with
       | ("", "[")::("INT", _)::_
       |	("", "[")::("", "]")::_
       |	("", "[")::("", "...")::_ -> ()
       | _ -> raise Stream.Failure
     )

usage:

....
  | LEFTA [ t=SELF; is_bound; "["; bounds=LIST0 bound SEP ","; "]"
         -> Type.Array (t, bounds)
....


Anton Moscal

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


  parent reply	other threads:[~2003-05-28 10:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-23  9:07 Lukasz Lew
2003-05-23  9:26 ` Michal Moskal
2003-05-26 12:28   ` Damien Doligez
2003-05-27 21:12   ` Pierre Weis
2003-05-28  9:20     ` Michal Moskal
2003-05-28  9:37       ` Diego Olivier Fernandez Pons
2003-05-28 10:24         ` Michal Moskal
2003-05-28 15:45           ` brogoff
2003-05-28 20:34     ` Alain.Frisch
2003-05-28 10:48   ` Anton Moscal [this message]
2003-06-05 14:02 Diego Olivier Fernandez Pons
2003-06-10  9:03 ` Diego Olivier Fernandez Pons

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=3ED493F3.1000400@post.tepkom.ru \
    --to=msk@mail.tepkom.ru \
    --cc=caml-list@inria.fr \
    --cc=malekith@pld-linux.org \
    /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).