* camlp4: how do you write this rule?
@ 2009-03-11 23:21 Joel Reymont
2009-03-12 0:12 ` [Caml-list] " Martin Jambon
0 siblings, 1 reply; 2+ messages in thread
From: Joel Reymont @ 2009-03-11 23:21 UTC (permalink / raw)
To: O'Caml Mailing List
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) ]
];
---
http://tinyco.de
--- Mac & iPhone
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] camlp4: how do you write this rule?
2009-03-11 23:21 camlp4: how do you write this rule? Joel Reymont
@ 2009-03-12 0:12 ` Martin Jambon
0 siblings, 0 replies; 2+ messages in thread
From: Martin Jambon @ 2009-03-12 0:12 UTC (permalink / raw)
To: Joel Reymont; +Cc: O'Caml Mailing List
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/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-03-12 0:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-11 23:21 camlp4: how do you write this rule? Joel Reymont
2009-03-12 0:12 ` [Caml-list] " Martin Jambon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox