SCM Repository
Annotation of /sml/branches/SMLNJ/src/ml-yacc/lib/join.sml
Parent Directory
|
Revision Log
Revision 8 - (view) (download)
1 : | monnier | 2 | (* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi |
2 : | * | ||
3 : | * $Log$ | ||
4 : | monnier | 8 | * Revision 1.1.1.2 1998/01/18 01:00:08 monnier |
5 : | * *** empty log message *** | ||
6 : | monnier | 2 | * |
7 : | monnier | 8 | * Revision 1.1.1.1 1997/01/14 01:38:04 george |
8 : | * Version 109.24 | ||
9 : | * | ||
10 : | monnier | 2 | * Revision 1.1.1.1 1996/01/31 16:01:42 george |
11 : | * Version 109 | ||
12 : | * | ||
13 : | *) | ||
14 : | |||
15 : | (* functor Join creates a user parser by putting together a Lexer structure, | ||
16 : | an LrValues structure, and a polymorphic parser structure. Note that | ||
17 : | the Lexer and LrValues structure must share the type pos (i.e. the type | ||
18 : | of line numbers), the type svalues for semantic values, and the type | ||
19 : | of tokens. | ||
20 : | *) | ||
21 : | |||
22 : | functor Join(structure Lex : LEXER | ||
23 : | structure ParserData: PARSER_DATA | ||
24 : | structure LrParser : LR_PARSER | ||
25 : | sharing ParserData.LrTable = LrParser.LrTable | ||
26 : | sharing ParserData.Token = LrParser.Token | ||
27 : | sharing type Lex.UserDeclarations.svalue = ParserData.svalue | ||
28 : | sharing type Lex.UserDeclarations.pos = ParserData.pos | ||
29 : | sharing type Lex.UserDeclarations.token = ParserData.Token.token) | ||
30 : | : PARSER = | ||
31 : | struct | ||
32 : | structure Token = ParserData.Token | ||
33 : | structure Stream = LrParser.Stream | ||
34 : | |||
35 : | exception ParseError = LrParser.ParseError | ||
36 : | |||
37 : | type arg = ParserData.arg | ||
38 : | type pos = ParserData.pos | ||
39 : | type result = ParserData.result | ||
40 : | type svalue = ParserData.svalue | ||
41 : | val makeLexer = LrParser.Stream.streamify o Lex.makeLexer | ||
42 : | val parse = fn (lookahead,lexer,error,arg) => | ||
43 : | (fn (a,b) => (ParserData.Actions.extract a,b)) | ||
44 : | (LrParser.parse {table = ParserData.table, | ||
45 : | lexer=lexer, | ||
46 : | lookahead=lookahead, | ||
47 : | saction = ParserData.Actions.actions, | ||
48 : | arg=arg, | ||
49 : | void= ParserData.Actions.void, | ||
50 : | ec = {is_keyword = ParserData.EC.is_keyword, | ||
51 : | noShift = ParserData.EC.noShift, | ||
52 : | preferred_change = ParserData.EC.preferred_change, | ||
53 : | errtermvalue = ParserData.EC.errtermvalue, | ||
54 : | error=error, | ||
55 : | showTerminal = ParserData.EC.showTerminal, | ||
56 : | terms = ParserData.EC.terms}} | ||
57 : | ) | ||
58 : | val sameToken = Token.sameToken | ||
59 : | end | ||
60 : | |||
61 : | (* functor JoinWithArg creates a variant of the parser structure produced | ||
62 : | above. In this case, the makeLexer take an additional argument before | ||
63 : | yielding a value of type unit -> (svalue,pos) token | ||
64 : | *) | ||
65 : | |||
66 : | functor JoinWithArg(structure Lex : ARG_LEXER | ||
67 : | structure ParserData: PARSER_DATA | ||
68 : | structure LrParser : LR_PARSER | ||
69 : | sharing ParserData.LrTable = LrParser.LrTable | ||
70 : | sharing ParserData.Token = LrParser.Token | ||
71 : | sharing type Lex.UserDeclarations.svalue = ParserData.svalue | ||
72 : | sharing type Lex.UserDeclarations.pos = ParserData.pos | ||
73 : | sharing type Lex.UserDeclarations.token = ParserData.Token.token) | ||
74 : | : ARG_PARSER = | ||
75 : | struct | ||
76 : | structure Token = ParserData.Token | ||
77 : | structure Stream = LrParser.Stream | ||
78 : | |||
79 : | exception ParseError = LrParser.ParseError | ||
80 : | |||
81 : | type arg = ParserData.arg | ||
82 : | type lexarg = Lex.UserDeclarations.arg | ||
83 : | type pos = ParserData.pos | ||
84 : | type result = ParserData.result | ||
85 : | type svalue = ParserData.svalue | ||
86 : | |||
87 : | val makeLexer = fn s => fn arg => | ||
88 : | LrParser.Stream.streamify (Lex.makeLexer s arg) | ||
89 : | val parse = fn (lookahead,lexer,error,arg) => | ||
90 : | (fn (a,b) => (ParserData.Actions.extract a,b)) | ||
91 : | (LrParser.parse {table = ParserData.table, | ||
92 : | lexer=lexer, | ||
93 : | lookahead=lookahead, | ||
94 : | saction = ParserData.Actions.actions, | ||
95 : | arg=arg, | ||
96 : | void= ParserData.Actions.void, | ||
97 : | ec = {is_keyword = ParserData.EC.is_keyword, | ||
98 : | noShift = ParserData.EC.noShift, | ||
99 : | preferred_change = ParserData.EC.preferred_change, | ||
100 : | errtermvalue = ParserData.EC.errtermvalue, | ||
101 : | error=error, | ||
102 : | showTerminal = ParserData.EC.showTerminal, | ||
103 : | terms = ParserData.EC.terms}} | ||
104 : | ) | ||
105 : | val sameToken = Token.sameToken | ||
106 : | end; |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |