More about the update of dypgen:

The function define_scheme is called by extend_grammar which is called by a
user action of the parser.

In define_scheme the following block is outdated:

let lhs =
    try dyp.add_nt name "Obj_sexpr"
    with Dyp.Constructor_mismatch _ -> failwith ("CONSTRUCTOR MISMATCH " ^
name)
  in

add_nt is not available anymore. To bind a constructor to a new non terminal
you use Bind_to_cons in the list of parser commands that is returned by the
user action:

    Bind_to_cons [(name,"Obj_sexpr")]

In define_scheme:

    match o with
      | STRING _ ->
        Dyp.Ter Dyp_symbols.t_NAME
      | SCHEME_CODE _ ->
        Dyp.Ter Dyp_symbols.t_NAME

Terminal symbols are now just strings instead of int. The previous code must
be changed:

    match o with
      | STRING _ ->
        Dyp.Ter "NAME"
      | SCHEME_CODE _ ->
        Dyp.Ter "NAME"

Non terminals too became strings:

      | NONTERMINAL (sr,s,p) ->
          let nt = mapnt s in
          let nt =
            try dyp.add_nt nt "Obj_sexpr"
            with Dyp.Constructor_mismatch _ -> failwith ("CONSTRUCTOR
MISMATCH " ^ s)
            | Dyp.Bad_constructor _ -> failwith ("BAD CONSTRUCTOR FOR " ^ s)
          in
          let ntpri = cal_priority priority_data p in
          Dyp.Non_ter (nt,ntpri)

becomes:

      | NONTERMINAL (sr,s,p) ->
          let nt = mapnt s in
          let ntpri = cal_priority p in
          Dyp.Non_ter (nt,ntpri)

and cal_priority must become:

let cal_priority p =
  match p with
  | `No_prio -> No_priority
  | `Eq_prio p -> Eq_priority p
  | `Less_prio p -> Less_priority p
  | `Lesseq_prio p -> Lesseq_priority p
  | `Greater_prio p -> Greater_priority p
  | `Greatereq_prio p -> Greatereq_priority p

Instead of:

let cal_priority priority_data p =
  let cp p =
    try find_priority priority_data p
    with Not_found -> failwith ("Priority " ^ p ^ " not defined!")
  in
  match p with
  | `No_prio -> No_priority
  | `Eq_prio p -> Eq_priority (cp p)
  | `Less_prio p -> Less_priority (cp p)
  | `Lesseq_prio p -> Lesseq_priority (cp p)
  | `Greater_prio p -> Greater_priority (cp p)
  | `Greatereq_prio p -> Greatereq_priority (cp p)

Off course it is probably better to code with the regular variants directly
instead of the polymorphic ones and get rid of cal_priority.

Watch out that in the new code:

      | NONTERMINAL (sr,s,p) ->
          let nt = mapnt s in
          let ntpri = cal_priority p in
          Dyp.Non_ter (nt,ntpri)

The binding of nt to "Obj_sexpr" has disappeared (because it is not done
with add_nt anymore). You must not forget to bind this nt to "Obj_sexpr"
with Bind_to_cons if nt is new. This must be done when the calling user
action returns its parser command list.

This:
      | s ->
        let name = Dyp_symbols.str_token s in
        Dyp.Ter (Dyp_symbols.get_token_name s)
becomes:
      | s -> Dyp.Ter s

This code:

  let priority = match prio with
  | `Default -> Dyp_priority_data.default_priority
  | `Priority p ->
    try find_priority priority_data p
    with Not_found -> clierr sr ("Priority " ^ p ^ " not found")
  in
  let rule  = lhs,(List.map f rhs),priority in

Becomes:

  let priority = match prio with
  | `Default -> "default_priority"
  | `Priority p -> p
  in
  let rule  = lhs,(List.map f rhs),priority,[] in

Remark the empty list at the end of the 4-tuple that makes the rule. It is a
list of options for the rule (it is only useful when the lexer generator is
dypgen see 6.1 of the manual for more info).

In addition to the new rule and the new action, define_scheme and
extend_grammar should return the list of string couples (nt,cons) where nt
is a new non terminal bind to the constructor cons, to allow the user action
to return the appropriate command Bind_to_cons.
------------------------------------------------------------------------------
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to