let levels_of_rules entry position rules =
                  let elev =
                    match entry.edesc with
                    | Dlevels elev -> elev
                    | Dparser _ ->
                        (eprintf "Error: entry not extensible: \"%s\"\n"
                           entry.ename;
                         flush Pervasives.stderr;
                         failwith "Grammar.extend")
                  in
                    if rules = []
                    then elev
                    else
                      (let (levs1, make_lev, levs2) =
                         get_level entry position elev in
                       let (levs, _) =
                         List.fold_left
                           (fun (levs, make_lev) (lname, assoc, level) ->
                              let lev = make_lev lname assoc in
                              let lev =
                                List.fold_left
                                  (fun lev (symbols, action) ->
                                     let symbols =
                                       List.map (change_to_self entry)
                                         symbols
                                     in
                                       (List.iter (check_gram entry) symbols;
                                        let (e1, symbols) =
                                          get_initial symbols
                                        in
                                          (insert_tokens entry.egram symbols;
                                           insert_level entry e1 symbols
                                             action lev)))
                                  lev level
                              in ((lev :: levs), empty_lev))
                           ([], make_lev) rules
                       in levs1 @ ((List.rev levs) @ levs2))