src/Pure/Syntax/parser.ML
changeset 17221 6cd180204582
parent 17192 0cfbf76ed313
child 17314 04e21a27c0ad
equal deleted inserted replaced
17220:b41d8e290bf8 17221:6cd180204582
   444   | extend_gram (Gram {nt_count, prod_count, tags, chains, lambdas, prods})
   444   | extend_gram (Gram {nt_count, prod_count, tags, chains, lambdas, prods})
   445                 xprods =
   445                 xprods =
   446   let
   446   let
   447     (*Get tag for existing nonterminal or create a new one*)
   447     (*Get tag for existing nonterminal or create a new one*)
   448     fun get_tag nt_count tags nt =
   448     fun get_tag nt_count tags nt =
   449       case Symtab.lookup (tags, nt) of
   449       case Symtab.curried_lookup tags nt of
   450         SOME tag => (nt_count, tags, tag)
   450         SOME tag => (nt_count, tags, tag)
   451       | NONE => (nt_count+1, Symtab.update_new ((nt, nt_count), tags),
   451       | NONE => (nt_count+1, Symtab.curried_update_new (nt, nt_count) tags,
   452                  nt_count);
   452                  nt_count);
   453 
   453 
   454     (*Convert symbols to the form used by the parser;
   454     (*Convert symbols to the form used by the parser;
   455       delimiters and predefined terms are stored as terminals,
   455       delimiters and predefined terms are stored as terminals,
   456       nonterminals are converted to integer tags*)
   456       nonterminals are converted to integer tags*)
   521                               else (gram_b, gram_a)
   521                               else (gram_b, gram_a)
   522       end;
   522       end;
   523 
   523 
   524     (*get existing tag from grammar1 or create a new one*)
   524     (*get existing tag from grammar1 or create a new one*)
   525     fun get_tag nt_count tags nt =
   525     fun get_tag nt_count tags nt =
   526       case Symtab.lookup (tags, nt) of
   526       case Symtab.curried_lookup tags nt of
   527         SOME tag => (nt_count, tags, tag)
   527         SOME tag => (nt_count, tags, tag)
   528       | NONE => (nt_count+1, Symtab.update_new ((nt, nt_count), tags),
   528       | NONE => (nt_count+1, Symtab.curried_update_new (nt, nt_count) tags,
   529                 nt_count)
   529                 nt_count)
   530 
   530 
   531     val ((nt_count1', tags1'), tag_table) =
   531     val ((nt_count1', tags1'), tag_table) =
   532       let val tag_list = Symtab.dest tags2;
   532       let val tag_list = Symtab.dest tags2;
   533 
   533 
   866 fun get_trees l = List.mapPartial (fn (_, _, [pt], _, _, _) => SOME pt | _ => NONE)
   866 fun get_trees l = List.mapPartial (fn (_, _, [pt], _, _, _) => SOME pt | _ => NONE)
   867                             l;
   867                             l;
   868 
   868 
   869 fun earley prods tags chains startsymbol indata =
   869 fun earley prods tags chains startsymbol indata =
   870   let
   870   let
   871     val start_tag = case Symtab.lookup (tags, startsymbol) of
   871     val start_tag = case Symtab.curried_lookup tags startsymbol of
   872                        SOME tag => tag
   872                        SOME tag => tag
   873                      | NONE   => error ("parse: Unknown startsymbol " ^
   873                      | NONE   => error ("parse: Unknown startsymbol " ^
   874                                         quote startsymbol);
   874                                         quote startsymbol);
   875     val S0 = [(~1, 0, [], [Nonterminal (start_tag, 0), Terminal EndToken],
   875     val S0 = [(~1, 0, [], [Nonterminal (start_tag, 0), Terminal EndToken],
   876                "", 0)];
   876                "", 0)];