Browse thread
camlp4 stream parser syntax
[
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: | Joel Reymont <joelr1@g...> |
| Subject: | Re: Re : [Caml-list] Re: camlp4 stream parser syntax |
On Mar 7, 2009, at 11:21 PM, Matthieu Wipliez wrote: > why are you using stream parsers instead of Camlp4 grammars ? Because I don't know any better? I'm just starting out, really. I have a parser that I wrote using ocamlyacc and menhir. I finally when with dypgen and didn't touch the code for a few months. I then tried to simplify the grammar on account of a later type checking pass and realized that I cannot troubleshoot it. I think I can make do with a camlp4 parser and it will vastly simplify debugging. > This: > ... > could be written as: > expression: [ > [ (i, _) = INT -> Int i > | (s, _) = STRING -> Str s > ... ] > ]; Doesn't your example assume that I'm using the camlp4 lexer? > expression: [ > [ e1 = SELF; "/"; e2 = SELF -> > if e2 = Int 0 then > Loc.raise _loc (Failure "division by zero") > else > BinaryOp (e1, Div, e2) ] > ]; Where does SELF above come from? Can I use a token instead of "/" since I return SLASH whenever "/" is found by the lexer. > By the way, do you need you own tailor-made lexer? Camlp4 provides > one that might satisfy your needs. It has been said that it's not extensible so I wrote my own lexer using ocamllex and wrapped it to return (tok, loc) Stream.t. > Otherwise, you can always define your own lexer (I had to do that > for the project I'm working on, see file attached). Thanks, I'll study it. > Your parser would then look like > > (* functor application *) > module Camlp4Loc = Camlp4.Struct.Loc > module Lexer = Cal_lexer.Make(Camlp4Loc) > module Gram = Camlp4.Struct.Grammar.Static.Make(Lexer) Is this extending the OCaml grammar or starting with an "empty" one? > (* rule definition *) > let rule = Gram.Entry.mk "rule" Is this the "start" rule of the parser? Thanks, Joel --- http://tinyco.de Mac, C++, OCaml