summaryrefslogtreecommitdiff
path: root/web/yacco2/diagrams/threadmanualcall.txt
blob: ec1c574d43c7fc2dabe8b36a7176984b3e0a5f3d (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
/*
 file: /yacco2/diagrams+etc/threadmanualcall.txt
 Example of a subrule calling a thread manually.
 Taken from grammar pass3.lex before explicit procedure call of threads
 construct invented.
 The start_manually_parallel_parsing function uses the
 thread's id generated from O2linker as its key to find the thread to launch.
*/
  -> "@" 
  /@
  \Yacco2's pre-processor include directive.\fbreak
 \fbreak
 This demonstrates a nested environment 
 where the grammar uses recursion by 
 calling a function which contains the |pass3| grammar sequence.
 In this example, grammar |pass3| 
 manually calls a thread via
 |start_manually_parallel_parsing| 
 to get its file name to process.
 With the returned ``file-inclusion'' terminal, 
 |PROCESS_INCLUDE_FILE| is called to parse
 the include file: a bom-de-bom-bom bump-and-grind sequence.
 The |use_cnt_| is a global variable that protects
 against the file include recursion of calling self
 until a stack overflow occurs.
 @/
  { 
    op
      using namespace NS_prefile_include;
      using namespace NS_yacco2_T_enum;

      Parser::parse_result result = 
        rule_info__.parser__->
        start_manually_parallel_parsing(ITH_prefile_include.thd_id__);
      if(result == Parser::erred){
          // in this case, it will not happen: here for education
          rule_info__.parser__->set_abort_parse(true);
          return;
      }
      // process returned token
      Caccept_parse& accept_parm = 
           *rule_info__.parser__->arbitrated_token__;
      CAbs_lr1_sym* rtn_tok = accept_parm.accept_token__;
      int id = rtn_tok->enumerated_id__;
      accept_parm.accept_token__ = 0;
      if(id == T_Enum::T_T_file_inclusion_) {			
          T_file_inclusion* finc = (T_file_inclusion*)(rtn_tok);
          CAbs_lr1_sym* err = finc->error_sym();
          if(err != 0) {
            rule_info__.parser__->set_abort_parse(true);
            ADD_TOKEN_TO_ERROR_QUEUE(*finc); 
            ADD_TOKEN_TO_ERROR_QUEUE(*finc->error_sym()); 
            finc->error_sym(0);
            return;
          }
          rule_info__.parser__->
            override_current_token(*accept_parm.la_token__
	                          ,accept_parm.la_token_pos__);
           bool result = 
            PROCESS_INCLUDE_FILE
                (*rule_info__.parser__
		,*finc,*rule_info__.parser__->token_producer__);
          if(result == false){ // exceeded nested file limit
            rule_info__.parser__->set_abort_parse(true);
            return;
          }
          ADD_TOKEN_TO_RECYCLE_BIN(*finc);//file name inside
          return;
      }
      // catch all  errors
      rule_info__.parser__->set_abort_parse(true);
    ***
    }