src/Pure/Syntax/parser.ML
changeset 80946 b76f64d7d493
parent 80945 584828fa7a97
child 80947 1ba97eb5e5e2
equal deleted inserted replaced
80945:584828fa7a97 80946:b76f64d7d493
   583 local
   583 local
   584 
   584 
   585 fun process_states gram stateset i c states =
   585 fun process_states gram stateset i c states =
   586   let
   586   let
   587     fun process _ [] (Si, Sii) = (Si, Sii)
   587     fun process _ [] (Si, Sii) = (Si, Sii)
   588       | process used (S :: States) (Si, Sii) =
   588       | process used ((S as (info, symbs, ts)) :: States) (Si, Sii) =
   589           (case S of
   589           (case symbs of
   590             (info, Nonterminal (nt, min_prec) :: sa, ts) =>
   590             Nonterminal (nt, min_prec) :: sa =>
   591               let (*predictor operation*)
   591               let (*predictor operation*)
   592                 fun mk_state (rhs, id, prod_prec) = ((nt, prod_prec, id, i), rhs, []);
   592                 fun mk_state (rhs, id, prod_prec) = ((nt, prod_prec, id, i), rhs, []);
   593                 fun movedot_lambda (t, k) = if min_prec <= k then SOME (info, sa, t @ ts) else NONE;
   593                 fun movedot_lambda (t, k) = if min_prec <= k then SOME (info, sa, t @ ts) else NONE;
   594                 val (used', new_states) =
   594                 val (used', new_states) =
   595                   (case Inttab.lookup used nt of
   595                   (case Inttab.lookup used nt of
   607                       let
   607                       let
   608                         val tk_prods = prods_for gram c nt;
   608                         val tk_prods = prods_for gram c nt;
   609                         val States' = map mk_state (get_RHS min_prec tk_prods);
   609                         val States' = map mk_state (get_RHS min_prec tk_prods);
   610                       in (Inttab.update (nt, (min_prec, [])) used, States') end);
   610                       in (Inttab.update (nt, (min_prec, [])) used, States') end);
   611               in process used' (new_states @ States) (S :: Si, Sii) end
   611               in process used' (new_states @ States) (S :: Si, Sii) end
   612           | (info as (_, _, id, _), Terminal a :: sa, ts) => (*scanner operation*)
   612           | Terminal a :: sa => (*scanner operation*)
   613               let
   613               let
       
   614                 val (_, _, id, _) = info;
   614                 val Sii' =
   615                 val Sii' =
   615                   if Lexicon.tokens_match_ord (a, c) <> EQUAL then Sii
   616                   if Lexicon.tokens_match_ord (a, c) <> EQUAL then Sii
   616                   else (*move dot*)
   617                   else (*move dot*)
   617                     let val ts' = if Lexicon.valued_token c orelse id <> "" then Tip c :: ts else ts
   618                     let val ts' = if Lexicon.valued_token c orelse id <> "" then Tip c :: ts else ts
   618                     in (info, sa, ts') :: Sii end;
   619                     in (info, sa, ts') :: Sii end;
   619               in process used States (S :: Si, Sii') end
   620               in process used States (S :: Si, Sii') end
   620           | ((A, prec, id, j), [], ts) => (*completer operation*)
   621           | [] => (*completer operation*)
   621               let
   622               let
       
   623                 val (A, prec, id, j) = info;
   622                 val tt = if id = "" then ts else [Node (id, rev ts)];
   624                 val tt = if id = "" then ts else [Node (id, rev ts)];
   623                 val (used', Slist) =
   625                 val (used', Slist) =
   624                   if j = i then (*lambda production?*)
   626                   if j = i then (*lambda production?*)
   625                     let val (prec', used') = update_trees (A, (tt, prec)) used
   627                     let val (prec', used') = update_trees (A, (tt, prec)) used
   626                     in (used', get_states_lambda A prec prec' Si) end
   628                     in (used', get_states_lambda A prec prec' Si) end