summaryrefslogtreecommitdiff
path: root/web/yacco2/o2testdriver/testdriver.w
blob: 410c1d999ada7048518e26d7e0851569ec1ab8cc (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
@q file: testdriver.w@>
%   Copyright Dave Bone 1998 - 2015
%   
%    This Source Code Form is subject to the terms of the Mozilla Public
%    License, v. 2.0. If a copy of the MPL was not distributed with this
%    file, You can obtain one at http://mozilla.org/MPL/2.0/.
%   
\input "eplain"
\input "supp-pdf"
\input"/usr/local/yacco2/diagrams/o2mac.tex"
@i "/yacco2/license.w"
@** Testdriver introduction.\fbreak
Testout the lexical part of \O2.
This is a quick and dirty program originally c++
but now literate? So don't critique me on its sparseness.
Its header files etc are cloned from \O2's implementation.
Its logic is the same pattern as \O2{} program.
Same notes and chords to parsing.

The driver uses the {\bf{test\_components.lex}} grammar to parse and test out the data files inputs.
It is equivalent to \O2's   {\bf{pass3.lex}} token pass without
the other lexical components.
In {\bf{\Whereyacco2/qa}}, there are various dat files acting as exercisers
for testdriver.
{\bf{\Whereyacco2/qa/o2testdriver\_tests.bat}} bash script runs the various tests.

The claim-to-fame for {\bf{test\_components.lex}} is how the {\bf{arbitrator-code}}
is placed within a rule that has direct thread calls.
Rule {\bf{Rtoken}} closures these other rules that directly call threads.
Due to current \O2{} implementation, this is a requirement to gen the arbitrator
procedure.
Why not have a read: {\bf{\Whereyacco2/docs/test\_components.pdf}} with its enlightened comments.


@*2 Append header files for testdriver environment.\fbreak
@<accrue testdriver code@>+=
#include "globals.h"
#include "yacco2_stbl.h"
using namespace yacco2_stbl;
#include "test_components.h"
#include "o2_externs.h"

@** Define variables.\fbreak
@<accrue testdriver code@>+=
int RECURSION_INDEX__(0);

YACCO2_define_trace_variables();
yacco2::TOKEN_GAGGLE P3_tokens;
yacco2::TOKEN_GAGGLE Error_queue;
yacco2::TOKEN_GAGGLE tc_recycle_bin;
T_sym_tbl_report_card report_card;
std::string tc_file_to_compile;
STBL_T_ITEMS_type STBL_T_ITEMS;

yacco2::CHAR T_SW('n');
yacco2::CHAR ERR_SW('n');
yacco2::CHAR PRT_SW('n');
STATES_type LR1_STATES;
LR1_STATES_type LR1_COMMON_STATES;
bool LR1_HEALTH(LR1_COMPATIBLE);
int NO_LR1_STATES(0);
STATES_SET_type VISITED_MERGE_STATES_IN_LA_CALC;
CYCLIC_USE_TBL_type CYCLIC_USE_TABLE;


@** Mainline.\fbreak
@<accrue testdriver code@>+=
int main(int argc, char* argv[]){
cout << "Testdriver start" << endl;
yacco2::lrclog << "Testdriver start" << endl;

LOAD_YACCO2_KEYWORDS_INTO_STBL();

  GET_CMD_LINE(argc,argv,Yacco2_holding_file,Error_queue);
  if(Error_queue.empty()!=true){
	DUMP_ERROR_QUEUE(Error_queue);
	return-1;
  }
YACCO2_PARSE_CMD_LINE
(T_SW,ERR_SW,PRT_SW,tc_file_to_compile,Error_queue);
  
  if(Error_queue.empty()!=true){
    DUMP_ERROR_QUEUE(Error_queue);
    return-1;
  }
  tok_can<std::ifstream> cmd_line(tc_file_to_compile.c_str());
  if(cmd_line.file_ok() == NO){
    cout << "Error occurred file does not exist: " << tc_file_to_compile.c_str() << endl;
    return 1;
  }
  //|yacco2::YACCO2_TH__ = 1;|//watch test\_component.lex parse
  //|yacco2::YACCO2_T__ = 1;|//watch terminals as fetched
  yacco2::YACCO2_AR__ = 1;//watch arbitration
  //|yacco2::YACCO2_MSG__ = 1;|//watch communication between threads
  using namespace NS_test_components;
  Ctest_components tc_fsm;
  Parser tc(tc_fsm,&cmd_line,&P3_tokens,0,&Error_queue,&tc_recycle_bin,0);
  tc.parse();

  yacco2::TOKEN_GAGGLE::iterator i = P3_tokens.begin();
  yacco2::TOKEN_GAGGLE::iterator ie = P3_tokens.end();
  cout << "Dump of P3 tokons" << endl;
  for(int yyy = 1;i != ie;++i){
      CAbs_lr1_sym* sym = *i;
	if(sym == yacco2::PTR_LR1_eog__) continue;
	cout << yyy << ":: " << sym->id() 
		<< " file no: " << sym->external_file_id() 
		<< " line no: " << sym->line_no()
		<< " pos: " << sym->pos_in_line()
		<< endl;
	yacco2::lrclog << yyy << ":: " << sym->id() 
		<< " file no: " << sym->external_file_id() 
		<< " line no: " << sym->line_no()
		<< " pos: " << sym->pos_in_line()
		<< endl;
    ++yyy;
  }
  if(Error_queue.empty()!=true){
    DUMP_ERROR_QUEUE(Error_queue);
    cout << "Testdriver exit" << endl;
    yacco2::lrclog << "Testdriver exit" << endl;
    return-1;
  }
  //  |yacco2::Delete_tokens(Error_queue,true);|
exit:
    cout << "Testdriver exit" << endl;
    yacco2::lrclog << "Testdriver exit" << endl;
  return 0;
}
@*2 Testdriver implementation.\fbreak
Output program to |testdriver.cpp|.
@(testdriver.cpp@>= 
@<accrue testdriver code@>;

@** Index.