|
|
1.1 root 1: (* MLPG.GRM: Grammar specification for ml parser generator
2: Created by David Tarditi
3: *)
4: open Misc;
5: %%
6:
7: %eof EOF
8: %right ARROW
9: %left ASTERISK
10:
11: %term DELIMITER | OF | Term | Nonterm | START | COLON | ID of string |
12: UNKNOWN of string | EOF | BAR | PROG of string | PREC of LexValue |
13: PERCENT_EOF | PREC_TAG | HEADER of string | PREFER | IPREFER |
14: KEYWORD | FOR | LBRACE | RBRACE | COMMA | ASTERISK | ARROW |
15: TYVAR of string | IDDOT of string | RPAREN | LPAREN | INT of string |
16: STRUCT | VERBOSE | TO | VAL | EQUAL | BLOCK
17:
18: %nonterm MPC_DECLS of decl_data | MPC_DECL of decl_data |
19: ID_LIST of string list | TRULE of rule list | TRULELIST of rule list |
20: BEGIN | TY of string list |
21: CONSTR_LIST of (constr*constr_data) list |
22: RHSLIST of rhs_data | RULEPREC of string option |
23: SUBST_DECL of (string*string) list |
24: TYPELIST of string list | RECORDLIST of string list |
25: QUALID of string list | LABEL of string
26:
27: %%
28:
29: BEGIN : HEADER MPC_DECLS DELIMITER TRULELIST
30: (make_parser (HEADER,MPC_DECLS,TRULELIST))
31:
32: MPC_DECLS : MPC_DECLS MPC_DECL (join_decls MPC_DECLS MPC_DECL)
33:
34: MPC_DECLS: ({start=NONE,prec=NONE,nonterm=NONE,term=NONE,eof=NONE,
35: prefer=nil,iprefer=nil,keyword=nil,structure'=NONE,
36: verbose=false})
37:
38: MPC_DECL: Term CONSTR_LIST
39: ({ start=NONE,prec=NONE,nonterm=NONE,
40: term = make_tok_dict CONSTR_LIST, eof = NONE,
41: prefer=nil,iprefer=nil,keyword=nil,structure'=NONE,
42: verbose=false})
43:
44: | Nonterm CONSTR_LIST
45: ({ start=NONE,prec=NONE,nonterm=make_tok_dict CONSTR_LIST,
46: term = NONE, eof = NONE,prefer=nil,iprefer=nil,keyword=nil,
47: structure'=NONE,verbose=false})
48: | PREC ID_LIST
49: ({start=NONE,prec=save_prec(ID_LIST1,PREC1),
50: nonterm=NONE,term=NONE,eof=NONE,prefer=nil,iprefer=nil,
51: keyword=nil,structure'=NONE,verbose=false})
52:
53: | START ID
54: ({start=SOME ID,prec=NONE,nonterm=NONE,structure'=NONE,
55: term = NONE, eof = NONE,prefer=nil,iprefer=nil,keyword=nil,
56: verbose=false})
57:
58: | PERCENT_EOF ID
59: ({start=NONE,prec=NONE,nonterm=NONE,term=NONE,eof=SOME ID,
60: prefer=nil,iprefer=nil,keyword=nil,structure'=NONE,
61: verbose=false})
62:
63: | KEYWORD ID_LIST
64: ({start=NONE,prec=NONE,nonterm=NONE,term=NONE,eof=NONE,
65: prefer=nil,iprefer=nil,keyword=ID_LIST1,structure'=NONE,
66: verbose=false})
67:
68: | IPREFER ID_LIST
69: ({start=NONE,prec=NONE,nonterm=NONE,term=NONE,eof=NONE,
70: prefer=nil,iprefer=ID_LIST1,keyword=nil,structure'=NONE,
71: verbose=false})
72:
73: | PREFER SUBST_DECL
74: ({start=NONE,prec=NONE,nonterm=NONE,term=NONE,eof=NONE,
75: prefer=SUBST_DECL1,iprefer=nil,keyword=nil,structure'=NONE,
76: verbose=false})
77:
78: | STRUCT ID
79: ({start=NONE,prec=NONE,nonterm=NONE,term=NONE,eof=NONE,
80: prefer=nil,iprefer=nil,keyword=nil,structure'=SOME ID,
81: verbose=false})
82:
83: | VERBOSE
84: ({start=NONE,prec=NONE,nonterm=NONE,term=NONE,eof=NONE,
85: prefer=nil,iprefer=nil,keyword=nil,structure'=NONE,
86: verbose=true})
87:
88: SUBST_DECL : SUBST_DECL BAR ID FOR ID
89: ((ID1,ID2)::SUBST_DECL)
90:
91: | ID FOR ID
92: ([(ID1,ID2)])
93:
94: CONSTR_LIST : CONSTR_LIST BAR ID OF TY
95: ((ID,{ty=SOME TY,num=0})::CONSTR_LIST)
96:
97: | CONSTR_LIST BAR ID
98: ((ID,{ty=NONE,num=0})::CONSTR_LIST)
99:
100: | ID OF TY ([(ID,{ty=SOME TY,num=0})])
101:
102: | ID ([(ID,{ty=NONE,num=0})])
103:
104: TRULE : ID COLON RHSLIST
105: (map (fn {rhs,code,prec} => {lhs=ID1,rhs=rev rhs,code=code,prec=prec})
106: RHSLIST1)
107:
108: TRULELIST: TRULELIST TRULE (TRULE1 @ TRULELIST1)
109:
110: | (nil)
111:
112: ID_LIST : ID_LIST ID (ID1 :: ID_LIST1)
113:
114: | (nil)
115:
116: RHSLIST : ID_LIST RULEPREC PROG
117: ([{rhs=ID_LIST1,code=PROG1,prec=RULEPREC1}])
118:
119: | RHSLIST BAR ID_LIST RULEPREC PROG
120: ({rhs=ID_LIST1,code=PROG1,prec=RULEPREC1}::RHSLIST1)
121:
122: TY : TYVAR
123: ([TYVAR])
124: | LBRACE RECORDLIST RBRACE
125: ("{ "::RECORDLIST@[" } "])
126: | LBRACE RBRACE
127: (["{ }"])
128: | LPAREN TY RPAREN
129: (" ( "::(TY@[" ) "]))
130: | LPAREN TYPELIST RPAREN QUALID
131: (" ( "::TYPELIST@(" ) "::QUALID))
132: | TY QUALID
133: (TY@(" "::QUALID))
134: | QUALID
135: (QUALID)
136: | TY ASTERISK TY
137: (TY1@("*"::TY2))
138: | TY ARROW TY
139: (TY1@(" -> "::" "::TY2))
140:
141: TYPELIST : TYPELIST COMMA TY
142: (TYPELIST@(","::TY))
143: | TY COMMA TY
144: (TY1 @ ("," :: TY2))
145:
146: RECORDLIST : RECORDLIST COMMA LABEL COLON TY
147: (RECORDLIST@(" "::LABEL::" : "::TY))
148: | LABEL COLON TY
149: (" "::LABEL::" : "::TY)
150:
151: QUALID : ID ([ID])
152: | IDDOT QUALID (IDDOT::QUALID)
153:
154: LABEL : ID (ID)
155: | INT (INT)
156:
157: RULEPREC : PREC_TAG ID (SOME ID1)
158:
159: RULEPREC : (NONE)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.