Nicolas Pouillard wrote:
> On 4/5/07, Martin Jambon <[EMAIL PROTECTED]> wrote:
>> On Thu, 5 Apr 2007, Hugo Ferreira wrote:
>>
>>> Hello,
>>>
>>> I would like to use a reserved word and substitute that by a function
>>> call. For example, the following:
>>>
>>> let  _ = HEAP in
>>> let h1 = HEAP in
>>>
>>> would become
>>>
>>> let __heap = new_heap () in
>>> let     h1 = new_heap () in
> 
> As always it will be a lot simpler to do that kind of thing using a
> filter in camlp4 3.10.
> 
> ...
> match (* do things bottom-up *) super#expr e with
> | <:[EMAIL PROTECTED]< let _ = HEAP in $e$ >> ->
>      <:[EMAIL PROTECTED]< let __heap = new_heap () in $e$ >>
> | <:[EMAIL PROTECTED]< let $p$ = HEAP in $e$ >> ->
>      <:[EMAIL PROTECTED]< let $p$ = new_heap () in $e$ >>
> | e -> e
> ...
> 

Exactly what I was looking for. Alas.. I will have to wait for this.

>> You shouldn't try to do this because the parser looks only one token ahead
>> to make its decision. If you add a rule that starts from "let" (it has
>> to), the token which enables the parser to select this rule is in position
>> 3, so it comes too late. Camlp4 will not warn you about the conflict but
>> fail during preprocessing because it will choose either the predefined
>> "let" rule or yours without knowing if it's the right one.
> 
> In fact it's wrong camlp4 can takes more than one token of look ahead.
> It will try to match the input with all the firsts terminals of a rule.
> 

My solution seems to confirm this. In fact I can use the rule for
processing the whole "let x = y and " expression with success. I need
only ensure that I don't "hide" the original/predefined camlp4 rule (I
did this by looking for a 'y' as "HEAP" which is not a valid Ocaml
constructor).

> However you're right to discourage him to try that kind of thing.
> Indeed it's highly dependent on the left factorization mechanism
> performed by camlp4.
> 

In other words, the "solution" I have may fail under certain
circumstances? Unfortunately I cannot see what factorization can occur
with the expression "x = HEAP". Can you give me an example?

Thanks to both of you for the feedback,
Hugo F.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html
-~----------~----~----~----~------~----~------~--~---

Reply via email to