minor
[prop.git] / tools / test / g0.pcc
blob4b412bf8019ee69ffa8367bc248f2eec1319fd26
1 lexemetype T =
2   and_ | as_ | in_ | datatype_ | type_ | where_ | view_ | public_ | private_ | protected_ 
3 | id_ | functor_ | let_ | defrule_ | if_ | assert_ | retract_ | left_arrow_
4 | colon_dash_ | defclause_ | lexscan_ | lexscanner_ | tokentype_
5 | and_colon_ | or_colon_ | not_colon_ | implies_colon_ | equiv_colon_ | xor_colon_
6 | character_ | integer_ | real_ | string_ | regexp_
7 | and_also_ | or_else_ | left_shift_ | right_shift_
8 | inc_ | dec_ | ge_ | le_ | eq_ | ne_ | dots_
9 | match_ | matchall_ | rewrite_ | reduce_ | case_ | operator_
10 | class_ | struct_ | union_ | exp_
11 | plus_eq_ | minus_eq_ | mult_eq_ | div_eq_ | mod_eq_
12 | or_eq_ | and_eq_ | xor_eq_ | left_shift_eq_ | right_shift_eq_ 
13 | arrow_ | colon_colon_ | int_ | instantiate_ | error_colon_ | eof_colon_ 
14 | before_colon_ | case_insensitive_colon_ | non_backtracking_colon_
15 | contexts_colon_ | lalr1_parse_ | lalr1_parser_
18 %left inc_ dec_
19 %left '.' arrow_
20 %left '*' '/' '%'
21 %left '+' '-'
22 %left left_shift_ right_shift_
23 %left '<' '>' ge_ le_
24 %left eq_ ne_
25 %left '&'
26 %left '^'
27 %left '|'
28 %left and_also_
29 %left or_else_
30 %right '=' plus_eq_ minus_eq_ mult_eq_ div_eq_ mod_eq_
31 %right or_eq_ and_eq_ xor_eq_ left_shift_eq_ right_shift_eq_ 
32 %left colon_colon_
33 %left not_colon_
34 %left and_colon_
35 %left implies_colon_
36 %left xor_colon_
37 %left equiv_colon_
38 %left or_colon_
40 syntax class BigOne {};
42 syntax BigOne {
43 /***************************************************************************
44  *  The start symbol 
45  ***************************************************************************/
46 start:           decl_list      
48 /***************************************************************************
49  *  Declaration list
50  ***************************************************************************/
51 decl_list:      
52 | decl decl_list
55 /***************************************************************************
56  *  Declarations can be either datatype or type declarations, pattern 
57  *  matching or rewriting statements
58  ***************************************************************************/
59 decl:   a_decl 
61 a_decl: data_type 
62         datatype_decl_list where_types ';'      
63 |       token_type 
64         datatype_decl_list where_types ';'      
65 |       instantiate_datatype_decl 
66 |       typep type_decl_list ';' 
67 |       match_decl      
68 |       matchall_decl
69 |       rewrite_decl    
70 |       reduce_decl
71 |       let_decl
72 |       production_decl 
73 |       horn_clause_decl        
74 |       lexscan_decl            
75 |       parse_decl              
76 // |    error ';'               
79 token_type:     tokentype_      
81 data_type:      datatype_       
83 typep:          type_           
86 /***************************************************************************
87  *   Parser generator
88  ***************************************************************************/
89 parse_decl:     lalr1_parse paren_exp '{' parse_rule_list '}'
90                 
93 lalr1_parse:    lalr1_parse_    
96 parse_rule_list: 
97 |               parse_rule parse_rule_list  
98                 
101 parse_rule:     id ':' parse_production_list
102                 ';'
103                 
106 parse_production_list:  parse_production        
107                         
108                 |       parse_production '|' parse_production_list
109                         
110                 ;
112 parse_production:       parse_symbol_list 
115 parse_symbol_list:      
116 |                       parse_symbol parse_symbol_list
117                         
120 parse_symbol:           id              
121 |                       functor         
122 |                       character       
123 |                       '{' 
124                         line_num
125                          
126                         decl_list 
127                          
128                         '}'
129                         
132 line_num:       ;       
134 /***************************************************************************
135  *   Lexical scanner generator
136  ***************************************************************************/
137 lex_dummy:       ;
138 lexscan_decl:   lexscan_tok paren_exp lex_dummy
139                 '{' case_insensitive_opt non_backtracking_opt contexts_opt
140                     before_opt lexscan_rules '}' 
143 contexts_opt:   contexts_colon_ id      
144 |                                       
147 non_backtracking_opt: non_backtracking_colon_                   
148 |                                               
151 case_insensitive_opt: case_insensitive_colon_   
152 |                                               
155 before_opt:     
156 |               before_colon_  '{' 
157                  
158                 decl_list 
159                 
160                 '}'
162                 
164 lexscan_tok:    lexscan_        
167 lexscan_rules:  lexscan_rule                    
168                 
169 |               lexscan_rule lexscan_rules      
170                 
173 lexscan_rule:   casep string_or_wild_card ':'
174                  decl_list 
175 |               casep functor ':'
176                  decl_list 
177 |               casep eof_colon_ 
178                  decl_list 
181 string_or_wild_card:    string  
182                 |       '_'     
183                 ;
185 /***************************************************************************
186  *   Instantiate a datatype 
187  ***************************************************************************/
188 instantiate_datatype_decl: instantiatep datatype_ instantiate_ty_decl_list ';' 
189         
192 instantiate_ty_decl_list: 
193         instantiate_ty_decl
194         
195 |       instantiate_ty_decl ',' instantiate_ty_decl_list
196         
199 instantiate_ty_decl:  
200         id 
201         
202 |       id '<' ty_or_int_list '>'
203         
206 instantiatep:   instantiate_    
209 /***************************************************************************
210  *  Reduction rules
211  ***************************************************************************/
212 reduce_decl:    reduce paren_exp '{' reduction_rules '}'
215 reduce:         reduce_         
218 reduction_rules:        
221 /***************************************************************************
222  *  Rewrite rules
223  ***************************************************************************/
224 rewrite_decl:   rewrite_tok '(' exp ')' '{' body '}'
227 rewrite_tok:    rewrite_        
230 /***************************************************************************
231  *  Datatype declaration list contains a list of mutually recursive 
232  * datatype declarations.
233  ***************************************************************************/
234 datatype_decl_list:     datatype_decl                           
235                         
236 |                       datatype_decl and_ datatype_decl_list   
237                         
240 /***************************************************************************
241  *  An optional list of type declarations may follow datatype declarations
242  ***************************************************************************/
243 where_types:    
244 |               where_ type_ type_decl_list 
247 /***************************************************************************
248  *  Type declarations
249  ***************************************************************************/
250 type_decl_list: type_decl                       
251 |               type_decl and_ type_decl_list   
254 /***************************************************************************
255  *  Type declarations may be used in place of typedef's
256  ***************************************************************************/
257 type_decl:      id '=' ty
258                 
259 |               id '<' template_var_list '>' '=' ty
260                 
263 /***************************************************************************
264  *  A datatype declaration defines the name of the type (which may be
265  *  parametric) followed a list of term declarations. 
266  ***************************************************************************/
267 datatype_decl:  id scope_opt '=' term_decl_list 
268                  view_decl body
269                 
270 |               id '<' template_var_list '>' scope_opt '=' term_decl_list 
271                  view_decl body
272                 
275 scope_opt:                      
276 |               scope           
279 scope:          public_         
280 |               private_        
281 |               protected_      
284 view_decl:      
285 |               viewp view_aliases 
288 viewp:          view_ 
291 view_aliases:   view_alias      
292 |               view_alias '|' view_aliases     
295 view_alias:     term_decl ':' pat       
298 body:           
299 |               scope '{' 
300                  
301                 decl_list 
302                 
303                 '}'
304                 
307 /***************************************************************************
308  *  Termplate variable list
309  ***************************************************************************/
310 template_var_list:      template_var    
311 |                       template_var ',' template_var_list      
312                         
313 ;               
315 /***************************************************************************
316  *  A template variable may be parameterized by type or by an integer
317  ***************************************************************************/
318 template_var:   class_ id       
319 |               id              
320 |               ty id           
323 /***************************************************************************
324  *  Horn clauses
325  ***************************************************************************/
326 horn_clause_decl:  defclause_tok horn_clause_list '.' 
329 defclause_tok:  defclause_      
332 horn_clause_list:       horn_clause     
333 |                       horn_clause and_ horn_clause_list        
336 horn_clause:    clause  
337 |               clause colon_dash_ clause_list  
340 clause:         id pat  
343 clause_list:    clause  
344 |               clause ',' clause_list  
348 /***************************************************************************
350  *   Let declarations
351  *    
352  ***************************************************************************/
353 let_decl:       let_tok
354                 let_exp_list in_
355                 '{'
356                 decl_list 
357                 '}'
360 let_tok:        let_    
363 let_exp_list:   let_exp         
364 |               let_exp and_ let_exp_list       
367 let_exp:        pat '=' paren_exp 
368 |               pat '=' id
371 match_decl:     match_tok match_exp_list 
372                 
373                 '{' rule_list 
374                 '}'
377 matchall_decl:  matchall_tok match_exp_list 
378                 
379                 '{' rule_list 
380                 '}'
383 match_tok:      match_  
385 matchall_tok:   matchall_       
387         
388 match_exp_list: paren_exp                       
389 |               paren_exp and_ match_exp_list   
392 paren_exp:      '('  exp 
393                 
396 rule_list:      rule            
397 |               rule rule_list  
400 rule :          casep pat 
401                 where_opt 
402                 ':'
403                 
404                 decl_list
407 casep:          case_ 
410 production_decl:        defrule_ production_rule_list ';'
412                         
414 production_rule_list:   
415 |                       production_rule production_rule_list
416                         
419 production_rule:        rule_name
420                         antecedent_list 
421                         decl_list 
422                         '}'
425 rule_name:              id ':'          
426 |                       string ':'      
429 antecedent_list:        antecedent 
430                         
431 |                       antecedent ',' antecedent_list
432                         
435 antecedent:     id paren_exp
436 |               id 
437                 where_opt
438 |               id left_arrow_ id 
439                 paren_exp
440 |               '!' 
441                 antecedent      
442                 
445 dots_opt:               
446 |               dots_   
449 where_opt:                        
450 |               where_ paren_exp  
453 simple_pat:     
454         '(' pat ')'                     
455 |       '(' pat_list2 ')'               
456 |       id                              
457 |       id as_ simple_pat               
458 |       functor                         
459 |       functor simple_pat              
460 |       '[' pat_list ']'                
461 |       '`' '[' pat_list dots_opt ']'   
462 |       '{' lab_pat_list '}'
463 |       '(' simple_pat binop_pat pat ')' 
464 |       '(' prefixop simple_pat ')'     
465 |       '(' simple_pat postfixop ')'    
466 |       integer                         
467 |       character                       
468 |       real                            
469 |       string                          
470 |       regexp                          
471 |       '_'                             
472 |       '(' pat ':' ty ')'              
475 pat:    simple_pat                      
476 |       pat and_colon_ pat              
477 |       pat or_colon_ pat               
478 |       pat implies_colon_ pat          
479 |       pat equiv_colon_ pat            
480 |       pat xor_colon_ pat              
481 |       not_colon_ simple_pat           
484 lab_pat_list:                   
485 |               lab_pat_list2   
488 lab_pat_list2:  lab_pat  
489 |               lab_pat ',' lab_pat_list2 
492 lab_pat:        id '=' pat      
493 |               id              
496 pat_list:                       
497 |               pat             
498 |               pat_list2       
501 pat_list2:      pat ',' pat
502                 
503 |               pat ',' pat_list2       
506 class_ty:       class_ class_ty                 
507 |               id                              
508 |               id '<' ty_or_int_list '>'       
511 ty:     class_ty                        
512 |       '(' ty ')'                      
513 |       '(' ty_list ')'                 
514 |       '{' lab_ty_list '}'
515 |       ty '['  exp 
516 |       ty '*'                          
517 |       ty '&'                          
518 |       ty id                           
521 ty_list:        ty ',' ty       
522                 
523 |               ty ',' ty_list  
526 lab_ty_list:    lab_ty                  
527 |               lab_ty ',' lab_ty_list  
530 lab_ty:         id ':' ty       
533 term_decl:      id                      
534 |               id string               
535 |               id '(' ty ')'           
536 |               id '(' ty_list ')'      
537 |               id '{' lab_ty_list '}'
538 |               prefixop ty             
539 |               ty postfixop            
540 |               ty binop ty             
541 |               '(' ty '|' ty ')'       
544 term_decl_list: term_decl                       
545 |               term_decl '|' term_decl_list    
548 prefixop:       '~'                     
549 |               '!'                     
550 |               '-'                     
551 |               inc_                    
552 |               dec_                    
553 |               operator_ prefixop      
556 postfixop:      inc_                    
557 |               dec_                    
558 |               operator_ postfixop     
561 binop_pat:      binop   
562 |               '*'     
563 |               '|'     
564 |               '>'     
565 |               '&'     
568 binop:  '+'                     
569 |       '-'             
570 |       '/'             
571 |       '%'             
572 |       '^'             
573 |       '='             
574 |       ge_             
575 |       le_             
576 |       ne_             
577 |       eq_             
578 |       or_else_        
579 |       and_also_       
580 |       left_shift_     
581 |       right_shift_    
582 |       plus_eq_        
583 |       minus_eq_       
584 |       mult_eq_        
585 |       div_eq_         
586 |       mod_eq_         
587 |       or_eq_          
588 |       and_eq_         
589 |       xor_eq_         
590 |       left_shift_eq_  
591 |       right_shift_eq_ 
592 |       arrow_          
593 |       operator_ '*'   
594 |       operator_ '|'   
595 |       operator_ '>'   
596 |       operator_ '<'   
597 |       operator_ '&'   
598 |       operator_ binop 
601 exp:            exp_    
604 ty_or_int_list: ty_or_int                       
605                 
606 |               ty_or_int ',' ty_or_int_list    
607                 
610 ty_or_int:      ty      
611 |               integer 
614 id:             id_             
617 functor:        functor_        
620 character:      character_      
623 integer:        integer_        
626 real:           real_            
629 string:         string_         
632 regexp:         regexp_