Hello,
On 24-10-2010, OGrandeDiEnne <[email protected]> wrote:
> Hello people,
> i'm writing a small preprocessor for a programming language.
> I need to represent a program parsed tree in order to modify it during
> execution. My basic idea was to define a type for each of grammar
> product; so for example boolean expressions are represented by the
> type:
>
> type bool_expr = (* Represents boolexp and lboolexp *)
> | True
> | False
> | Not of bool_expr
> | And of bool_expr * bool_expr
> | Or of bool_expr * bool_expr ..........
>
> The parsing is done by ocamllex/ocamlyacc which instantiate "objects"
> of those types.
>
> So far so good.
>
> The problem is that i have *mutually recursive productions* in my
> grammar:
>
> ProductionA -> Something | SomethingSomething | ProductionB
>
> ProductionB -> SomethingSomethingSomething | ProductionA
>
> and i can NOT define mutually recursive types in ocaml (as far as i
> understood by: http://pauillac.inria.fr/caml/caml-list/1393.html )
>
> So which is the best solution to implement this ?
> Any comments will be appreciated.
>
The mailing list link is from 1999 (pre-historic age for computer
science).
You can define mutually recursive types:
type bool_expr =
| True
| False
| Funcall of funcall
and funcall =
{
fun_name: string;
fun_args: bool_expr list;
}
You just need to use the "and" between mutually recursive type
definition.
(but maybe I don't understand your question)
And parse it accordingly.
Regards,
Sylvain Le Gall
--
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