summaryrefslogtreecommitdiff
path: root/web/yacco2/library/runtime_env.w
blob: 072fc6efea388f2fe4dd19f767e098cb48027b2f (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
@q file: runtime_env.w@>
@q%   Copyright Dave Bone 1998 - 2015@>
@q% /*@>
@q%    This Source Code Form is subject to the terms of the Mozilla Public@>
@q%    License, v. 2.0. If a copy of the MPL was not distributed with this@>
@q%    file, You can obtain one at http://mozilla.org/MPL/2.0/.@>
@q% */@>
@** Yacco2 global variables.\fbreak
A hodge-podge of entities and procedures supporting tracing, files processed with
 recursion support,
threading tables and their first sets,
 low-level character mapping, and low level mutual exclusion controlling
 access to
threads, tracing, and symbol table management.

Access control: Bouncer / doorman.\fbreak
By their name |TRACE_MU|, |MUTEX TH_TBL_MU|, and |MUTEX SYM_TBL_MU|
are mutexes for crowd control for tracing, thread table management, 
and symbol table access.
|THDS_STABLE__| and |THDS_FSET_BY_T__| are data structures generated by
Yacco2's Linker that get resolved to the specific use of this library. 
They are dangling references.

File management:\fbreak
|FILE_TBL__| is a dictionary of file names that 
have been opened during the compile process.
It's key is the file number component to the symbol's GPS in the source file.
|FILE_CNT__| is the current file number being processed.
It starts from 0 due to \CPLUSPLUS/'s vector requirement used by |FILE_TBL__|.
The |tok_can| template containers use these variables: ie,
raw character symbol processing.
|STK_FILE_NOS__| is a stack of nested |FILE_CNT__| file numbers
used to re-establish processing of the file following its include statement.   

@<Type...@>+=
typedef std::vector<std::string> gbl_file_map_type;

@*2 Global variables.
@<Global variables@>+=
extern std::list<std::string> O2_LOGICALS__;
extern std::ofstream lrclog;
extern std::ofstream lrerrors;
extern yacco2::KCHARP Lr1_VERSION;
extern yacco2::KCHARP O2linker_VERSION;
extern yacco2::MUTEX TRACE_MU;
extern yacco2::MUTEX TH_TBL_MU;
extern yacco2::MUTEX SYM_TBL_MU;
extern yacco2::MUTEX TOKEN_MU;
extern yacco2::gbl_file_map_type FILE_TBL__;
extern yacco2::UINT FILE_CNT__;
extern std::vector<yacco2::UINT> STK_FILE_NOS__;
struct rc_map;
extern yacco2::rc_map RC__;


@ |LRK_LA_EOLR_SET|. \fbreak
Used by |find_reduce_entry| for meta termials lookahed set.
Meta-terminals are 8 elements that start off the enumeration scheme. 
  Therefore they all fit within one partition.
\QUEshift, eog, and \PARshift{} are left out of the lookahead set
leaving eolr, \INVshift, \ALLshift,\PROCshift, and \REDshift.

@<Global variables@>+=  
extern yacco2::Set_entry LRK_LA_EOLR_SET;

@ |LRK_LA_QUE_SET| for error enforcement. \fbreak
Used by |find_questionable_sym_in_reduce_lookahead| 
for forced reduce to handle error detection.
It forces the reducing subrule to reduce cuz the
\QUEshift{} symbol in in its follow set.
That is the shifted into parse state for the recuded rule
contains the \QUEshift{} symbol used for error catching.
@<Global variables@>+=  
extern yacco2::Set_entry LRK_LA_QUE_SET;

@*2 Global routines.
@<External rtns and variables@>+=
extern void Delete_tokens(yacco2::TOKEN_GAGGLE& Tks,bool Do_delete=OFF);
extern void Clear_yacco2_opened_files_dictionary();


@*2 Global variables implementations.
@<accrue yacco2 code@>=
std::list<std::string> yacco2::O2_LOGICALS__;
yacco2::gbl_file_map_type yacco2::FILE_TBL__;
std::vector<yacco2::UINT> yacco2::STK_FILE_NOS__;
yacco2::UINT yacco2::FILE_CNT__(0);
yacco2::rc_map yacco2::RC__;
yacco2::Type_pp_fnct_ptr yacco2::PTR_AR_for_manual_thread_spawning(0);
// split lines: cuz Apple's latest compiler bug 
// No matching literal operator for call to 'operator"' date macro 
// with arguments of types 'const char*' and 'unsigned long', and no matching literal operator template 
// 
yacco2::KCHARP 
yacco2::Lr1_VERSION = "O2 version: 1.0 Distribution Date: "@/
 __DATE__ "\n";
yacco2::KCHARP 
yacco2::O2linker_VERSION = "O2linker version: 1.0 Distribution Date: "@/
__DATE__ "\n";

yacco2::MUTEX yacco2::TOKEN_MU;
yacco2::MUTEX yacco2::TRACE_MU;
yacco2::MUTEX yacco2::TH_TBL_MU;
yacco2::MUTEX yacco2::SYM_TBL_MU;
std::ofstream yacco2::lrclog("1lrtracings.log");
std::ofstream yacco2::lrerrors("1lrerrors.log");
yacco2::Set_entry 
yacco2::LRK_LA_EOLR_SET 
 = {0,0xf4};// eolr, \REDshift, \INVshift, \ALLshift, and \PROCshift 
yacco2::Set_entry 
yacco2::LRK_LA_QUE_SET 
 = {0,0x01};// elem 1 is \QUEshift so |2^0|

@*2 Runtime errors.\fbreak
It supplies all the error objects that get thrown
within yacco2's environment. 
Presently, my design is crude: no design but a list of error events.

@<Struct...@>+=
struct Source_info{
   Source_info(yacco2::KCHARP File,yacco2::UINT Line);
   void w_info();
   yacco2::KCHARP file__;
   yacco2::INT line__;
};
struct Yacco2_faulty_precondition:Source_info{
   Yacco2_faulty_precondition(yacco2::KCHARP Message
                                ,yacco2::KCHARP File = __FILE__
                                ,yacco2::UINT Line = __LINE__);
};

struct Yacco2_faulty_postcondition:Source_info{
    Yacco2_faulty_postcondition(yacco2::KCHARP Message
                                  ,yacco2::KCHARP File = __FILE__
                                  ,yacco2::UINT Line = __LINE__);
};

@*2 Runtime error messages implementations. 
@<accrue yacco2 code@>=
   yacco2::
   Source_info::@/
   Source_info(yacco2::KCHARP File,yacco2::UINT Line)
           :file__(File)
           ,line__(Line){
           w_info();
           }
           
   void 
   yacco2::
   Source_info::@/
   w_info(){
           yacco2::lrclog
           << " Version: " << yacco2::Lr1_VERSION
           << " thrown from source file: " << file__
           << " line: " << line__
           << __FILE__ << __LINE__<< std::endl;
           std::cout
           << " Version: " << yacco2::Lr1_VERSION
           << " thrown from source file: " << file__
           << " line: " << line__
           << __FILE__ << __LINE__<< std::endl;
   }

   yacco2::
   Yacco2_faulty_precondition::@/
   Yacco2_faulty_precondition(yacco2::KCHARP Message
                                ,yacco2::KCHARP File
                                ,yacco2::UINT Line)@/
                                :Source_info(File,Line){
    yacco2::lrclog << "Yacco2_faulty_precondition: " << Message << ' ' << __FILE__ << ": " << __LINE__<< std::endl;
    std::cout << "Yacco2_faulty_precondition: " << Message << std::endl;
  }

    yacco2::
    Yacco2_faulty_postcondition::@/
    Yacco2_faulty_postcondition(yacco2::KCHARP Message
                                  ,yacco2::KCHARP File
                                  ,yacco2::UINT Line)@/
                                  :Source_info(File,Line){
      yacco2::lrclog << "Yacco2_faulty_postcondition: " << Message << ' '<< __FILE__ << ": " << __LINE__<< std::endl;
      std::cout << "Yacco2_faulty_postcondition: " << Message << std::endl;
    }


@*2 Global garbage sweeper.\fbreak
Simple container whose contents are deleted.
As one parses, somewhere the newly minted tokens needed to be deleted.
The container maintains a one-to-one reference to the symbol which gets
deleted by this routine.
Due to the ``lr k symbols'' being globally defined in global space rather
than being their creation by the new operator, 
there is protective code to prevent their deletion.

Depending on how the ``Raw Characters'' are built, they could also be bypassed.
For now, the ``global garbage'' sweeper is not very good: a map template just is down
right slow. So I must revisit my thought and come up with a better data structure to
use.

I bypass this routine as the cost of building
the thread index is TOOOOOooo slow and occassionally buggy from
the template implementation.
@^MSN bug pranks.@>
@<Type...@>+=
typedef std::set < yacco2::CAbs_lr1_sym* > set_of_objs_type;
typedef set_of_objs_type::iterator set_of_objs_iter_type;

@*2 |Delete_tokens|.
@<accrue yacco2 code@>=
extern
void yacco2::Delete_tokens(yacco2::TOKEN_GAGGLE& Tks,bool Do_delete){@/
return;
using namespace NS_yacco2_k_symbols;
static yacco2::set_of_objs_type deleted_syms;
static yacco2::set_of_objs_type dont_delete_syms;
static bool onetime(OFF);
if(onetime == OFF){
  onetime = ON;
  dont_delete_syms.insert(PTR_LR1_eolr__);
  dont_delete_syms.insert(PTR_LR1_questionable_shift_operator__);
  dont_delete_syms.insert(PTR_LR1_eog__);
  dont_delete_syms.insert(PTR_LR1_parallel_operator__);
  dont_delete_syms.insert(PTR_LR1_invisible_shift_operator__);
  dont_delete_syms.insert(PTR_LR1_all_shift_operator__);
  dont_delete_syms.insert(PTR_LR1_fset_transience_operator__);
}
  if(Do_delete == ON){
	  set_of_objs_iter_type k = deleted_syms.begin();
	  set_of_objs_iter_type ke = deleted_syms.end();
	  for(;k!=ke;++k){
	    CAbs_lr1_sym* sym = *k;
		///|delete sym;|
	  }
	  return;
  }
  TOKEN_GAGGLE_ITER i = Tks.begin();
  TOKEN_GAGGLE_ITER ie = Tks.end();
  for(;i != ie;++i){
    yacco2::CAbs_lr1_sym* sym = *i;
	yacco2::set_of_objs_iter_type j;
	j = deleted_syms.find(sym);
	if(j != deleted_syms.end()) continue;//already deleted
	j = dont_delete_syms.find(sym);
	if(j != dont_delete_syms.end()) continue;
	deleted_syms.insert(sym);
  }
}

@*2 |Clear_yacco2_opened_files_dictionary|.\fbreak
Allows one to have multiple parse sessions.
This clears the previous parse attempt.
Give me an example of why u need this?
Consider a XML language recognizer that is continuously being called to process a
say Soap session.
Each session is a new parsing bout.
@<accrue yacco2 code@>=
extern
void yacco2::Clear_yacco2_opened_files_dictionary(){@/
 yacco2::FILE_TBL__.clear();
 yacco2::STK_FILE_NOS__.clear();
 yacco2::FILE_CNT__ = 0;

}