summaryrefslogtreecommitdiff
path: root/web/yacco2/compiler/grammars/o2_err_hdlr.lex
blob: 02c5136daf89f259c30709ff598cf66952594716 (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
/*
  Copyright Dave Bone 1998 - 2014
  All Rights Reserved. 
  No part of this document may be reproduced without written consent from the author.
	
FILE:		o2_err_hdlr.lex
Date:	  	8 Jul 2003
Purpose:	grammar to process errors from yacco2
Conduit:	none
Change:		11 Mar 2004 - replace tab with space so that
                          displaced error lines up properly
*/
/@
@i "/usr/local/yacco2/copyright.w"
@** |o2_err_hdlr| grammar.\fbreak
Grammar that processes for printing posted errors from yacco2.
@/
fsm	
(fsm-id "o2_err_hdlr.lex",fsm-filename o2_err_hdlr,fsm-namespace NS_o2_err_hdlr
,fsm-class Co2_err_hdlr
,fsm-version "1.0",fsm-date "8 Jul 2003",fsm-debug "false"
,fsm-comments "Logic sequencer: Print out errors from \\O2.")
@"/usr/local/yacco2/compiler/grammars/yacco2_T_includes.T"
rules{
Ro2_err_hdlr (){
  -> Rerrors eog
  -> eog
}

Rerrors (){
  -> Rerror
  -> Rerrors Rerror
}

Rerror	(
lhs{
  user-declaration
  void error_where(CAbs_lr1_sym* E_sym){
    std::string& ext_fle = yacco2::FILE_TBL__[E_sym->tok_co_ords__.external_file_id__];
    std::string line_of_data;
    std::ifstream ifile;
    ifile.open(ext_fle.c_str());
    if(ifile.good()){
        yacco2::UINT lno(1);yacco2::UINT dlno(E_sym->tok_co_ords__.line_no__);
        for(;lno<=dlno;++lno){
          getline(ifile,line_of_data);
          if(lno == dlno) break;
          line_of_data.clear();
        }      
    }      

    std::string space(" ");
    std::string::size_type f = line_of_data.find_first_of('\t');
    for(;f != std::string::npos;){
     line_of_data.replace(f,1,space);
     f = line_of_data.find_first_of('\t');
    }
    
    yacco2::lrclog << "Error in file#: " << E_sym->tok_co_ords__.external_file_id__
		<< " \"" << ext_fle.c_str() << "\"" << std::endl;
	yacco2::lrclog << line_of_data.c_str() << std::endl;
    std::cout << "Error in file#: " << E_sym->tok_co_ords__.external_file_id__
		<< " \"" << ext_fle.c_str() << "\"" << std::endl;
	std::cout << line_of_data.c_str() << std::endl;
	for(int pos = 1;pos < E_sym->tok_co_ords__.pos_in_line__;++pos){
	 yacco2::lrclog << ' ';
	 std::cout << ' ';
	}
	yacco2::lrclog << '^' << std::endl;
	yacco2::lrclog << "\tfpos: " << E_sym->tok_co_ords__.rc_pos__
		<< " line#: " << E_sym->tok_co_ords__.line_no__
		<< " cpos: " << E_sym->tok_co_ords__.pos_in_line__
		<< std::endl;
	std::cout << '^' << std::endl;
	std::cout << "\tfpos: " << E_sym->tok_co_ords__.rc_pos__
		<< " line#: " << E_sym->tok_co_ords__.line_no__
		<< " cpos: " << E_sym->tok_co_ords__.pos_in_line__
		<< std::endl;
		if(E_sym->tok_co_ords__.who_file__ != 0){
			yacco2::lrclog << "\twho thru it: " << E_sym->tok_co_ords__.who_file__
				<< " line#: " << E_sym->tok_co_ords__.who_line_no__
				<< std::endl;
			std::cout << "\twho thru it: " << E_sym->tok_co_ords__.who_file__
				<< " line#: " << E_sym->tok_co_ords__.who_line_no__
				<< std::endl;
		}
    ifile.close();
  };
  ***
}
){
  -> "nested files exceeded" {
  op
    error_where(sf->p1__);
    yacco2::lrclog << "\t" << sf->p1__->id__
    << " nested number: " << sf->p1__->nested_cnt() << std::endl;
    std::cout << "\t" << sf->p1__->id__
    << " nested number exceeded: " << sf->p1__->nested_cnt() << std::endl;
  ***
  }  
  -> "no end-of-code" {
  op
    error_where(sf->p1__);
    yacco2::lrclog << "\t" << sf->p1__->id__ << std::endl;
    std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }  
  -> "no filename" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }      
  -> "bad filename" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__
   << " filename: \"" << sf->p1__->file_name()->c_str()
   << "\" does not exist" << std::endl;
   std::cout << "\t" << sf->p1__->id__
   << " filename: \"" << sf->p1__->file_name()->c_str()
   << "\" does not exist" << std::endl;
  ***
  }     
  -> "bad cmd-opt" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }       
  -> "bad int-no" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }       
  -> "bad int-no range" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }  
  -> "no int present" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }   
  -> "bad eos" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }           
  -> "bad esc" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }           
  -> "comment-overrun" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__<< std::endl;
   std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }  
  -> "bad char" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }  	
  -> "bad univ-seq" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }
  -> "file-inclusion" "bad filename" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__;
   yacco2::lrclog << " " << sf->p2__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__;
   std::cout << " " << sf->p2__->id__ << std::endl;
  ***
  }
  -> "file-inclusion" "bad esc" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__;
   yacco2::lrclog << " " << sf->p2__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__;
   std::cout << " " << sf->p2__->id__ << std::endl;
  ***
  }
  -> "file-inclusion" "bad eos" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__;
   yacco2::lrclog << " " << sf->p2__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__;
   std::cout << " " << sf->p2__->id__ << std::endl;
  ***
  }
  -> "file-inclusion" "no filename" {
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__;
   yacco2::lrclog << " " << sf->p2__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__;
   std::cout << " " << sf->p2__->id__ << std::endl;
  ***
  }
  -> |+| {// catch balance of errors
  op
   error_where(sf->p1__);
   yacco2::lrclog << "\t" << sf->p1__->id__ << std::endl;
   std::cout << "\t" << sf->p1__->id__ << std::endl;
  ***
  }
}  
}// end of rules