Version française
Home     About     Download     Resources     Contact us    
Browse thread
camlp4: how do you write this rule?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Martin Jambon <martin.jambon@e...>
Subject: Re: [Caml-list] camlp4: how do you write this rule?
Joel Reymont wrote:
> I would like my expression rule to parse "1 + 2 points" as "Plus (1,
> Points 2)".
> 
> I currently have the following, with Points right-associative and at the
> bottom, but it doesn't work. Is this something that Camlp4 can handle?
> 
>     Thanks, Joel
> 
> expr:
>   [ ...
>   | LEFTA
>     [ e1 = expr; "Or"; e2 = expr -> Or (e1, e2)
>     | e1 = expr; "And"; e2 = expr -> And (e1, e2)
>     | e1 = expr; "Mod"; e2 = expr -> Mod (e1, e2)
>     | e1 = expr; "*"; e2 = expr -> Mul (e1, e2)
>     | e1 = expr; "/"; e2 = expr -> Div (e1, e2)
>     | "Not"; e = expr -> Not e
>     ]
>   | RIGHTA
>     [ e = expr; [ "Points"; "Point" ]; i = OPT instr -> Points (e, i) ]
>   ];

I'm sure you mean:

[ "Points" | "Point" ]



Martin

-- 
http://mjambon.com/