123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384(**************************************************************************)(* -*- tuareg -*- *)(* *)(* Copyright (C) 2017,2018,2019 Yann Régis-Gianas, Nicolas Jeannerod, *)(* Ralf Treinen. *)(* *)(* This is free software: you can redistribute it and/or modify it *)(* under the terms of the GNU General Public License, version 3. *)(* *)(* Additional terms apply, due to the reproduction of portions of *)(* the POSIX standard. Please refer to the file COPYING for details. *)(**************************************************************************)openParsertypet=|PreWordofstring*CST.word_cst|IoNumberofstring|OperatorofParser.token|EOF|NEWLINEletstring_of_pretoken=function|PreWord(s,_)->Printf.sprintf"PREWORD(%s)"s|IoNumbers->Printf.sprintf"IONUM(%s)"s|Operatort->Printf.sprintf"OPERATOR(%s)"(Token.string_of_tokent)|EOF->"EOF"|NEWLINE->"NEWLINE"letoperators=Hashtbl.(lett=create17inList.iter(fun(sym,tok)->addtsymtok)["&&",AND_IF;"||",OR_IF;";;",DSEMI;"<&",LESSAND;">&",GREATAND;"<>",LESSGREAT;">>",DGREAT;">|",CLOBBER;"|",Pipe;"(",Lparen;")",Rparen;"<",LESS;">",GREAT;";",Semicolon;"&",Uppersand];t)letoptoken_of_strings=tryOperator(Hashtbl.findoperatorss)withNot_found->Printf.eprintf"Internal error: `%s' is not a valid operator token.\n"s;assertfalseletpreword_of_operator=function|AND_IF->"&&"|OR_IF->"||"|DSEMI->";;"|LESSAND->"<&"|GREATAND->">&"|LESSGREAT->"<>"|DGREAT->">>"|CLOBBER->">|"|Pipe->"|"|Lparen->"("|Rparen->")"|LESS->"<"|DLESS_->"<<"|GREAT->">"|Semicolon->";"|Uppersand->"&"|_->assertfalse(* By definition of operators. *)letpreword_of_pretoken=function|IoNumbers->PreWord(s,[WordLiterals])|Operatoro->lets=preword_of_operatoroinPreWord(s,[WordLiterals])|NEWLINE->PreWord("\n",[WordLiteral"\n"])|p->p