summaryrefslogtreecommitdiff
path: root/web/yacco2/compiler/grammars/rule_lhs_phrase.lex
blob: f5bc58b9c32de79789b036a88c441279f56e100e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
/*
  Copyright Dave Bone 1998 - 2014 
  All Rights Reserved. 
  No part of this document may be reproduced without written consent from the author.
	
FILE:		  rule_lhs_phrase.lex
Dates:		  3 Jun 2004
Purpose:	  parse rule's lhs construct
Output:       T_rule_lhs_phrase
              assorted errors
*/
/@
@i "/usr/local/yacco2/copyright.w"
@** |rule_lhs_phrase| Thread.\fbreak
Parse rule's lhs construct.\fbreak
\fbreak
Example of a rule's lhs to parse:\fbreak
\listing{"/usr/local/yacco2/diagrams+etc/rulelhs.txt"}
This thread is a ``chained procedure call''.
@/
fsm	
(fsm-id "rule_lhs_phrase.lex"
,fsm-filename rule_lhs_phrase
,fsm-namespace NS_rule_lhs_phrase
,fsm-class Crule_lhs_phrase{
  user-prefix-declaration
    using namespace NS_yacco2_terminals;
#include "lint_balls.h"
#include "cweb_or_c_k.h"

#include "identifier.h"
#include "c_string.h"
#include "o2_sdc.h"
  ***
  user-declaration
    public:
    void add_sdc_to_directive(yacco2::CAbs_lr1_sym* Dir,T_syntax_code* Sdc);
    T_rule_lhs_phrase* rule_lhs_phrase_;
  ***
  user-implementation
    void Crule_lhs_phrase::
    add_sdc_to_directive(yacco2::CAbs_lr1_sym* Dir,T_syntax_code* Sdc){
      using namespace NS_yacco2_T_enum;
      using namespace NS_yacco2_terminals;
      yacco2::INT eid = Dir->enumerated_id__;
      switch (eid){
		case T_Enum::T_T_user_declaration_: {
		  T_user_declaration* k = (T_user_declaration*)Dir;
		  k->syntax_code(Sdc);
		  break;
		}      
		case T_Enum::T_T_constructor_: {
		  T_constructor* k = (T_constructor*)Dir;
		  k->syntax_code(Sdc);
		  break;
		}      
		case T_Enum::T_T_destructor_: {
		  T_destructor* k = (T_destructor*)Dir;
		  k->syntax_code(Sdc);
		  break;
		}      
		case T_Enum::T_T_op_: {
		  T_op* k = (T_op*)Dir;
		  k->syntax_code(Sdc);
		  break;
		}      
		case T_Enum::T_T_user_implementation_: {
		  T_user_implementation* k = (T_user_implementation*)Dir;
		  k->syntax_code(Sdc);
		  break;
		}      
		default: {
          CAbs_lr1_sym* sym = new Err_improper_directive;
          sym->set_rc(*Dir,__FILE__,__LINE__);
          RSVP_FSM(sym);
          parser__->set_stop_parse(true);
          return;
   		}      
      }
      rule_lhs_phrase_->add_directive_to_lhs(Dir,parser__);        
    }
  ***
  op
    if(rule_lhs_phrase_ != 0){
      delete rule_lhs_phrase_;
      rule_lhs_phrase_ = 0;
    }
    rule_lhs_phrase_ = new T_rule_lhs_phrase;
    rule_lhs_phrase_->set_rc(*parser__->start_token__,__FILE__,__LINE__);
    AST* t = new AST(*rule_lhs_phrase_);
    rule_lhs_phrase_->phrase_tree(t);
  ***
  constructor
    rule_lhs_phrase_ = 0;
  ***
}
,fsm-version "1.0",fsm-date "24 mar 2004",fsm-debug "false"
,fsm-comments "Parse a rule's ``lhs'' directive.")
parallel-parser	
(	
  parallel-thread-function
    TH_rule_lhs_phrase
  ***
  parallel-la-boundary
    eolr
  ***
)
@"/usr/local/yacco2/compiler/grammars/yacco2_T_includes.T"

rules{
Rrule_lhs_phrase  (){
  -> "#lhs"
  Rlint Rpotential_directives  Rlint {
    op
      Crule_lhs_phrase* fsm = (Crule_lhs_phrase*)rule_info__.parser__->fsm_tbl__;
      RSVP(fsm->rule_lhs_phrase_);
      fsm->rule_lhs_phrase_ = 0;
    ***
    }	
}

Rlhs  (){
  ->  ||| "#lhs" NS_identifier::TH_identifier
  -> ||| |?| NULL{
    op 
      rule_info__.parser__->set_abort_parse(true);       
    ***
    }
}

Rpotential_directives  (){
  ->  |.| // no syntax code: end of subsule
  ->  "{" Rlint Rmust_directive_phrase Rmaybe_more_directives Rclose_brace Rlint
}

Rmust_directive_phrase  (){ 
  ->  Rdirective_cweb_k Rlint Rmust_directive Rsyntax_code Rlint {
    op
      AST* cwebt = sf->p1__->cweb_t_;
      Rmust_directive* dir = sf->p3__;
      Rsyntax_code* sdc = sf->p4__;
      if(cwebt != 0)
        sdc->syntax_code_->add_cweb_marker(cwebt);
      Crule_lhs_phrase* fsm = (Crule_lhs_phrase*)rule_info__.parser__->fsm_tbl__;
      fsm->add_sdc_to_directive(dir->directive_,sdc->syntax_code_);
    ***
    } 
}

Rmust_directive  (
lhs {
  user-declaration
    CAbs_lr1_sym* directive_;
  ***
  constructor
    directive_ = 0;
  ***
 } 
){ 
  ->  ||| "#user-declaration" NS_identifier::TH_identifier { 
    op
      directive_ = sf->p2__;
    ***
    }
  ->  ||| "#user-implementation" NULL { 
    op
      directive_ = sf->p2__;
    ***
    }
  ->  ||| "#constructor" NULL { 
    op
      directive_ = sf->p2__;
    ***
    }
  ->  ||| "#destructor" NULL { 
    op
      directive_ = sf->p2__;
    ***
    }
  ->  ||| "#op" NULL { 
    op
      directive_ = sf->p2__;
    ***
    }
  -> ||| |?| NULL { 
      op
		directive_ = 0;
        sf->p2__->set_auto_delete(true);
        CAbs_lr1_sym* sym = new Err_bad_directive;
        sym->set_rc(*sf->p2__,__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      ***
      }
  ->  |?| { 
      op
        CAbs_lr1_sym* sym = new Err_no_directive_present;
        sym->set_rc(*rule_info__.parser__->current_token(),__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      ***
      }      
}

Rclose_brace  (){
  ->  |?| { 
      op
        CAbs_lr1_sym* sym = new Err_no_close_brace;
        sym->set_rc(*rule_info__.parser__->current_token(),__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      ***
      }
  ->  "}"
}

Rmaybe_more_directives  (){ 
  ->   
  ->  Rmaybe_directive_phrases 
}

Rmaybe_directive_phrases  (){ 
  ->  Rmaybe_directive_phrase 
  ->  Rmaybe_directive_phrases Rmaybe_directive_phrase 
}

Rmaybe_directive_phrase  (){ 
  ->  Rcweb_k Rlint Rdirective Rsyntax_code Rlint {
    op
      AST* cwebt = sf->p1__->cweb_t_;
      Rdirective* dir = sf->p3__;
      Rsyntax_code* sdc = sf->p4__;
      if(cwebt != 0)
        sdc->syntax_code_->add_cweb_marker(cwebt);
      Crule_lhs_phrase* fsm = (Crule_lhs_phrase*)rule_info__.parser__->fsm_tbl__;
      fsm->add_sdc_to_directive(dir->directive_,sdc->syntax_code_);
    ***
    } 
  ->  Rdirective Rsyntax_code Rlint {
    op
      Rdirective* dir = sf->p1__;
      Rsyntax_code* sdc = sf->p2__;
      Crule_lhs_phrase* fsm = (Crule_lhs_phrase*)rule_info__.parser__->fsm_tbl__;
      fsm->add_sdc_to_directive(dir->directive_,sdc->syntax_code_);
    ***
    } 
}

Rdirective_phrase  (){ 
  ->  Rcweb_k Rlint Rdirective Rsyntax_code Rlint {
    op
      AST* cwebt = sf->p1__->cweb_t_;
      Rdirective* dir = sf->p3__;
      Rsyntax_code* sdc = sf->p4__;
      if(cwebt != 0)
        sdc->syntax_code_->add_cweb_marker(cwebt);
      Crule_lhs_phrase* fsm = (Crule_lhs_phrase*)rule_info__.parser__->fsm_tbl__;
      fsm->add_sdc_to_directive(dir->directive_,sdc->syntax_code_);
    ***
    } 
}


Rdirective  (
lhs {
  user-declaration
    CAbs_lr1_sym* directive_;
  ***
  constructor
    directive_ = 0;
  ***
 } 
){ 
  ->  ||| "#user-declaration" NS_identifier::TH_identifier { 
    op
      directive_ = sf->p2__;
    ***
    }
  ->  ||| "#user-implementation" NULL { 
    op
      directive_ = sf->p2__;
    ***
    }
  ->  ||| "#constructor" NULL { 
    op
      directive_ = sf->p2__;
    ***
    }
  ->  ||| "#destructor" NULL { 
    op
      directive_ = sf->p2__;
    ***
    }
  ->  ||| "#op" NULL { 
    op
      directive_ = sf->p2__;
    ***
    }
  -> ||| |?| NULL { 
      op
		directive_ = 0;
        sf->p2__->set_auto_delete(true);
        CAbs_lr1_sym* sym = new Err_bad_directive;
        sym->set_rc(*sf->p2__,__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      ***
      }
}


Rsyntax_code  (
lhs {
  user-declaration
    T_syntax_code* syntax_code_;
  ***
	constructor
	  syntax_code_ = 0;
	***
 } 
){
  -> ||| "syntax-code" NS_o2_sdc::TH_o2_sdc {
      op
        syntax_code_ = sf->p2__;
      ***
      }
  -> ||| |?| NULL { // catcher in the Rye? These are errors
      op
        RSVP(sf->p2__);
        rule_info__.parser__->set_stop_parse(true);
      ***
      }
}

Rlint  (){
  ->  ||| lint NS_lint_balls::TH_lint_balls
  -> 
}

Rcweb_marker  (
lhs {
   user-declaration
     AST* cweb_t_;
   ***
   constructor
     cweb_t_ = 0;
   ***
}
){
 ->  ||| "cweb-comment" NS_cweb_or_c_k::TH_cweb_or_c_k {
    op
        T_cweb_comment* k = sf->p2__;
        AST* cwebk_t_ = new AST(*k);
        cweb_t_ = new AST();
        T_cweb_marker* cw = new T_cweb_marker(cweb_t_);
        cw->set_rc(*k,__FILE__,__LINE__);
      AST::set_content(*cweb_t_,*cw);
        AST::join_pts(*cweb_t_,*cwebk_t_);

    ***
    }
}

Rdirective_cweb_k  (
lhs {
	user-declaration
	  AST* cweb_t_;
	***
	constructor
	  cweb_t_ = 0;
	***
	}
){
  -> 
  ->  ||| "cweb-comment" NS_cweb_or_c_k::TH_cweb_or_c_k {
	op
        T_cweb_comment* k = sf->p2__;
        AST* cwebk_t_ = new AST(*k);
        cweb_t_ = new AST();
        T_cweb_marker* cw = new T_cweb_marker(cweb_t_);
        cw->set_rc(*k,__FILE__,__LINE__);
      AST::set_content(*cweb_t_,*cw);
        AST::join_pts(*cweb_t_,*cwebk_t_);

	***
	}
  ->  ||| "comment-overrun" NULL {
      op 
		RSVP(sf->p2__);
		rule_info__.parser__->set_stop_parse(true); 
      ***
      }      
}

Rcweb_k  (
lhs {
	user-declaration
	  AST* cweb_t_;
	***
	constructor
	  cweb_t_ = 0;
	***
	}
){
 ->  ||| "cweb-comment" NS_cweb_or_c_k::TH_cweb_or_c_k {
	op
        T_cweb_comment* k = sf->p2__;
        AST* cwebk_t_ = new AST(*k);
        cweb_t_ = new AST();
        T_cweb_marker* cw = new T_cweb_marker(cweb_t_);
        cw->set_rc(*k,__FILE__,__LINE__);
      AST::set_content(*cweb_t_,*cw);
        AST::join_pts(*cweb_t_,*cwebk_t_);
	***
	}
  ->  ||| "comment-overrun" NULL {
      op 
		RSVP(sf->p2__);
		rule_info__.parser__->set_stop_parse(true); 
      ***
      }     
}

}// end of rules