Browse thread
[Caml-list] Ocamlyacc vs stream parser
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Anton Moscal <msk@m...> |
| Subject: | Re: [Caml-list] Ocamlyacc vs stream parser |
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