1(* 2 * @TAG(OTHER_PRINCETON_OSS) 3 *) 4(* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi 5 * 6 * $Log$ 7 * Revision 1.1 2006/06/23 03:21:27 michaeln 8 * Changed the names of the files in mlyacclib because I want these files 9 * to move into sigobj, and I don't want name-clashes, particularly with 10 * names like stream.sml. (If you use a parser generated by mlyacc, then 11 * you need to have the files in mlyacclib available too.) 12 * 13 * Revision 1.1 2006/06/22 07:40:27 michaeln 14 * Add a MoscowML compilable implementation of MLyacc, using the MLton sources 15 * as the base. 16 * 17 * Revision 1.1.1.1 1997/01/14 01:38:04 george 18 * Version 109.24 19 * 20 * Revision 1.1.1.1 1996/01/31 16:01:42 george 21 * Version 109 22 * 23 *) 24 25(* functor Join creates a user parser by putting together a Lexer structure, 26 an LrValues structure, and a polymorphic parser structure. Note that 27 the Lexer and LrValues structure must share the type pos (i.e. the type 28 of line numbers), the type svalues for semantic values, and the type 29 of tokens. 30*) 31 32functor Join(structure Lex : LEXER 33 structure ParserData: PARSER_DATA 34 structure LrParser : LR_PARSER 35 sharing ParserData.LrTable = LrParser.LrTable 36 sharing ParserData.Token = LrParser.Token 37 sharing type Lex.UserDeclarations.svalue = ParserData.svalue 38 sharing type Lex.UserDeclarations.pos = ParserData.pos 39 sharing type Lex.UserDeclarations.token = ParserData.Token.token) 40 : PARSER = 41struct 42 structure Token = ParserData.Token 43 structure Stream = LrParser.Stream 44 45 exception ParseError = LrParser.ParseError 46 47 type arg = ParserData.arg 48 type pos = ParserData.pos 49 type result = ParserData.result 50 type svalue = ParserData.svalue 51 val makeLexer = LrParser.Stream.streamify o Lex.makeLexer 52 val parse = fn (lookahead,lexer,error,arg) => 53 (fn (a,b) => (ParserData.Actions.extract a,b)) 54 (LrParser.parse {table = ParserData.table, 55 lexer=lexer, 56 lookahead=lookahead, 57 saction = ParserData.Actions.actions, 58 arg=arg, 59 void= ParserData.Actions.void, 60 ec = {is_keyword = ParserData.EC.is_keyword, 61 noShift = ParserData.EC.noShift, 62 preferred_change = ParserData.EC.preferred_change, 63 errtermvalue = ParserData.EC.errtermvalue, 64 error=error, 65 showTerminal = ParserData.EC.showTerminal, 66 terms = ParserData.EC.terms}} 67 ) 68 val sameToken = Token.sameToken 69end 70 71(* functor JoinWithArg creates a variant of the parser structure produced 72 above. In this case, the makeLexer take an additional argument before 73 yielding a value of type unit -> (svalue,pos) token 74 *) 75 76functor JoinWithArg(structure Lex : ARG_LEXER 77 structure ParserData: PARSER_DATA 78 structure LrParser : LR_PARSER 79 sharing ParserData.LrTable = LrParser.LrTable 80 sharing ParserData.Token = LrParser.Token 81 sharing type Lex.UserDeclarations.svalue = ParserData.svalue 82 sharing type Lex.UserDeclarations.pos = ParserData.pos 83 sharing type Lex.UserDeclarations.token = ParserData.Token.token) 84 : ARG_PARSER = 85struct 86 structure Token = ParserData.Token 87 structure Stream = LrParser.Stream 88 89 exception ParseError = LrParser.ParseError 90 91 type arg = ParserData.arg 92 type lexarg = Lex.UserDeclarations.arg 93 type pos = ParserData.pos 94 type result = ParserData.result 95 type svalue = ParserData.svalue 96 97 val makeLexer = fn s => fn arg => 98 LrParser.Stream.streamify (Lex.makeLexer s arg) 99 val parse = fn (lookahead,lexer,error,arg) => 100 (fn (a,b) => (ParserData.Actions.extract a,b)) 101 (LrParser.parse {table = ParserData.table, 102 lexer=lexer, 103 lookahead=lookahead, 104 saction = ParserData.Actions.actions, 105 arg=arg, 106 void= ParserData.Actions.void, 107 ec = {is_keyword = ParserData.EC.is_keyword, 108 noShift = ParserData.EC.noShift, 109 preferred_change = ParserData.EC.preferred_change, 110 errtermvalue = ParserData.EC.errtermvalue, 111 error=error, 112 showTerminal = ParserData.EC.showTerminal, 113 terms = ParserData.EC.terms}} 114 ) 115 val sameToken = Token.sameToken 116end; 117