123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118(******************************************************************************)(* *)(* Menhir *)(* *)(* Copyright Inria. All rights reserved. This file is distributed under *)(* the terms of the GNU Library General Public License version 2, with a *)(* special exception on linking, as described in the file LICENSE. *)(* *)(******************************************************************************)moduleMake(I:IncrementalEngine.EVERYTHING)(User:sigvalprint:string->unitvalprint_symbol:I.xsymbol->unitvalprint_element:(I.element->unit)optionend)=structletarrow=" -> "letdot="."letspace=" "letnewline="\n"openUseropenI(* Printing a list of symbols. An optional dot is printed at offset
[i] into the list [symbols], if this offset lies between [0] and
the length of the list (included). *)letrecprint_symbolsisymbols=ifi=0thenbeginprintdot;printspace;print_symbols(-1)symbolsendelsebeginmatchsymbolswith|[]->()|symbol::symbols->print_symbolsymbol;printspace;print_symbols(i-1)symbolsend(* Printing an element as a symbol. *)letprint_element_as_symbolelement=matchelementwith|Element(s,_,_,_)->print_symbol(X(incoming_symbols))(* Some of the functions that follow need an element printer. They use
[print_element] if provided by the user; otherwise they use
[print_element_as_symbol]. *)letprint_element=matchprint_elementwith|Someprint_element->print_element|None->print_element_as_symbol(* Printing a stack as a list of symbols. Stack bottom on the left,
stack top on the right. *)letrecprint_stackenv=matchtopenv,popenvwith|Someelement,Someenv->print_stackenv;printspace;print_elementelement|_,_->()letprint_stackenv=print_stackenv;printnewline(* Printing an item. *)letprint_item(prod,i)=print_symbol(lhsprod);printarrow;print_symbolsi(rhsprod);printnewline(* Printing a list of symbols (public version). *)letprint_symbolssymbols=print_symbols(-1)symbols(* Printing a production (without a dot). *)letprint_productionprod=print_item(prod,-1)(* Printing the current LR(1) state. *)letprint_current_stateenv=print"Current LR(1) state: ";matchtopenvwith|None->print"<some initial state>";(* TEMPORARY unsatisfactory *)printnewline|Some(Element(current,_,_,_))->print(string_of_int(numbercurrent));printnewline;List.iterprint_item(itemscurrent)letprint_envenv=print_stackenv;print_current_stateenv;printnewlineend