]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/pxp/pxp/m2parsergen/parser.mly
Initial revision
[helm.git] / helm / DEVEL / pxp / pxp / m2parsergen / parser.mly
1 /* $Id$
2  * ----------------------------------------------------------------------
3  *
4  */
5
6 %{
7   open Ast
8
9 %}
10
11 %token Space
12 %token Token
13 %token Type
14 %token <string> Lname
15 %token <string> Uname
16 %token Separator
17 %token Lparen
18 %token Rparen
19 %token Comma
20 %token Colon
21 %token <string * int * int> Code
22 %token Error
23 %token Alt
24 %token Loop_plus
25 %token Loop_star
26 %token Dollar
27 %token Lbracket
28 %token Rbracket%token Eof
29
30 %start text
31 %type <Ast.text> text
32
33 %%
34
35 text:
36   declarations rules
37     { { text_decls = $1; text_rules = $2; } }
38
39 declarations:
40   declaration declarations
41     { $1 :: $2 }
42 | Separator
43     { [] }
44
45 declaration:
46   Token Uname
47     { D_token $2 }
48 | Token Type Uname
49     { D_typed_token $3 }
50
51 rules:
52   rule rules
53     { $1 :: $2 }
54 | Separator
55     { [] }
56
57 rule:
58   Lname Lparen formal_arguments Colon branches
59     { { rule_name = $1;
60         rule_arguments = $3;
61         rule_branches = $5;
62       }
63     }
64
65 formal_arguments:
66   Rparen
67     { [] }
68 | Lname comma_formal_arguments
69     { $1 :: $2 }
70
71 comma_formal_arguments:
72   Comma Lname comma_formal_arguments
73     { $2 :: $3 }
74 | Rparen
75     { [] }
76
77 branches:
78   branch alt_branches
79     { $1 :: $2 }
80
81 alt_branches:
82   Alt branch alt_branches
83     { $2 :: $3 }
84 |
85     { [] }
86
87 branch:
88   simple_branch
89     { $1 }
90 | Dollar Code simple_branch
91     { { $3 with branch_early_code = $2 } }
92
93 simple_branch:
94   symbol Dollar Code patterns Code opt_error_handler
95     { { branch_selector = $1;
96         branch_early_code = ("",0,0);
97         branch_binding_code = $3;
98         branch_pattern = $4;
99         branch_result_code = $5;
100         branch_error_code = $6;
101       }
102     }
103 | symbol patterns Code opt_error_handler
104     { { branch_selector = $1;
105         branch_early_code = ("",0,0);
106         branch_binding_code = ("", 0, 0);
107         branch_pattern = $2;
108         branch_result_code = $3;
109         branch_error_code = $4;
110       }
111     }
112
113 patterns:
114   pattern patterns
115     { $1 :: $2 }
116
117     { [] }
118
119 pattern:
120   symbol Loop_star
121     { { pat_symbol = $1;
122         pat_modifier = Repetition;
123       }
124     }
125 | symbol Error
126     { { pat_symbol = $1;
127         pat_modifier = Option;
128       }
129     }
130 | symbol
131     { { pat_symbol = $1;
132         pat_modifier = Exact;
133       }
134     }
135
136 symbol:
137   Lname Colon Uname
138     { U_symbol($3, Some $1) }
139 | Lname Colon Lname Lparen actual_arguments 
140     { L_symbol($3, $5, Some $1) }
141 | Lname Colon Lbracket Lname Rbracket Lparen actual_arguments 
142     { L_indirect($4, $7, Some $1) }
143 | Uname
144     { U_symbol($1, None) }
145 | Lname Lparen actual_arguments 
146     { L_symbol($1, $3, None) }
147 | Lbracket Lname Rbracket Lparen actual_arguments 
148     { L_indirect($2, $5, None) }
149
150
151 actual_arguments:
152   Rparen
153     { [] }
154 | Lname comma_actual_arguments
155     { $1 :: $2 }
156
157 comma_actual_arguments:
158   Rparen
159     { [] }
160 | Comma Lname comma_actual_arguments
161     { $2 :: $3 }
162
163 opt_error_handler:
164   Error Code
165     { Some $2 }
166
167     { None }
168
169 %%
170
171 (* ======================================================================
172  * History:
173  * 
174  * $Log$
175  * Revision 1.1  2000/11/17 09:57:32  lpadovan
176  * Initial revision
177  *
178  * Revision 1.4  2000/05/09 00:03:22  gerd
179  *      Added [ ml_name ] symbols, where ml_name is an arbitrary
180  * OCaml identifier.
181  *
182  * Revision 1.3  2000/05/08 22:03:01  gerd
183  *      It is now possible to have a $ {{ }} sequence right BEFORE
184  * the first token. This code is executed just after the first token
185  * has been recognized.
186  *
187  * Revision 1.2  2000/05/06 21:51:46  gerd
188  *      New Dollar tag.
189  *
190  * Revision 1.1  2000/05/06 17:36:17  gerd
191  *      Initial revision.
192  *
193  * 
194  *)