Debian Codegraph @

lexsrc.l

raw
1 %{
2 /*
3 * The Regina Rexx Interpreter
4 * Copyright (C) 1992-1994 Anders Christensen <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 /*
21 * If you change this file the following has to be done:
22 * - regenerate lexsrc.c using an old version of Flex: 2.5.4. This is
23 * provided by flex-old package. Run: make lexsrc
24 * - change the value of YY_BUF_SIZE to 101000 in lexsrc.c
25 * This value MUST be larger than BUFFERSIZE in rexx.h
26 * It is not set automatically because certain variables
27 * are defined with this value BEFORE rexx.h is included
28 * Increasing this value will slow down parsing a bit.
29 * This value will be blown away if you regenerate lexxsrc.c
30 * from this file.
31 */
32
33 #include "rexx.h"
34 #include "yaccsrc.h"
35 #include <string.h>
36 #include <assert.h>
37 #include <errno.h>
38
39 /* Define ASCII_0_TERMINATES_STRING if you want that ASCII-0 terminates
40 * an input string. Normally this should not happen. Input strings are
41 * terminated by a length encoding. The string {"", length=1} is invalid for
42 * the lexer (ASCII-0 is not allowed) while {"", length=0} is allowed (this
43 * is an empty input).
44 * ASCII_0_TERMINATES_STRING is only(!) for backward compatibility and
45 * shouldn't be used under normal circumstances.
46 * FGC
47 */
48 #define ASCII_0_TERMINATES_STRING
49
50 #ifdef YYLMAX
51 # undef YYLMAX
52 #endif
53 #define YYLMAX BUFFERSIZE
54
55 #ifdef FLEX_SCANNER
56 #undef YY_CHAR
57 #define YY_CHAR YY_CHAR_TYPE
58 #undef YY_INPUT
59 #define YY_INPUT(buf,result,max_size) result=fill_buffer(buf,max_size)
60 #endif
61
62 /* NOTE: Every comment is replaced by a '`' character in the lower input
63 * routines. These should check for such (illegal) characters.
64 */
65 #define MY_ISBLANK(c) (((c)==' ')||((c)=='\t')||((c)=='\v')||((c)=='\f')|| \
66 ((c)=='\r')||((c)=='`'))
67
68 PROTECTION_VAR(regina_parser)
69 /* externals which are protected by regina_parser */
70 internal_parser_type parser_data = {NULL, };
71 int retlength=0 ;
72 char retvalue[BUFFERSIZE] ;
73 unsigned SymbolDetect = 0;
74 /* end of externals protected by regina_parser */
75
76 /* locals, they are protected by regina_parser, too */
77 static int nextline = 1;
78 static int nextstart = 1;
79 static int do_level = 0 ;
80 static int in_numform=0, next_numform=0 ;
81 static int obs_with=0, in_do=0, in_then=0;
82 static int in_parse=0 ;
83 static int in_trace=0, itflag=0 ;
84 static int in_signal=0, in_call=0 ;
85 static enum { not_in_address = 0,
86 in_address_keyword, /* ADDRESS just seen */
87 in_address_main, /* after the first word */
88 in_address_value, /* like main but VALUE was seen */
89 in_address_with} in_address = not_in_address,
90 last_in_address = not_in_address ;
91 static enum {no_seek_with = 0,
92 seek_with_from_parse,
93 seek_with_from_address} seek_with = no_seek_with ;
94 /*
95 * expression_ended is set if a typical expression has ended and the next
96 * token has to be preceeded by a CONCATENATE (abuttal) operator in most
97 * cases.
98 */
99 static int expression_ended=0;
100
101 /*
102 * insert_abuttal is set if the last token was a possible end of an expression.
103 * The next token may need to be preceeded by an additional CONCATENATE
104 * operator under some conditions like not being "in_parse".
105 */
106 static int insert_abuttal=0;
107
108 /*
109 * A symbol may be pending after a CONTATENATE (abuttal) operator has been
110 * returned. This symbol will be stored here. 0 indicates no pending symbol.
111 * ASCII 0 will never been returned, there is no need for another indicator.
112 */
113 static int delayed_symbol=0;
114
115 /*
116 * inhibit_delayed_abuttal can be set only if delayed_symbol has been set,
117 * but not always. An opening parenthesis must have been detected, too.
118 * It inhibits the use of a CONCATENATE (abuttal) operator after the staring
119 * parenthesis. Examples:
120 * CONCATENATE {var_symbol} <-- needs a CONCATENATE, another {var_symbol}
121 * may follow.
122 * CONCATENATE {var_symbol} "(" <-- needs a CONCATENATE, another {var_symbol}
123 * is an expression's start.
124 */
125 static int inhibit_delayed_abuttal=0;
126
127 static char ch;
128 static int kill_this_space=0, kill_next_space=1 ;
129 static int extnextline = -1, extnextstart; /* for a delayed line increment */
130 static int linenr=1 ;
131 static int contline = 0;
132 static int inEOF=0 ;
133 static int singlequote=0, doblequote=0 ;
134 static int firstln=0 ;
135 static int bufptr=0 ;
136 /* Previous bug. 8-bits clean combined with EOF ==> need an int */
137 static int chbuffer[LOOKAHEAD] ;
138 static int ipretflag=0, cch=0 ;
139 static const char *interptr=NULL ;
140 static const char *last_interptr=NULL ;
141 static const char *interptrmax ;
142 static int cchmax = 0 ;
143
144 static YY_CHAR_TYPE *rmspc( YY_CHAR_TYPE *instr ) ;
145 static void set_assignment( char delim );
146 static int process_number_or_const( const char *text, int len );
147 static int process_hex_or_bin_string( char *text, int len, int base );
148 static void compress_string( char *dest, const char *src );
149 static int fill_buffer( char *buf, int max_size ) ;
150 #define SET_NEXTSTART() (nextstart += yyleng)
151
152 #define YY_FATAL_ERROR(s) exiterror( ERR_PROG_UNREADABLE, 1, s )
153 %}
154
155
156 %start comm signal sgtype procd parse then with
157 %start numeric do1 other value1 ifcont signame nmform
158
159 %e 2500
160 %p 17000
161 %k 1500
162 %a 7000
163 %n 1000
164 %o 8000
165
166 %{
167 %}
168
169
170 /*
171 * ANSI 6.2.2 definitions (partially with extensions)
172 */
173 digit [0-9]
174 special [,:;)(]
175 not [\\^~\xAC\xAA]
176 extra [#$@]
177 general [_!?A-Za-z]|{extra}
178 dot [.]
179
180 /*
181 * sigh, we need the reversed classes. flex isn't smart
182 * enough to provide it.
183 * Added "0-9" to notGeneral... to fix bug 724390
184 */
185 notGeneralDot [^_!?A-Za-z0-9#$@.]
186 notGeneralParen [^_!?A-Za-z0-9#$@.(]
187
188 space [ \t]
189 blank [\f\v\r]|{space}
190 EOL ;|\r?\n
191
192 /*
193 * A comment is converted to a sequence of ` signs in the
194 * lower layer
195 */
196 comment [`]
197 between ({blank}|{comment})*
198
199 var_symbol_c {dot}|{digit}|{general}
200 var_symbol {general}{var_symbol_c}*
201 /*
202 * A number is a little bit different to detect signs in the
203 * exponent
204 */
205 const_symbol ({dot}|{digit}){var_symbol_c}*
206 reserved_symbol {dot}[a-zA-Z]+
207 symbol {var_symbol}|{const_symbol}
208
209 mantissa ({dot}?{digit}+)|({digit}+{dot}{digit}*)
210 exponent [eE][-+]?{digit}+
211 /*
212 * read ANSI 6.2.1.1 carefully. We have to check the chars
213 * after the exponent for notGeneralDot below.
214 */
215 number {mantissa}{exponent}?
216
217 hex_digit {digit}|[a-fA-F]
218 bin_digit [0-1]
219 hex_digit_tuple {blank}*{hex_digit}{hex_digit}
220 bin_digit_tuple {blank}*{bin_digit}{bin_digit}{bin_digit}{bin_digit}
221
222 hex_string_start {hex_digit}{hex_digit}?
223 hex_string ({hex_string_start}{hex_digit_tuple}*)?
224 bin_string_start {bin_digit}({bin_digit}({bin_digit}{bin_digit}?)?)?
225 bin_string ({bin_string_start}{bin_digit_tuple}*)?
226
227 text_string '([^']|'')*'|\"([^"]|\"\")*\"
228 mintext_string '([^']|'')+'|\"([^"]|\"\")+\"
229
230 /*
231 * Allow characters for any token in string passed back to TRACE instruction
232 * Fixes bug 3564586.
233 */
234 trace_char {symbol}
235
236 /*
237 * The list of keywords.
238 */
239 key_address [aA][dD][dD][rR][eE][sS][sS]
240 key_arg [aA][rR][gG]
241 key_by [bB][yY]
242 key_call [cC][aA][lL][lL]
243 key_caseless [cC][aA][sS][eE][lL][eE][sS][sS]
244 key_digits [dD][iI][gG][iI][tT][sS]
245 key_do [dD][oO]
246 key_dotline {dot}[lL][iI][nN][eE]
247 key_drop [dD][rR][oO][pP]
248 key_else [eE][lL][sS][eE]
249 key_end [eE][nN][dD]
250 key_engineering [eE][nN][gG][iI][nN][eE][eE][rR][iI][nN][gG]
251 key_error [eE][rR][rR][oO][rR]
252 key_exit [eE][xX][iI][tT]
253 key_expose [eE][xX][pP][oO][sS][eE]
254 key_external [eE][xX][tT][eE][rR][nN][aA][lL]
255 key_failure [fF][aA][iI][lL][uU][rR][eE]
256 key_for [fF][oO][rR]
257 key_forever [fF][oO][rR][eE][vV][eE][rR]
258 key_form [fF][oO][rR][mM]
259 key_fuzz [fF][uU][zZ][zZ]
260 key_halt [hH][aA][lL][tT]
261 key_if [iI][fF]
262 key_interpret [iI][nN][tT][eE][rR][pP][rR][eE][tT]
263 key_iterate [iI][tT][eE][rR][aA][tT][eE]
264 key_leave [lL][eE][aA][vV][eE]
265 key_linein [lL][iI][nN][eE][iI][nN]
266 key_lostdigits [lL][oO][sS][tT][dD][iI][gG][iI][tT][sS]
267 key_lower [lL][oO][wW][eE][rR]
268 key_name [nN][aA][mM][eE]
269 key_nop [nN][oO][pP]
270 key_notready [nN][oO][tT][rR][eE][aA][dD][yY]
271 key_novalue [nN][oO][vV][aA][lL][uU][eE]
272 key_numeric [nN][uU][mM][eE][rR][iI][cC]
273 key_off [oO][fF][fF]
274 key_on [oO][nN]
275 key_options [oO][pP][tT][iI][oO][nN][sS]
276 key_otherwise [oO][tT][hH][eE][rR][wW][iI][sS][eE]
277 key_parse [pP][aA][rR][sS][eE]
278 key_procedure [pP][rR][oO][cC][eE][dD][uU][rR][eE]
279 key_pull [pP][uU][lL][lL]
280 key_push [pP][uU][sS][hH]
281 key_queue [qQ][uU][eE][uU][eE]
282 key_return [rR][eE][tT][uU][rR][nN]
283 key_say [sS][aA][yY]
284 key_scientific [sS][cC][iI][eE][nN][tT][iI][fF][iI][cC]
285 key_select [sS][eE][lL][eE][cC][tT]
286 key_signal [sS][iI][gG][nN][aA][lL]
287 key_source [sS][oO][uU][rR][cC][eE]
288 key_syntax [sS][yY][nN][tT][aA][xX]
289 key_then [tT][hH][eE][nN]
290 key_to [tT][oO]
291 key_trace [tT][rR][aA][cC][eE]
292 key_until [uU][nN][tT][iI][lL]
293 key_upper [uU][pP][pP][eE][rR]
294 key_value [vV][aA][lL][uU][eE]
295 key_var [vV][aA][rR]
296 key_version [vV][eE][rR][sS][iI][oO][nN]
297 key_when [wW][hH][eE][nN]
298 key_while [wW][hH][iI][lL][eE]
299 key_with [wW][iI][tT][hH]
300
301
302 %%
303
304 {
305 if ( delayed_symbol )
306 {
307 int retval;
308 retval = delayed_symbol;
309 delayed_symbol = 0;
310 /*
311 * Pass the meaning of inhibit_delayed_abuttal to the normal algorithm
312 * for automatic abuttal detection.
313 */
314 expression_ended = !inhibit_delayed_abuttal;
315 inhibit_delayed_abuttal = 0;
316 return retval;
317 }
318
319 if (next_numform)
320 {
321 in_numform = 1 ;
322 next_numform = 0 ;
323 }
324 else
325 in_numform = 0 ;
326
327 last_in_address = in_address ; /* just for the "Environment" */
328 /* there can't be an intermediate SPACE between ADDRESS and the next word*/
329 if ( in_address == in_address_keyword )
330 in_address = in_address_main ;
331
332 kill_this_space = kill_next_space ;
333 kill_next_space = 0 ;
334
335
336 if (itflag)
337 {
338 in_trace = 0 ;
339 seek_with = no_seek_with ;
340 }
341 itflag = (in_trace) ;
342
343 if (extnextline != -1)
344 {
345 parser_data.tstart = nextstart = extnextstart;
346 parser_data.tline = nextline = extnextline;
347 extnextline = -1;
348 }
349 else
350 {
351 parser_data.tstart = nextstart ;
352 parser_data.tline = nextline ;
353 }
354 insert_abuttal = expression_ended ;
355 expression_ended = 0 ;
356 }
357
358 {comment}* {
359 SET_NEXTSTART() ; }
360
361 <ifcont>{between}{EOL}{between} {
362 /*
363 * Fixes bug 579597, "[;\r?\n]" instead of "{EOL}" causes the bug.
364 */
365 char *ptr;
366 if ((ptr = strchr(yytext, '\n')) != NULL)
367 {
368 nextstart = yyleng - (int) (ptr - (char *) yytext) ;
369 nextline++ ;
370 if (extnextline != -1)
371 {
372 extnextline++;
373 extnextstart = nextstart; /* fixes bug 938204 */
374 }
375 }
376 else
377 SET_NEXTSTART() ;
378 return STATSEP ; }
379
380 {between}{EOL}{between} {
381 char *ptr;
382 BEGIN comm ;
383 if ( obs_with )
384 {
385 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
386 exiterror( ERR_INVALID_TEMPLATE, 1, yytext ) ;
387 }
388 obs_with = in_do = 0 ;
389 in_signal = in_call = 0 ;
390 in_address = not_in_address;
391 in_parse = 0 ;
392 if ( seek_with == seek_with_from_address )
393 seek_with = no_seek_with ;
394 if ((ptr = strchr(yytext, '\n')) != NULL)
395 {
396 nextstart = yyleng - (int) (ptr - (char *) yytext) ;
397 nextline++ ;
398 if (extnextline != -1)
399 {
400 extnextline++;
401 extnextstart = nextstart; /* fixes bug 938204 */
402 }
403 }
404 else
405 SET_NEXTSTART() ;
406 return STATSEP ; }
407
408 {key_dotline}/{notGeneralDot} {
409 int i;
410 char work[16];
411
412 /* support C-like __LINE__ value */
413 /* determine current source line, and create a numeric literal */
414
415 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
416
417 sprintf (work, "%d", parser_data.tline);
418
419 /* copy back work, right-to-left */
420
421 for (i = strlen (work) - 1; i >= 0; i--)
422 {
423 unput (work[i]);
424 }
425 }
426
427 <comm>{key_address}{between} {
428 BEGIN value1 ; /* Allow a following VALUE keyword */
429 seek_with = seek_with_from_address ;
430 in_address = in_address_keyword ;
431 in_call = 1 ; /* Allow the next words to be given as in CALL. */
432 SET_NEXTSTART() ;
433 return ADDRESS ; }
434
435 <comm>{key_arg}{between} {
436 BEGIN other ;
437 in_parse = 1 ;
438 SET_NEXTSTART() ;
439 return ARG ; }
440
441 <comm>{key_call}{between} {
442 BEGIN signal ;
443 in_call = 1 ;
444 SET_NEXTSTART() ;
445 return CALL ; }
446
447 <comm>{key_do}{between} {
448 BEGIN do1 ;
449 assert( do_level >=0 ) ;
450 do_level++ ;
451 in_do = 1 ;
452 SET_NEXTSTART() ;
453 return DO ; }
454
455 <comm>{key_drop}{between} {
456 BEGIN other ;
457 in_parse = 1 ;
458 SET_NEXTSTART() ;
459 return DROP ; }
460
461 <comm>{key_else}{between} {
462 BEGIN comm ;
463 SET_NEXTSTART() ;
464 return ELSE ; }
465
466 <comm>{key_exit}{between} {
467 BEGIN other ;
468 SET_NEXTSTART() ;
469 return EXIT ; }
470
471 <comm>{key_if}{between} {
472 BEGIN ifcont ;
473 in_then = 1 ;
474 parser_data.if_linenr = linenr - 1;
475 SET_NEXTSTART() ;
476 return IF ; }
477
478 <comm>{key_interpret}{between} {
479 BEGIN other ;
480 SET_NEXTSTART() ;
481 return INTERPRET ; }
482
483 <comm>{key_iterate}{between} {
484 BEGIN other ;
485 SET_NEXTSTART() ;
486 return ITERATE ; }
487
488 <comm>{key_leave}{between} {
489 BEGIN other ;
490 SET_NEXTSTART() ;
491 return LEAVE ; }
492
493 <comm>{key_options}{between} {
494 BEGIN other ;
495 SET_NEXTSTART() ;
496 return OPTIONS ; }
497
498 <comm>{key_nop}{between} {
499 BEGIN other ;
500 SET_NEXTSTART() ;
501 return NOP ; }
502
503 <comm>{key_numeric}{between} {
504 BEGIN numeric ;
505 SET_NEXTSTART() ;
506 return NUMERIC ; }
507
508 <comm>{key_parse}{between} {
509 BEGIN parse ;
510 in_parse = 1 ;
511 SET_NEXTSTART() ;
512 return PARSE ; }
513
514 <comm>{key_procedure}{between} {
515 BEGIN procd ;
516 SET_NEXTSTART() ;
517 return PROCEDURE ; }
518
519 <comm>{key_pull}{between} {
520 BEGIN other ;
521 in_parse = 1 ;
522 SET_NEXTSTART() ;
523 return PULL ; }
524
525 <comm>{key_push}{between} {
526 BEGIN other ;
527 SET_NEXTSTART() ;
528 return PUSH ; }
529
530 <comm>{key_queue}{between} {
531 BEGIN other ;
532 SET_NEXTSTART() ;
533 return QUEUE ; }
534
535 <comm>{key_return}{between} {
536 BEGIN other ;
537 SET_NEXTSTART() ;
538 return RETURN ; }
539
540 <comm>{key_say}{between} {
541 BEGIN other ;
542 SET_NEXTSTART() ;
543 return SAY ; }
544
545 <comm>{key_select}{between} {
546 BEGIN other ;
547 assert( do_level >= 0 ) ;
548 do_level++ ; parser_data.select_linenr = linenr - 1;
549 SET_NEXTSTART() ;
550 return SELECT ; }
551
552 <comm>{key_signal}{between} {
553 BEGIN signal ;
554 in_signal = 1 ;
555 SET_NEXTSTART() ;
556 return SIGNAL ; }
557
558 <comm>{key_trace}{between} {
559 BEGIN value1 ;
560 in_trace = 1 ;
561 SET_NEXTSTART() ;
562 return TRACE ; }
563
564 <comm>{key_upper}{between} {
565 BEGIN other ;
566 in_parse = 1 ;
567 SET_NEXTSTART() ;
568 return UPPER ; }
569
570 <comm>{key_when}{between} {
571 BEGIN ifcont ;
572 in_then = 1 ;
573 parser_data.when_linenr = linenr - 1;
574 SET_NEXTSTART() ;
575 return WHEN ; }
576
577 <comm>{key_otherwise}{between} {
578 BEGIN comm ;
579 SET_NEXTSTART() ;
580 return OTHERWISE ; }
581
582 <comm>{key_end}{between} {
583 BEGIN other ;
584 assert( do_level >= 0 ) ;
585 if ( !do_level )
586 {
587 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
588 exiterror( ERR_UNMATCHED_END, 1 ) ;
589 }
590 do_level-- ;
591 SET_NEXTSTART() ;
592 return END ; }
593
594 {between} {
595 if (in_parse)
596 {
597 SET_NEXTSTART() ;
598 return yylex() ;
599 }
600 else
601 REJECT ; }
602
603 \. {
604 if (in_parse)
605 {
606 SET_NEXTSTART() ;
607 return PLACEHOLDER ;
608 }
609 else
610 {
611 REJECT ;
612 }
613 }
614
615 <comm>{const_symbol}{between}={between} {
616 /* .var = */
617 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
618 if ( yytext[0] == '.' )
619 {
620 set_assignment( '=' );
621 /*
622 * FIXME, FGC: ANSI 6.2.3.1 forces an error 50.1 if yytext[0]=='.'
623 * ANSI 6.3.2.8 forces this error 31.3 which is wrong
624 * in its content.
625 * We use 6.2.3.1
626 */
627 if ( !KNOWN_RESERVED( retvalue, retlength ) )
628 {
629 yytext[retlength] = '\0';
630 exiterror( ERR_RESERVED_SYMBOL, 1, yytext );
631 }
632 else
633 {
634 yytext[retlength] = '\0';
635 exiterror( ERR_INVALID_START, 3, yytext );
636 }
637 }
638 else
639 {
640 yytext[retlength] = '\0';
641 exiterror( ERR_INVALID_START, 2, yytext );
642 }
643 /* known reserved variable */
644 SET_NEXTSTART() ;
645 return ASSIGNMENTVARIABLE ; }
646
647 <comm>{var_symbol}{between}={between} {
648 /* var = */
649 BEGIN other ;
650
651 set_assignment( '=' );
652
653 SET_NEXTSTART() ;
654 return ASSIGNMENTVARIABLE ; }
655
656 <comm>{const_symbol}{between}\+{blank}*={between} {
657 /* .var += */
658 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
659 if ( yytext[0] == '.' )
660 {
661 set_assignment( '+' );
662 /*
663 * FIXME, FGC: ANSI 6.2.3.1 forces an error 50.1 if yytext[0]=='.'
664 * ANSI 6.3.2.8 forces this error 31.3 which is wrong
665 * in its content.
666 * We use 6.2.3.1
667 */
668 if ( !KNOWN_RESERVED( retvalue, retlength ) )
669 {
670 yytext[retlength] = '\0';
671 exiterror( ERR_RESERVED_SYMBOL, 1, yytext );
672 }
673 else
674 {
675 yytext[retlength] = '\0';
676 exiterror( ERR_INVALID_START, 3, yytext );
677 }
678 }
679 else
680 {
681 yytext[retlength] = '\0';
682 exiterror( ERR_INVALID_START, 2, yytext );
683 }
684 /* known reserved variable */
685 SET_NEXTSTART() ;
686 return PLUSASSIGNMENTVARIABLE ; }
687
688 <comm>{var_symbol}{between}\+{blank}*={between} {
689 /* var += */
690 BEGIN other ;
691
692 set_assignment( '+' );
693
694 SET_NEXTSTART() ;
695 return PLUSASSIGNMENTVARIABLE ; }
696
697 <comm>{const_symbol}{between}\-{blank}*={between} {
698 /* .var -= */
699 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
700 if ( yytext[0] == '.' )
701 {
702 set_assignment( '-' );
703 /*
704 * FIXME, FGC: ANSI 6.2.3.1 forces an error 50.1 if yytext[0]=='.'
705 * ANSI 6.3.2.8 forces this error 31.3 which is wrong
706 * in its content.
707 * We use 6.2.3.1
708 */
709 if ( !KNOWN_RESERVED( retvalue, retlength ) )
710 {
711 yytext[retlength] = '\0';
712 exiterror( ERR_RESERVED_SYMBOL, 1, yytext );
713 }
714 else
715 {
716 yytext[retlength] = '\0';
717 exiterror( ERR_INVALID_START, 3, yytext );
718 }
719 }
720 else
721 {
722 yytext[retlength] = '\0';
723 exiterror( ERR_INVALID_START, 2, yytext );
724 }
725 /* known reserved variable */
726 SET_NEXTSTART() ;
727 return MINUSASSIGNMENTVARIABLE ; }
728
729 <comm>{var_symbol}{between}\-{blank}*={between} {
730 /* var -= */
731 BEGIN other ;
732
733 set_assignment( '-' );
734
735 SET_NEXTSTART() ;
736 return MINUSASSIGNMENTVARIABLE ; }
737
738 <comm>{const_symbol}{between}\*{blank}*={between} {
739 /* .var *= */
740 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
741 if ( yytext[0] == '.' )
742 {
743 set_assignment( '*' );
744 /*
745 * FIXME, FGC: ANSI 6.2.3.1 forces an error 50.1 if yytext[0]=='.'
746 * ANSI 6.3.2.8 forces this error 31.3 which is wrong
747 * in its content.
748 * We use 6.2.3.1
749 */
750 if ( !KNOWN_RESERVED( retvalue, retlength ) )
751 {
752 yytext[retlength] = '\0';
753 exiterror( ERR_RESERVED_SYMBOL, 1, yytext );
754 }
755 else
756 {
757 yytext[retlength] = '\0';
758 exiterror( ERR_INVALID_START, 3, yytext );
759 }
760 }
761 else
762 {
763 yytext[retlength] = '\0';
764 exiterror( ERR_INVALID_START, 2, yytext );
765 }
766 /* known reserved variable */
767 SET_NEXTSTART() ;
768 return MULTASSIGNMENTVARIABLE ; }
769
770 <comm>{var_symbol}{between}\*{blank}*={between} {
771 /* var *= */
772 BEGIN other ;
773
774 set_assignment( '*' );
775
776 SET_NEXTSTART() ;
777 return MULTASSIGNMENTVARIABLE ; }
778
779 <comm>{const_symbol}{between}\/{blank}*={between} {
780 /* .var /= */
781 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
782 if ( yytext[0] == '.' )
783 {
784 set_assignment( '/' );
785 /*
786 * FIXME, FGC: ANSI 6.2.3.1 forces an error 50.1 if yytext[0]=='.'
787 * ANSI 6.3.2.8 forces this error 31.3 which is wrong
788 * in its content.
789 * We use 6.2.3.1
790 */
791 if ( !KNOWN_RESERVED( retvalue, retlength ) )
792 {
793 yytext[retlength] = '\0';
794 exiterror( ERR_RESERVED_SYMBOL, 1, yytext );
795 }
796 else
797 {
798 yytext[retlength] = '\0';
799 exiterror( ERR_INVALID_START, 3, yytext );
800 }
801 }
802 else
803 {
804 yytext[retlength] = '\0';
805 exiterror( ERR_INVALID_START, 2, yytext );
806 }
807 /* known reserved variable */
808 SET_NEXTSTART() ;
809 return DIVASSIGNMENTVARIABLE ; }
810
811 <comm>{var_symbol}{between}\/{blank}*={between} {
812 /* var /= */
813 BEGIN other ;
814
815 set_assignment( '/' );
816
817 SET_NEXTSTART() ;
818 return DIVASSIGNMENTVARIABLE ; }
819
820 <comm>{const_symbol}{between}\%{blank}*={between} {
821 /* .var %= */
822 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
823 if ( yytext[0] == '.' )
824 {
825 set_assignment( '%' );
826 /*
827 * FIXME, FGC: ANSI 6.2.3.1 forces an error 50.1 if yytext[0]=='.'
828 * ANSI 6.3.2.8 forces this error 31.3 which is wrong
829 * in its content.
830 * We use 6.2.3.1
831 */
832 if ( !KNOWN_RESERVED( retvalue, retlength ) )
833 {
834 yytext[retlength] = '\0';
835 exiterror( ERR_RESERVED_SYMBOL, 1, yytext );
836 }
837 else
838 {
839 yytext[retlength] = '\0';
840 exiterror( ERR_INVALID_START, 3, yytext );
841 }
842 }
843 else
844 {
845 yytext[retlength] = '\0';
846 exiterror( ERR_INVALID_START, 2, yytext );
847 }
848 /* known reserved variable */
849 SET_NEXTSTART() ;
850 return INTDIVASSIGNMENTVARIABLE ; }
851
852 <comm>{var_symbol}{between}\%{blank}*={between} {
853 /* var %= */
854 BEGIN other ;
855
856 set_assignment( '%' );
857
858 SET_NEXTSTART() ;
859 return INTDIVASSIGNMENTVARIABLE ; }
860
861 <comm>{const_symbol}{between}\/{blank}*\/{blank}*={between} {
862 /* .var //= */
863 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
864 if ( yytext[0] == '.' )
865 {
866 set_assignment( '/' );
867 /*
868 * FIXME, FGC: ANSI 6.2.3.1 forces an error 50.1 if yytext[0]=='.'
869 * ANSI 6.3.2.8 forces this error 31.3 which is wrong
870 * in its content.
871 * We use 6.2.3.1
872 */
873 if ( !KNOWN_RESERVED( retvalue, retlength ) )
874 {
875 yytext[retlength] = '\0';
876 exiterror( ERR_RESERVED_SYMBOL, 1, yytext );
877 }
878 else
879 {
880 yytext[retlength] = '\0';
881 exiterror( ERR_INVALID_START, 3, yytext );
882 }
883 }
884 else
885 {
886 yytext[retlength] = '\0';
887 exiterror( ERR_INVALID_START, 2, yytext );
888 }
889 /* known reserved variable */
890 SET_NEXTSTART() ;
891 return MODULUSASSIGNMENTVARIABLE ; }
892
893 <comm>{var_symbol}{between}\/{blank}*\/{blank}*={between} {
894 /* var //= */
895 BEGIN other ;
896
897 set_assignment( '/' );
898
899 SET_NEXTSTART() ;
900 return MODULUSASSIGNMENTVARIABLE ; }
901
902 <comm>{const_symbol}{between}\|{blank}*={between} {
903 /* .var |= */
904 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
905 if ( yytext[0] == '.' )
906 {
907 set_assignment( '|' );
908 /*
909 * FIXME, FGC: ANSI 6.2.3.1 forces an error 50.1 if yytext[0]=='.'
910 * ANSI 6.3.2.8 forces this error 31.3 which is wrong
911 * in its content.
912 * We use 6.2.3.1
913 */
914 if ( !KNOWN_RESERVED( retvalue, retlength ) )
915 {
916 yytext[retlength] = '\0';
917 exiterror( ERR_RESERVED_SYMBOL, 1, yytext );
918 }
919 else
920 {
921 yytext[retlength] = '\0';
922 exiterror( ERR_INVALID_START, 3, yytext );
923 }
924 }
925 else
926 {
927 yytext[retlength] = '\0';
928 exiterror( ERR_INVALID_START, 2, yytext );
929 }
930 /* known reserved variable */
931 SET_NEXTSTART() ;
932 return ORASSIGNMENTVARIABLE ; }
933
934 <comm>{var_symbol}{between}\|{blank}*={between} {
935 /* var |= */
936 BEGIN other ;
937
938 set_assignment( '|' );
939
940 SET_NEXTSTART() ;
941 return ORASSIGNMENTVARIABLE ; }
942
943 <comm>{const_symbol}{between}\&{blank}*={between} {
944 /* .var &= */
945 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
946 if ( yytext[0] == '.' )
947 {
948 set_assignment( '&' );
949 /*
950 * FIXME, FGC: ANSI 6.2.3.1 forces an error 50.1 if yytext[0]=='.'
951 * ANSI 6.3.2.8 forces this error 31.3 which is wrong
952 * in its content.
953 * We use 6.2.3.1
954 */
955 if ( !KNOWN_RESERVED( retvalue, retlength ) )
956 {
957 yytext[retlength] = '\0';
958 exiterror( ERR_RESERVED_SYMBOL, 1, yytext );
959 }
960 else
961 {
962 yytext[retlength] = '\0';
963 exiterror( ERR_INVALID_START, 3, yytext );
964 }
965 }
966 else
967 {
968 yytext[retlength] = '\0';
969 exiterror( ERR_INVALID_START, 2, yytext );
970 }
971 /* known reserved variable */
972 SET_NEXTSTART() ;
973 return ANDASSIGNMENTVARIABLE ; }
974
975 <comm>{var_symbol}{between}\&{blank}*={between} {
976 /* var &= */
977 BEGIN other ;
978
979 set_assignment( '&' );
980
981 SET_NEXTSTART() ;
982 return ANDASSIGNMENTVARIABLE ; }
983
984 <comm>{const_symbol}{between}\&{blank}*\&{blank}*={between} {
985 /* .var &&= */
986 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
987 if ( yytext[0] == '.' )
988 {
989 set_assignment( '&' );
990 /*
991 * FIXME, FGC: ANSI 6.2.3.1 forces an error 50.1 if yytext[0]=='.'
992 * ANSI 6.3.2.8 forces this error 31.3 which is wrong
993 * in its content.
994 * We use 6.2.3.1
995 */
996 if ( !KNOWN_RESERVED( retvalue, retlength ) )
997 {
998 yytext[retlength] = '\0';
999 exiterror( ERR_RESERVED_SYMBOL, 1, yytext );
1000 }
1001 else
1002 {
1003 yytext[retlength] = '\0';
1004 exiterror( ERR_INVALID_START, 3, yytext );
1005 }
1006 }
1007 else
1008 {
1009 yytext[retlength] = '\0';
1010 exiterror( ERR_INVALID_START, 2, yytext );
1011 }
1012 /* known reserved variable */
1013 SET_NEXTSTART() ;
1014 return XORASSIGNMENTVARIABLE ; }
1015
1016 <comm>{var_symbol}{between}\&{blank}*\&{blank}*={between} {
1017 /* var &&= */
1018 BEGIN other ;
1019
1020 set_assignment( '&' );
1021
1022 SET_NEXTSTART() ;
1023 return XORASSIGNMENTVARIABLE ; }
1024
1025 <comm>{const_symbol}{between}\|{blank}*\|{blank}*={between} {
1026 /* .var ||= */
1027 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1028 if ( yytext[0] == '.' )
1029 {
1030 set_assignment( '|' );
1031 /*
1032 * FIXME, FGC: ANSI 6.2.3.1 forces an error 50.1 if yytext[0]=='.'
1033 * ANSI 6.3.2.8 forces this error 31.3 which is wrong
1034 * in its content.
1035 * We use 6.2.3.1
1036 */
1037 if ( !KNOWN_RESERVED( retvalue, retlength ) )
1038 {
1039 yytext[retlength] = '\0';
1040 exiterror( ERR_RESERVED_SYMBOL, 1, yytext );
1041 }
1042 else
1043 {
1044 yytext[retlength] = '\0';
1045 exiterror( ERR_INVALID_START, 3, yytext );
1046 }
1047 }
1048 else
1049 {
1050 yytext[retlength] = '\0';
1051 exiterror( ERR_INVALID_START, 2, yytext );
1052 }
1053 /* known reserved variable */
1054 SET_NEXTSTART() ;
1055 return CONCATASSIGNMENTVARIABLE ; }
1056
1057 <comm>{var_symbol}{between}\|{blank}*\|{blank}*={between} {
1058 /* var ||= */
1059 BEGIN other ;
1060
1061 set_assignment( '|' );
1062
1063 SET_NEXTSTART() ;
1064 return CONCATASSIGNMENTVARIABLE ; }
1065
1066 <nmform,signal,value1>{between}{key_value}{between} {
1067 if (in_call)
1068 {
1069 if ( ( last_in_address == in_address_keyword )
1070 && ( in_address == in_address_main ) )
1071 {
1072 BEGIN other ; /* the next useful expression will set it to "other"
1073 * in either case. The BEGIN-states aren't very
1074 * handy in most cases; they are not flexible enough.
1075 */
1076 in_address = in_address_value ;
1077 in_call = 0;
1078 SET_NEXTSTART() ;
1079 return VALUE ;
1080 }
1081 REJECT ;
1082 }
1083 BEGIN other ;
1084 if ((!in_trace)&&(!in_address)&&(!in_signal)&&(!in_call)&&(!in_numform))
1085 obs_with = 1 ;
1086 in_trace = in_signal = in_call = 0 ;
1087 SET_NEXTSTART() ;
1088 return VALUE ; }
1089
1090 <signal>{key_on}{between} {
1091 BEGIN sgtype ;
1092 SET_NEXTSTART() ;
1093 return ON ; }
1094
1095 <signal>{key_off}{between} {
1096 BEGIN sgtype ;
1097 SET_NEXTSTART() ;
1098 return OFF ; }
1099
1100 <signame>{key_name}{between} {
1101 BEGIN other ;
1102 SET_NEXTSTART() ;
1103 return NAME ; }
1104
1105 <sgtype>{key_error}{between} {
1106 BEGIN signame ;
1107 SET_NEXTSTART() ;
1108 return ERROR ; }
1109
1110 <sgtype>{key_halt}{between} {
1111 BEGIN signame ;
1112 SET_NEXTSTART() ;
1113 return HALT ; }
1114
1115 <sgtype>{key_novalue}{between} {
1116 BEGIN signame ;
1117 SET_NEXTSTART() ;
1118 return NOVALUE ; }
1119
1120 <sgtype>{key_notready}{between} {
1121 BEGIN signame ;
1122 SET_NEXTSTART() ;
1123 return NOTREADY ; }
1124
1125 <sgtype>{key_failure}{between} {
1126 BEGIN signame ;
1127 SET_NEXTSTART() ;
1128 return FAILURE ; }
1129
1130 <sgtype>{key_syntax}{between} {
1131 BEGIN signame ;
1132 SET_NEXTSTART() ;
1133 return SYNTAX ; }
1134
1135 <sgtype>{key_lostdigits}{between} {
1136 BEGIN signame ;
1137 SET_NEXTSTART() ;
1138 return LOSTDIGITS ; }
1139
1140 <value1>{between}{trace_char}+{between} {
1141 if (!in_trace) REJECT ;
1142 strcpy(retvalue,rmspc( yytext )) ;
1143 SET_NEXTSTART() ;
1144 return WHATEVER ; }
1145
1146 <procd>{key_expose}{between} {
1147 BEGIN other ;
1148 in_parse = 1 ;
1149 SET_NEXTSTART() ;
1150 return EXPOSE ; }
1151
1152 <parse>{key_upper}{between} {
1153 SET_NEXTSTART() ;
1154 return UPPER ; }
1155
1156 <parse>{key_lower}{between} {
1157 SET_NEXTSTART() ;
1158 return LOWER ; }
1159
1160 <parse>{key_caseless}{between} {
1161 SET_NEXTSTART() ;
1162 return CASELESS ; }
1163
1164 <parse>{key_arg}{between} {
1165 BEGIN other ;
1166 SET_NEXTSTART() ;
1167 return ARG ; }
1168
1169 <parse>{key_numeric}{between} {
1170 BEGIN other ;
1171 SET_NEXTSTART() ;
1172 return NUMERIC ; }
1173
1174 <parse>{key_pull}{between} {
1175 BEGIN other ;
1176 SET_NEXTSTART() ;
1177 return PULL ; }
1178
1179 <parse>{key_source}{between} {
1180 BEGIN other ;
1181 SET_NEXTSTART() ;
1182 return SOURCE ; }
1183
1184 <parse>{key_external}{between} {
1185 BEGIN other ;
1186 SET_NEXTSTART() ;
1187 return EXTERNAL ; }
1188
1189 <parse>{key_linein}{between} {
1190 BEGIN other ;
1191 SET_NEXTSTART() ;
1192 return LINEIN ; }
1193
1194 <parse>{key_version}{between} {
1195 BEGIN other ;
1196 SET_NEXTSTART() ;
1197 return VERSION ; }
1198
1199 <parse>{key_var}{between} {
1200 BEGIN other ;
1201 in_parse = 2; /* accept a variable and treat func(a) as func (a) */
1202 SET_NEXTSTART() ;
1203 return VAR ; }
1204
1205 <parse>{key_value}{between} {
1206 seek_with = seek_with_from_parse ;
1207 in_trace = 0 ;
1208 in_parse = 0 ;
1209 BEGIN with ; /* in fact this works as a "not comm" */
1210 SET_NEXTSTART() ;
1211 return VALUE ; }
1212
1213 <comm>{between}{key_then}{between} {
1214 in_then = 0 ;
1215 SET_NEXTSTART() ;
1216 return THEN ; }
1217
1218 <other,ifcont>{between}{key_then}{between} {
1219 if (in_then!=1) REJECT ;
1220 BEGIN comm ;
1221 in_then = 0 ;
1222 SET_NEXTSTART() ;
1223 return THEN ; }
1224
1225 {between}{key_with}{between} {
1226 /*
1227 * Fixes bug 952380
1228 */
1229 if ((in_do)||(!seek_with))
1230 REJECT ;
1231 BEGIN other ;
1232 if ( seek_with == seek_with_from_parse )
1233 in_parse = 1 ;
1234 seek_with = no_seek_with ;
1235 if (in_address) /* any address state */
1236 in_address = in_address_with ; /* WITH seen */
1237 SET_NEXTSTART() ;
1238 return WITH ; }
1239
1240
1241 <numeric>{key_digits}{between} {
1242 BEGIN other ;
1243 SET_NEXTSTART() ;
1244 return DIGITS ; }
1245
1246 <numeric>{key_form}{between} {
1247 BEGIN nmform ;
1248 next_numform = 1 ;
1249 SET_NEXTSTART() ;
1250 return FORM ; }
1251
1252 <nmform>{key_scientific}{between} {
1253 SET_NEXTSTART() ;
1254 return SCIENTIFIC ; }
1255
1256 <nmform>{key_engineering}{between} {
1257 SET_NEXTSTART() ;
1258 return ENGINEERING ; }
1259
1260 <numeric>{key_fuzz}{between} {
1261 BEGIN other ;
1262 SET_NEXTSTART() ;
1263 return FUZZ ; }
1264
1265 <do1>{key_forever}{between} {
1266 BEGIN other ;
1267 assert(in_do) ;
1268 in_do = 2 ;
1269 SET_NEXTSTART() ;
1270 return FOREVER ; }
1271
1272 {key_to}{between} {
1273 if ( in_do == 2 )
1274 {
1275 BEGIN other ;
1276 SET_NEXTSTART() ;
1277 return TO ;
1278 }
1279 else if ( in_do == 1 )
1280 {
1281 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1282 exiterror( ERR_INVALID_DO_SYNTAX, 1, "TO" ) ;
1283 }
1284 REJECT ; }
1285
1286 {key_by}{between} {
1287 if ( in_do == 2 )
1288 {
1289 BEGIN other ;
1290 SET_NEXTSTART() ;
1291 return BY ;
1292 }
1293 else if ( in_do == 1 )
1294 {
1295 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1296 exiterror( ERR_INVALID_DO_SYNTAX, 1, "BY" ) ;
1297 }
1298 REJECT ; }
1299
1300 {key_for}{between} {
1301 if ( in_do == 2 )
1302 {
1303 BEGIN other ;
1304 SET_NEXTSTART() ;
1305 return FOR ;
1306 }
1307 else if ( in_do == 1 )
1308 {
1309 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1310 exiterror( ERR_INVALID_DO_SYNTAX, 1, "FOR" ) ;
1311 }
1312 REJECT ; }
1313
1314 {key_while}{between} {
1315 if (in_do)
1316 {
1317 if ( in_do == 3 )
1318 {
1319 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1320 exiterror( ERR_INVALID_DO_SYNTAX, 1, "WHILE" ) ;
1321 }
1322 in_do=3 ;
1323 BEGIN other ;
1324 SET_NEXTSTART() ;
1325 return WHILE ;
1326 }
1327 REJECT ; }
1328
1329 {key_until}{between} {
1330 if (in_do) {
1331 if ( in_do == 3 )
1332 {
1333 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1334 exiterror( ERR_INVALID_DO_SYNTAX, 1, "UNTIL" ) ;
1335 }
1336
1337 in_do=3 ;
1338 BEGIN other ;
1339 SET_NEXTSTART() ;
1340 return UNTIL ; }
1341 REJECT ; }
1342
1343
1344 <do1>{reserved_symbol}{between}/= {
1345 BEGIN other ;
1346 in_do = 2 ;
1347 set_assignment( '=' );
1348 if ( !KNOWN_RESERVED( retvalue, retlength ) )
1349 exiterror( ERR_RESERVED_SYMBOL, 1, yytext ) ;
1350 SET_NEXTSTART() ;
1351 return DOVARIABLE ; }
1352
1353 <do1>{var_symbol}{between}/= {
1354 BEGIN other ;
1355 in_do = 2 ;
1356 strcpy(retvalue,rmspc( yytext )) ;
1357 SET_NEXTSTART() ;
1358 return DOVARIABLE ; }
1359
1360 <comm>{symbol}{between}:{between} {
1361 unsigned i;
1362 BEGIN comm ;
1363
1364 for( i = 0; ( ch = yytext[i] ) != '\0'; i++ )
1365 {
1366 /*
1367 * A blank or ':' can't occur in the normal text. They are terminators.
1368 */
1369 if ( ( ch == ':' )
1370 || ( ch == '\n' )
1371 || ( MY_ISBLANK( ch ) ) )
1372 break;
1373 retvalue[i] = (char) rx_toupper( ch );
1374 }
1375 retvalue[i] = '\0' ;
1376 SET_NEXTSTART() ;
1377 return LABEL ; }
1378
1379
1380 <comm>{mintext_string}{between}:{between} {
1381 BEGIN comm ;
1382
1383 compress_string( retvalue, yytext );
1384
1385 SET_NEXTSTART() ;
1386 return LABEL ; }
1387
1388
1389 {mintext_string}{comment}*\( {
1390 BEGIN other ;
1391
1392 compress_string( retvalue, yytext );
1393
1394 kill_next_space = 1 ;
1395 if ( insert_abuttal ) {
1396 inhibit_delayed_abuttal = 1 ;
1397 delayed_symbol = EXFUNCNAME ;
1398 SET_NEXTSTART() ;
1399 return CONCATENATE ; }
1400
1401 expression_ended = 0 ;
1402 SET_NEXTSTART() ;
1403 return EXFUNCNAME ; }
1404
1405
1406
1407 ('{hex_string}'|\"{hex_string}\")[xX]/{notGeneralDot} {
1408 /*
1409 * fixes bug 617225.
1410 */
1411 return process_hex_or_bin_string( yytext, yyleng, 16 ); }
1412
1413
1414
1415 ('{bin_string}'|\"{bin_string}\")[bB]/{notGeneralDot} {
1416 return process_hex_or_bin_string( yytext, yyleng, 2 ); }
1417
1418 {text_string}[xXbB]/{notGeneralParen} {
1419 char c;
1420 int i,base,charcount,first,tuple;
1421
1422 base = ( rx_toupper( yytext[yyleng - 1] ) == 'X' ) ? 16 : 2;
1423 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1424 /*
1425 * We are sure to have an invalid string since the above patterns won't
1426 * match. We can either have invalid characters or misplaced spaces.
1427 *
1428 * Blanks as the first characters are forbidden.
1429 */
1430 if ( MY_ISBLANK( yytext[1] ) )
1431 exiterror( ERR_INVALID_HEX_CONST, ( base == 16 ) ? 1 : 2, 1 );
1432
1433 tuple = ( base == 16 ) ? 2 : 4;
1434 for ( i = 1, first = 1, charcount = 0; i < yyleng - 2; i++ )
1435 {
1436 c = yytext[i];
1437 if ( MY_ISBLANK( c ) )
1438 {
1439 /*
1440 * The first tuple may have less than tuple chars
1441 */
1442 if ( ( ( charcount % tuple ) == 0 ) || first )
1443 {
1444 first = 0;
1445 charcount = 0;
1446 continue;
1447 }
1448 exiterror( ERR_INVALID_HEX_CONST, ( base == 16 ) ? 1 : 2, i );
1449 }
1450 charcount++;
1451 if ( base == 2 )
1452 {
1453 if ( ( c == '0' ) || ( c == '1' ) )
1454 continue;
1455 }
1456 if ( base == 16 )
1457 {
1458 if ( rx_isxdigit( c ) )
1459 continue;
1460 }
1461 exiterror( ERR_INVALID_HEX_CONST, ( base == 16 ) ? 3 : 4, c );
1462 }
1463 /*
1464 * We didn't match something like "1 12 34 "X Assume this as the error.
1465 * Look back to the first blank in the last sequence.
1466 */
1467 for ( i = yyleng - 2; i > 1; i-- )
1468 if ( !MY_ISBLANK( yytext[i - 1] ) )
1469 break;
1470 exiterror( ERR_INVALID_HEX_CONST, ( base == 16 ) ? 1 : 2, i ); }
1471
1472 {text_string} {
1473 BEGIN other ;
1474
1475 compress_string( retvalue, yytext );
1476
1477 strcpy( yytext, retvalue ); /* proper error display */
1478
1479 if (in_numform)
1480 {
1481 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1482 exiterror( ERR_INV_SUBKEYWORD, 11, "ENGINEERING SCIENTIFIC", retvalue ) ;
1483 }
1484
1485 /* fixes 1109372 */
1486 if ( insert_abuttal && !in_parse && !in_signal && !in_call ) {
1487 delayed_symbol = STRING ;
1488 SET_NEXTSTART() ;
1489 return CONCATENATE ; }
1490
1491 if (in_call)
1492 {
1493 in_call = 0 ;
1494 kill_next_space = 1 ;
1495 }
1496 else
1497 expression_ended = 1 ;
1498
1499 SET_NEXTSTART() ;
1500 return STRING ; }
1501
1502
1503 {digit}+ {
1504 if (!in_parse)
1505 REJECT ;
1506 strcpy(retvalue,yytext) ;
1507 SET_NEXTSTART() ;
1508 return OFFSET ; }
1509
1510 {digit}+/{notGeneralDot} {
1511 /*
1512 * This is the same as of the "{digit}+" rule above. flex is very stupid.
1513 * (Or is it a feature?)
1514 * The number below will take precedence instead of a plain "{digit}+",
1515 * even of the fact that the above rule may match the same length of
1516 * characters. flex seems to count the next "expect characters" for the
1517 * comparison which rule shall be used.
1518 */
1519 if (!in_parse)
1520 REJECT ;
1521 strcpy(retvalue,yytext) ;
1522 SET_NEXTSTART() ;
1523 return OFFSET ; }
1524
1525 {number}/{notGeneralDot} {
1526 /*
1527 * must split two rule parts because of the "/" rule-part.
1528 * This fixes bug 602283.
1529 */
1530 return process_number_or_const( yytext, yyleng );
1531 }
1532
1533 {const_symbol} {
1534 return process_number_or_const( yytext, yyleng );
1535 }
1536
1537 {var_symbol} {
1538 int i,j;
1539 /*
1540 * this might be a symbol in front of a function, but only if next
1541 * char in input stream is "(".
1542 */
1543
1544 if (in_trace) REJECT ;
1545
1546 memcpy( retvalue, yytext, yyleng + 1 ); /* include terminating '\0' */
1547 mem_upper( retvalue, yyleng );
1548
1549 if (in_numform)
1550 {
1551 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1552 exiterror( ERR_INV_SUBKEYWORD, 11, "ENGINEERING SCIENTIFIC", retvalue ) ;
1553 }
1554
1555 if ( ( last_in_address == in_address_keyword )
1556 && ( in_address == in_address_main ) )
1557 {
1558 kill_next_space = 1 ;
1559 in_call = 0 ;
1560 SET_NEXTSTART() ;
1561 return SIMSYMBOL ;
1562 }
1563
1564 BEGIN other;
1565
1566 if ( in_call )
1567 {
1568 /*
1569 * This has precedence over checking the parenthesis below.
1570 * Fixes bug 521502.
1571 */
1572 in_call = 0;
1573 kill_next_space = 1;
1574 SET_NEXTSTART();
1575 return SIMSYMBOL;
1576 }
1577
1578 if ( in_parse == 2 )
1579 {
1580 /*
1581 * This has precedence over checking the parenthesis below.
1582 * Fixes bug 1109335.
1583 */
1584 in_parse = 1;
1585 kill_next_space = 1;
1586 SET_NEXTSTART();
1587 return SIMSYMBOL;
1588 }
1589
1590 /* We must check if a '(' follows. Remember the number of eaten chars. */
1591 j = 1;
1592 #ifdef __cplusplus
1593 for (; ( i = yyinput() ) == '`';)
1594 #else
1595 for (; ( i = input() ) == '`';)
1596 #endif
1597 j++ ;
1598 if (i != '(')
1599 {
1600 j-- ;
1601 unput(i) ;
1602 }
1603 /* input() has destroyed the yytext-terminator re-set it */
1604 yytext[yyleng] = '\0';
1605 SET_NEXTSTART() ;
1606 nextstart += j ;
1607
1608 if ( i == '(' )
1609 {
1610 kill_next_space = 1 ;
1611 if ( insert_abuttal )
1612 {
1613 inhibit_delayed_abuttal = 1 ;
1614 delayed_symbol = INFUNCNAME ;
1615 return CONCATENATE ;
1616 }
1617 expression_ended = 0 ;
1618 return INFUNCNAME ;
1619 }
1620
1621 if ( insert_abuttal && !in_parse ) {
1622 delayed_symbol = SIMSYMBOL ;
1623 return CONCATENATE ; }
1624
1625 expression_ended = 1 ;
1626
1627 if ( in_address == in_address_with )
1628 kill_next_space = 1 ;
1629 if (SymbolDetect) /* allow a fast breakout */
1630 {
1631 /* We define a tricky preprocessor directive. This will give us
1632 * maximum performance without the loss of control or errors produced
1633 * by typos.
1634 */
1635 #define RET_IF(s) if ((SymbolDetect & SD_##s) && \
1636 (yyleng == sizeof(#s) - 1) && \
1637 (strncmp(retvalue, \
1638 #s, \
1639 sizeof(#s) - 1) == 0)) \
1640 return(s)
1641 /* e.g. RET_IF(INPUT); is replaced by:
1642 * if ((SymbolDetect & SD_INPUT) &&
1643 * (yyleng == sizeof("INPUT") - 1) &&
1644 * (strncmp(retvalue,
1645 * "INPUT",
1646 * sizeof("INPUT") - 1) == 0))
1647 * return(s);
1648 */
1649 RET_IF(INPUT);
1650 RET_IF(OUTPUT);
1651 RET_IF(ERROR);
1652 RET_IF(NORMAL);
1653 RET_IF(APPEND);
1654 RET_IF(REPLACE);
1655 RET_IF(STREAM);
1656 RET_IF(STEM);
1657 RET_IF(LIFO);
1658 RET_IF(FIFO);
1659 RET_IF(NOEOL);
1660 #undef RET_IF
1661 }
1662 return SIMSYMBOL ; }
1663
1664 {reserved_symbol} {
1665 int i,j;
1666 /*
1667 * this is mainly the content of var_symbol but we do a REJECT for all but
1668 * normal variable names.
1669 */
1670
1671 if ( in_trace || in_numform || in_call )
1672 REJECT;
1673
1674 if ( ( last_in_address == in_address_keyword )
1675 && ( in_address == in_address_main ) )
1676 REJECT;
1677
1678 set_assignment( '=' );
1679 if ( !KNOWN_RESERVED( retvalue, retlength ) )
1680 REJECT;
1681
1682 /* We must check if a '(' follows. Remember the number of eaten chars. */
1683 #ifdef __cplusplus
1684 for ( j = 1; ( i = yyinput() ) == '`'; )
1685 #else
1686 for ( j = 1; ( i = input() ) == '`'; )
1687 #endif
1688 j++;
1689 if ( i != '(' )
1690 {
1691 j--;
1692 unput( i );
1693 }
1694 /* input() has destroyed the yytext-terminator re-set it */
1695 yytext[yyleng] = '\0';
1696 SET_NEXTSTART();
1697 nextstart += j;
1698
1699 if ( i == '(' )
1700 REJECT; /* function name can't start with '.' */
1701
1702 BEGIN other;
1703 if ( insert_abuttal && !in_parse )
1704 {
1705 delayed_symbol = SIMSYMBOL;
1706 return CONCATENATE;
1707 }
1708
1709 expression_ended = 1;
1710 return SIMSYMBOL;
1711 }
1712
1713 {between}\) {
1714 expression_ended = 1 ;
1715 SET_NEXTSTART() ;
1716 return ')' ; }
1717
1718 \({between} {
1719 BEGIN other ;
1720 if ( insert_abuttal )
1721 {
1722 inhibit_delayed_abuttal = 1 ;
1723 delayed_symbol = '(' ;
1724 SET_NEXTSTART() ;
1725 return CONCATENATE ;
1726 }
1727 SET_NEXTSTART() ;
1728 return '(' ; }
1729
1730 {between}\,{between} {
1731 SET_NEXTSTART() ;
1732 return ',' ; }
1733
1734 {between}\-{between} {
1735 BEGIN other ;
1736 SET_NEXTSTART() ;
1737 return '-' ; }
1738
1739 {between}\+{between} {
1740 BEGIN other ;
1741 SET_NEXTSTART() ;
1742 return '+' ; }
1743
1744 {between}\/{between} {
1745 SET_NEXTSTART() ;
1746 return '/' ; }
1747
1748 {between}%{between} {
1749 SET_NEXTSTART() ;
1750 return '%' ; }
1751
1752 {between}\*{between} {
1753 SET_NEXTSTART() ;
1754 return '*' ; }
1755
1756 {between}\|{between} {
1757 SET_NEXTSTART() ;
1758 return '|' ; }
1759
1760 {between}&{between} {
1761 SET_NEXTSTART() ;
1762 return '&' ; }
1763
1764 {between}={between} {
1765 SET_NEXTSTART() ;
1766 return '=' ; }
1767
1768 {not}{between} {
1769 /* why don't I have a {between} in the beginning of this re? bug? */
1770 BEGIN other ;
1771 SET_NEXTSTART() ;
1772 return NOT ; }
1773
1774 {between}\>{blank}*\>{between} {
1775 SET_NEXTSTART() ;
1776 return GTGT ; }
1777
1778 {between}\<{blank}*\<{between} {
1779 SET_NEXTSTART() ;
1780 return LTLT ; }
1781
1782 {between}{not}{blank}*\>{blank}*\>{between} {
1783 SET_NEXTSTART() ;
1784 return NOTGTGT ; }
1785
1786 {between}{not}{blank}*\<{blank}*\<{between} {
1787 SET_NEXTSTART() ;
1788 return NOTLTLT ; }
1789
1790 {between}\>{blank}*\>{blank}*={between} {
1791 SET_NEXTSTART() ;
1792 return GTGTE ; }
1793
1794 {between}\<{blank}*\<{blank}*={between} {
1795 SET_NEXTSTART() ;
1796 return LTLTE ; }
1797
1798 {between}(\>|{not}{blank}*(\<{blank}*=|={blank}*\<)){between} {
1799 SET_NEXTSTART() ;
1800 return GT ; }
1801
1802 {between}({not}{blank}*\<|={blank}*\>|\>{blank}*=){between} {
1803 SET_NEXTSTART() ;
1804 return GTE ; }
1805
1806 {between}(\<|{not}{blank}*(\>{blank}*=|={blank}*\>)){between} {
1807 SET_NEXTSTART() ;
1808 return LT ; }
1809
1810 {between}({not}{blank}*\>|={blank}*\<|\<{blank}*=){between} {
1811 SET_NEXTSTART() ;
1812 return LTE ; }
1813
1814 {between}({not}{blank}*=|\<{blank}*\>|\>{blank}*\<){between} {
1815 SET_NEXTSTART() ;
1816 return DIFFERENT ; }
1817
1818 {between}={blank}*={between} {
1819 SET_NEXTSTART() ;
1820 return EQUALEQUAL ; }
1821
1822 {between}{not}{blank}*={blank}*={between} {
1823 SET_NEXTSTART() ;
1824 return NOTEQUALEQUAL ; }
1825
1826 {between}\/{blank}*\/{between} {
1827 SET_NEXTSTART() ;
1828 return MODULUS ; }
1829
1830 {between}&{blank}*&{between} {
1831 SET_NEXTSTART() ;
1832 return XOR ; }
1833
1834 {between}\|{blank}*\|{between} {
1835 SET_NEXTSTART() ;
1836 return CONCATENATE ; }
1837
1838 {between}\*{blank}*\*{between} {
1839 SET_NEXTSTART() ;
1840 return EXP ; }
1841
1842 {between}{blank}{between} {
1843 if ( in_address == in_address_value ) /* Always allow spaces in the VALUE */
1844 { /* part of the ADDRESS stmt. */
1845 SET_NEXTSTART() ;
1846 return SPACE ;
1847 }
1848 if (kill_this_space)
1849 {
1850 SET_NEXTSTART() ;
1851 return yylex() ;
1852 }
1853 SET_NEXTSTART() ;
1854 return (((in_parse)&&(!seek_with)) ? yylex() : SPACE) ; }
1855
1856 ['"] {
1857 SET_NEXTSTART() ;
1858 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1859 exiterror( ERR_UNMATCHED_QUOTE, 0 ) ; }
1860
1861
1862 : {
1863 SET_NEXTSTART() ;
1864 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1865 exiterror( ERR_SYMBOL_EXPECTED, 1, yytext ) ;}
1866
1867 . {
1868 SET_NEXTSTART() ;
1869 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
1870 exiterror( ERR_INVALID_CHAR, 1, yytext[0], yytext[0] ); }
1871
1872
1873 %%
1874
1875 #define NORMALSTAT 0
1876 #define COMMENTSTAT 1
1877 #define SINGLEQUOTE 2
1878 #define DOUBLEQUOTE 3
1879
1880 /*
1881 * set_assignment sets an assignment variable in retvalue from yytext with
1882 * a trailing {between}[={between}] stripped.
1883 * retlength is set, too.
1884 */
1885 static void set_assignment( char delim )
1886 {
1887 char ch;
1888
1889 for( retlength = 0; ( ch = yytext[retlength] ) != 0; retlength++ )
1890 {
1891 /*
1892 * A blank or delim can't occur in the normal text. They are terminators.
1893 */
1894 if ( ( ch == delim )
1895 || ( ch == '\n' )
1896 || ( MY_ISBLANK( ch ) ) )
1897 break;
1898 retvalue[retlength] = (char) rx_toupper( ch );
1899 }
1900 retvalue[retlength] = '\0' ;
1901 }
1902
1903 /* rmspc uppercases all characters and removes blanks from a string.
1904 * Returns the input string.
1905 */
1906 static YY_CHAR_TYPE *rmspc( YY_CHAR_TYPE *instr )
1907 {
1908 YY_CHAR_TYPE *retval=instr ,
1909 *dest =instr ,
1910 c ;
1911
1912 while ((c = *instr++) != '\0')
1913 {
1914 c = (YY_CHAR_TYPE) rx_toupper(c);
1915 /* These characters are treated as blanks: */
1916 if ((c!='`') && (c!=' ') && (c!=',') && (c!='\t') && (c!='\n'))
1917 *dest++ = c ;
1918 }
1919 *dest = '\0' ;
1920
1921 return( retval ) ;
1922 }
1923
1924 /*
1925 * process_number_or_const does the processing of a decimal number or a const.
1926 * The detection was to complicated to put it into one routine.
1927 * We have to read some more characters to decide whether or not we have
1928 * an INFUNCNAME.
1929 * Returns a lexical code.
1930 */
1931 static int process_number_or_const( const char *text, int len )
1932 {
1933 int eaten,c,symbol;
1934
1935 /*
1936 * Copy and uppercase the return value.
1937 */
1938 memcpy( retvalue, text, len + 1 ); /* include terminating '\0' */
1939 mem_upper( retvalue, len );
1940
1941 if ( in_numform )
1942 {
1943 parser_data.tline = linenr - 1; /* set tline for exiterror */
1944 exiterror( ERR_INV_SUBKEYWORD, 11, "ENGINEERING SCIENTIFIC", retvalue );
1945 }
1946 nextstart += len;
1947
1948 BEGIN other;
1949
1950 /*
1951 * Plain number or const_symbol.
1952 */
1953 if ( KNOWN_RESERVED( retvalue, len ) )
1954 symbol = SIMSYMBOL;
1955 else
1956 symbol = CONSYMBOL;
1957
1958 if ( in_call )
1959 {
1960 /*
1961 * This has precedence over checking the parenthesis below.
1962 * Fixes bug 521502.
1963 */
1964 in_call = 0;
1965 kill_next_space = 1;
1966 SET_NEXTSTART();
1967 return symbol;
1968 }
1969
1970 /*
1971 * We must check if a '(' follows. Remember the number of eaten chars.
1972 */
1973 eaten = 1;
1974 #ifdef __cplusplus
1975 while ( ( c = yyinput() ) == '`' )
1976 #else
1977 while ( ( c = input() ) == '`' )
1978 #endif
1979 {
1980 eaten++;
1981 }
1982 if ( c != '(' )
1983 {
1984 eaten--;
1985 unput( c );
1986 }
1987 /*
1988 * input() has destroyed the yytext-terminator re-set it
1989 */
1990 yytext[yyleng] = '\0';
1991 nextstart += eaten;
1992 if ( c == '(' )
1993 {
1994 kill_next_space = 1;
1995 if ( insert_abuttal )
1996 {
1997 inhibit_delayed_abuttal = 1;
1998 delayed_symbol = INFUNCNAME;
1999 return CONCATENATE;
2000 }
2001 expression_ended = 0;
2002 return INFUNCNAME;
2003 }
2004
2005 if ( insert_abuttal && !in_parse )
2006 {
2007 delayed_symbol = symbol;
2008 return CONCATENATE;
2009 }
2010
2011 expression_ended = 1;
2012 return symbol;
2013 }
2014
2015 /*
2016 * compress_string removes quotes or double quotes from the src and changes
2017 * double delimiter to one. The delimiter should be either ' or ".
2018 */
2019 static void compress_string( char *dest, const char *src )
2020 {
2021 char c, delim = *src++;
2022
2023 for (;;)
2024 {
2025 if ( ( c = *src++ ) == delim )
2026 {
2027 if (*src == delim )
2028 {
2029 *dest++ = *src++;
2030 }
2031 else
2032 {
2033 break;
2034 }
2035 }
2036 else
2037 {
2038 if ( c == '\n' )
2039 {
2040 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
2041 exiterror( ERR_UNMATCHED_QUOTE, 0 ) ;
2042 }
2043 *dest++ = c;
2044 }
2045 }
2046 *dest = '\0';
2047 }
2048
2049 /*
2050 * process_hex_or_bin_string convert the string in text which is given as
2051 * a hexstring or a binstring to a "normal" string. base must be either 2 or
2052 * 16.
2053 * We rely on having a well-formed string. This must be ensured. It is
2054 * something of the form "content"x or 'content'b or similar.
2055 * Returns a lexical code. retvalue and retlength will be filled.
2056 */
2057 static int process_hex_or_bin_string( char *text, int len, int base )
2058 {
2059 char c;
2060 int i,left;
2061 unsigned char *dest,sum;
2062
2063 BEGIN other;
2064 SET_NEXTSTART();
2065
2066 text++;
2067 len -= 3;
2068
2069 /*
2070 * First, count the number of valid chars to determine the missed leading
2071 * zeros of the first final character.
2072 */
2073 for ( i = 0, left = 0 ; i < len; i++ )
2074 {
2075 c = text[i];
2076 if ( !MY_ISBLANK( c ) )
2077 left++;
2078 }
2079
2080 /*
2081 * left shall be the count of input char left to process one dest char.
2082 * Accessing one character after the content's end is allowed.
2083 */
2084 left %= ( base == 2 ) ? 8 : 2;
2085
2086 dest = (unsigned char *) retvalue;
2087 retlength = 0;
2088
2089 sum = 0;
2090 c = *text;
2091 for (;;)
2092 {
2093 while ( len && MY_ISBLANK( c ) )
2094 {
2095 c = *++text;
2096 len--;
2097 }
2098 if ( len == 0 )
2099 break;
2100
2101 if ( base == 2 )
2102 {
2103 if ( left == 0 )
2104 left = 8;
2105 sum <<= 1;
2106 sum |= (unsigned char) ( c - '0' );
2107 }
2108 else
2109 {
2110 if ( left == 0 )
2111 left = 2;
2112 sum <<= 4;
2113 sum |= HEXVAL( c );
2114 }
2115 c = *++text;
2116 len--;
2117
2118 if ( --left == 0 )
2119 {
2120 dest[retlength++] = sum;
2121 sum = 0;
2122 }
2123 }
2124 dest[retlength] = '\0';
2125
2126 /* We must check if a '(' follows. Remember the number of eaten chars. */
2127 left = 1;
2128 #ifdef __cplusplus
2129 for (; ( i = yyinput() ) == '`';)
2130 #else
2131 for (; ( i = input() ) == '`';)
2132 #endif
2133 left++;
2134 if (i != '(')
2135 {
2136 left--;
2137 unput(i);
2138 }
2139 /* input() has destroyed the yytext-terminator re-set it */
2140 text[len] = '\0';
2141 SET_NEXTSTART();
2142 nextstart += left;
2143
2144 if (i == '(')
2145 {
2146 kill_next_space = 1;
2147 if (insert_abuttal)
2148 {
2149 inhibit_delayed_abuttal = 1;
2150 delayed_symbol = INFUNCNAME;
2151 return CONCATENATE;
2152 }
2153 expression_ended = 0;
2154 return INFUNCNAME;
2155 }
2156
2157 if ( insert_abuttal && !in_parse && !in_call )
2158 {
2159 /* fix bug 456 - the delayed symbol MUST be BINSTRING or HEXSTRING */
2160 delayed_symbol = ( base == 2 ) ? BINSTRING : HEXSTRING;
2161 return CONCATENATE;
2162 }
2163
2164 if ( in_call )
2165 {
2166 in_call = 0;
2167 kill_next_space = 1;
2168 }
2169 else
2170 expression_ended = 1;
2171
2172 return ( base == 2 ) ? BINSTRING : HEXSTRING;
2173 }
2174
2175 /* get_next_line: Lower level input fetcher.
2176 * Reads exactly one line from the input stream (file or string).
2177 * All EOL characters are removed and the result is stored in
2178 * last_source_line. A check for line overflow occurred here.
2179 * A special check is done for CP/M ^Z (DOS and friends use this for
2180 * "backward" compatibility, too).
2181 * line is filled with valid values on success.
2182 * max must reflect size of line and should be at least BUFFERSIZE + 2;
2183 * Returns -1 (no input) or the number of valid chars in line.
2184 */
2185 static int get_next_line( char *line, int max, FILE *stream )
2186 {
2187 lineboxptr newline ;
2188 offsrcline *incore_newline;
2189 int pos = 0;
2190 int c = 0;
2191
2192 if (inEOF) /* You can't use myunputc if EOF is reached! */
2193 return EOF ;
2194
2195 while (pos <= max - 2)
2196 {
2197 /* get next char */
2198 if (bufptr>0)
2199 c = chbuffer[--bufptr] ;
2200 else if (ipretflag)
2201 {
2202 if (interptr>=interptrmax)
2203 c = EOF ;
2204 else
2205 #ifdef ASCII_0_TERMINATES_STRING
2206 if ((c = *interptr++) == '\0')
2207 c = EOF ;
2208 #else
2209 c = *interptr++ ;
2210 #endif
2211 }
2212 else
2213 {
2214 c = getc(stream) ;
2215
2216 if ( parser_data.TSD->HaltRaised )
2217 halt_raised( parser_data.TSD );
2218 }
2219
2220 if ((c=='\r') || (c=='\n') || (c==EOF))
2221 break ;
2222 line[pos++] = (char) (unsigned char) c ;
2223 }
2224
2225 /* first, check for overflow */
2226 if ((c!='\r') && (c!='\n') && (c!=EOF))
2227 {
2228 parser_data.tline = linenr ; /* set tline for exiterror */
2229 exiterror( ERR_TOO_LONG_LINE, 0 ) ;
2230 }
2231
2232 /* We have either a (first) line terminator or EOF */
2233 if (c==EOF)
2234 {
2235 if ((pos==1) && (line[0]=='\x1A')) /* CP/M ^Z EOF? */
2236 pos-- ;
2237 if (pos == 0)
2238 {
2239 inEOF = 1 ;
2240 return EOF ;
2241 }
2242 chbuffer[bufptr++] = EOF; /* push back EOF for reuse */
2243 }
2244 else
2245 {
2246 /* Maybe we have CRLF or LFCR. Check for the pair character. */
2247 char pairChar = (c == '\r') ? '\n' : '\r';
2248
2249
2250 /* get one more char and consume it if it is the pair of the EOL */
2251 if (bufptr > 0)
2252 {
2253 if (chbuffer[bufptr - 1] == (int) pairChar)
2254 bufptr--;
2255 }
2256 else if (ipretflag)
2257 {
2258 if ((interptr < interptrmax) && (*interptr == pairChar))
2259 interptr++;
2260 }
2261 else
2262 {
2263 int next = getc(stream);
2264 if (next != pairChar)
2265 {
2266 /* ungetc may break some runtime stuff. Use the internal lookahead*/
2267 chbuffer[bufptr++] = next;
2268 }
2269 if ( parser_data.TSD->HaltRaised )
2270 halt_raised( parser_data.TSD );
2271 }
2272 }
2273
2274
2275 cch = 0 ; /* not needed ? */
2276 line[pos++] = '\n';
2277
2278 if (parser_data.incore_source)
2279 {
2280 /*
2281 * We can use the incore string to describe a source line, but we
2282 * MUST incement linenr otherwise .LINE doesn't work in instore macros.
2283 * This will probably also allow errors to be reported for the correct line number.
2284 */
2285 linenr++;
2286 incore_newline = FreshLine() ;
2287 incore_newline->length = pos - 1 ;
2288 incore_newline->offset = last_interptr - parser_data.incore_source ;
2289 last_interptr = interptr;
2290 return pos ;
2291 }
2292
2293 newline = (lineboxptr)Malloc(sizeof(linebox)) ;
2294 newline->line = Str_make_TSD( parser_data.TSD, pos - 1 ) ;
2295 newline->line->len = pos - 1 ;
2296 memcpy(newline->line->value, line, pos - 1 ) ;
2297 newline->prev = parser_data.last_source_line ;
2298 newline->next = NULL ;
2299 newline->lineno = linenr++ ;
2300
2301 if (parser_data.first_source_line==NULL)
2302 parser_data.first_source_line = newline ;
2303 else
2304 parser_data.last_source_line->next = newline ;
2305 parser_data.last_source_line = newline ;
2306
2307 return pos ;
2308 }
2309
2310 /* fill_buffer: Higher level input fetcher.
2311 * (To allow the C-file to compile, all Rexx comments in this comment
2312 * are written as "{*" "*}" instead of the normal, C-like manner.)
2313 * Reads lines from the input stream (yyin or string) with get_next_line.
2314 * Only one line is returned to allow the saving of the line number.
2315 * This routine replaces all comments by '`' signs. This allows
2316 * the detection of a "pseudo" blank: The fragment "say x{* *}y" uses two
2317 * variables, not one called "xy". The parsing of comments must be done
2318 * here to check for the actual numbers of open and closes ("{*" and "*}").
2319 * While doing this we must always check for strings since "'{*'" is not part
2320 * of a comment.
2321 * Here is a problem: Is this a nested valid comment: "{* '{*' *} *}"?
2322 * I think so although you cannot remove the outer comment signs without an
2323 * error. Everything within a comment is a comment (per def.). Counting
2324 * opens and closes of comment signs is an ugly trick to help the user.
2325 * He/she must know what he/she is doing if nesting comments!
2326 *
2327 * max_size gives the maximum size of buf. This is filled up with input.
2328 * We never return less than one character until EOF is reached. Thus, we
2329 * read more than one true input line if a comment spans over more than one
2330 * line.
2331 * A line will either be terminated by a single '\n' or by a blank. The
2332 * later one replaces a line continuation (',' [spaces] EOL).
2333 * Errors in this low
2334 *
2335 * Conclusion: We have to fight very hard to set the expected line number.
2336 * * Comments spanning over lines set them on getting the
2337 * "follow" lines.
2338 * * Concatenated lines set
2339 */
2340 static int fill_buffer( char *buf, int max_size )
2341 {
2342 /* statics protected by regina_parser */
2343 static char line[BUFFERSIZE+2] ; /* special buffer to allow max_size */
2344 static int pos = 0, max = 0 ; /* being smaller than BUFFERSIZE+1 */
2345 static int nesting = 0; /* nesting level of comments */
2346 int nesting_start_line = 0; /* start line of comment for errortext() */
2347 char *dest, c;
2348 int i, squote, dquote;
2349 int line_comment;
2350
2351 if (firstln == 0)
2352 {
2353 firstln = 1;
2354 contline = 0;
2355 nesting = 0;
2356 pos = 0;
2357 max = get_next_line( line, sizeof(line), yyin ) ;
2358 if (max < 0) /* empty input file */
2359 return 0 ;
2360 /* test for both #! - fixes bug 1230639 */
2361 if ( max > 1
2362 && line[0] == '#'
2363 && line[1] == '!' )
2364 { /* Ignore first line beginning this way for unix compat */
2365 max = 5;
2366 memcpy( line, "/**/\n", 5 );
2367 }
2368 }
2369 else if (pos < max) /* Are there still characters to transmit? */
2370 {
2371 /* Buffer already checked for correctness */
2372 if (max_size > max - pos)
2373 max_size = max - pos;
2374 memcpy(buf, line + pos, max_size);
2375 pos += max_size;
2376 return(max_size);
2377 }
2378 else /* Need next line */
2379 {
2380 if (contline && !nesting)
2381 {
2382 extnextline = ++nextline ;
2383 extnextstart = 1 ;
2384 contline = 0;
2385 }
2386 pos = 0;
2387 max = get_next_line( line, sizeof(line), yyin ) ;
2388 if (max < 0) /* empty input file */
2389 {
2390 if (nesting)
2391 {
2392 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
2393 exiterror( ERR_UNMATCHED_QUOTE, 1 ) ;
2394 }
2395 return 0 ;
2396 }
2397 }
2398
2399 /* A new line is available, check first for an ending comment */
2400 dest = line; /* we change comments in line */
2401 if (nesting) /* This may lead to more line reading */
2402 {
2403 /*
2404 * The first time extnextline is non-zero, we have the comment
2405 * starting sequence line. This is saved for use if no matching
2406 * ending comment sequence is found, so that the error message
2407 * reflects the start of the comment.
2408 * Regina feature request: #508788
2409 */
2410 if ( extnextline < 0 )
2411 nesting_start_line = nextline+1;
2412 extnextline = ++nextline ;
2413 extnextstart = 1; /* See Reference (*) below */
2414 repeated_nesting:
2415 while (pos < max)
2416 {
2417 c = line[pos];
2418 if (c == '*') /* start of comment end? */
2419 {
2420 if (line[pos+1] == '/')
2421 { /* pos+1 always exists, at least '\n' or '\0' */
2422 if (--nesting == 0)
2423 {
2424 pos += 2;
2425 *dest++ = '`';
2426 *dest++ = '`';
2427 break;
2428 }
2429 *dest++ = '`';
2430 pos++;
2431 }
2432 }
2433 else if (c == '/') /* start of new begin? */
2434 {
2435 if (line[pos+1] == '*')
2436 {
2437 nesting++;
2438 *dest++ = '`';
2439 pos++;
2440 }
2441 }
2442 *dest++ = '`';
2443 pos++;
2444 }
2445 if (pos >= max)
2446 {
2447 pos = 0;
2448 max = get_next_line( line, sizeof(line), yyin ) ;
2449 if (max < 0) /* empty input file */
2450 {
2451 if ( nesting_start_line )
2452 parser_data.tline = nesting_start_line ; /* set tline for exiterror */
2453 else
2454 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
2455 exiterror( ERR_UNMATCHED_QUOTE, 1 ) ;
2456 return 0 ;
2457 }
2458 /* This is a comment continuation. If the lexer will return
2459 * something it already has a valid tline/tstart pair.
2460 * The lexer will return the current token and on the NEXT
2461 * call it expects a valid nextline/nextstart pair.
2462 */
2463 extnextline = ++nextline; extnextstart = 1;
2464 dest = line; /* we change comments in line */
2465 goto repeated_nesting;
2466 }
2467 extnextstart = pos + 1;
2468 if (contline)
2469 { /* Exception! Have a look at: "x='y',{*\n\n*}\n'z'". This should
2470 * result in "x = 'y' 'z'".
2471 * We must parse until EOL and check for whitespaces and comments...
2472 */
2473 while (pos < max)
2474 {
2475 c = line[pos];
2476 if (!rx_isspace(c))
2477 {
2478 if (c == '/')
2479 {
2480 if (line[pos+1] == '*')
2481 {
2482 pos += 2;
2483 nesting++;
2484 goto repeated_nesting;
2485 }
2486 }
2487 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
2488 exiterror( ERR_YACC_SYNTAX, 1, parser_data.tline ) ; /* standard error */
2489 }
2490 pos++;
2491 }
2492 /* All done, it was a continuation line. */
2493 /* contline will be resetted by: */
2494 return fill_buffer( buf, max_size ) ;
2495 }
2496 }
2497 /* We have something to play with. Run through the input and check for
2498 * strings including comments.
2499 */
2500 squote = dquote = 0;
2501 line_comment = 0;
2502 while (pos < max)
2503 {
2504 /* We use selective loops to reduce comparisons */
2505 if (nesting)
2506 do
2507 {
2508 c = line[pos];
2509 if (c == '*') /* start of comment end? */
2510 {
2511 if (line[pos+1] == '/')
2512 { /* pos+1 always exists, at least '\n' or '\0' */
2513 if (--nesting == 0)
2514 {
2515 pos += 2;
2516 *dest++ = '`';
2517 *dest++ = '`';
2518 break;
2519 }
2520 pos++;
2521 }
2522 }
2523 else if (c == '/') /* start of new begin? */
2524 {
2525 if (line[pos+1] == '*')
2526 {
2527 nesting++;
2528 pos++;
2529 *dest++ = '`';
2530 }
2531 }
2532 pos++;
2533 *dest++ = '`';
2534 } while (pos < max);
2535 else if (squote)
2536 {
2537 while ((c = line[pos]) != '\'')
2538 {
2539 *dest++ = c;
2540 if (++pos >= max)
2541 {
2542 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
2543 exiterror( ERR_UNMATCHED_QUOTE, 2 ) ;
2544 }
2545 }
2546 *dest++ = '\'';
2547 pos++;
2548 squote = 0;
2549 }
2550 else if (dquote)
2551 {
2552 while ((c = line[pos]) != '\"')
2553 {
2554 *dest++ = c;
2555 if (++pos >= max)
2556 {
2557 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
2558 exiterror( ERR_UNMATCHED_QUOTE, 3 ) ;
2559 }
2560 }
2561 *dest++ = '\"';
2562 pos++;
2563 dquote = 0;
2564 }
2565 else if (line_comment)
2566 {
2567 while ((c = line[pos]) >= ' ') /* not at end of line yet */
2568 {
2569 *dest++ = '`';
2570 if (++pos >= max)
2571 {
2572 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
2573 exiterror( ERR_UNMATCHED_QUOTE, 3 ) ;
2574 }
2575 }
2576 *dest++ = c; /* line terminator */
2577 pos++;
2578 line_comment = 0;
2579 }
2580 else
2581 while (pos < max)
2582 switch (c = line[pos])
2583 {
2584 case '\'':
2585 *dest++ = c ;
2586 squote = 1 ;
2587 pos++ ;
2588 goto outer_loop;
2589
2590 case '\"':
2591 *dest++ = c ;
2592 dquote = 1 ;
2593 pos++ ;
2594 goto outer_loop;
2595
2596 case '/':
2597 if (line[pos + 1] == '*')
2598 {
2599 *dest++ = '`' ;
2600 *dest++ = '`' ;
2601 pos += 2 ;
2602 nesting++ ;
2603 goto outer_loop;
2604 }
2605 else
2606 {
2607 *dest++ = c;
2608 pos++ ;
2609 }
2610 break ;
2611
2612 case '-': /* line "--" comments */
2613 if ( line[pos + 1] == '-'
2614 && get_options_flag( parser_data.TSD->currlevel, EXT_SINGLE_LINE_COMMENTS )
2615 && !get_options_flag( parser_data.TSD->currlevel, EXT_STRICT_ANSI ) )
2616 {
2617 *dest++ = '`' ;
2618 *dest++ = '`' ;
2619 pos += 2 ;
2620 line_comment = 1 ;
2621 goto outer_loop;
2622 }
2623 else
2624 {
2625 *dest++ = c;
2626 pos++ ;
2627 }
2628 break ;
2629
2630 case '`':
2631 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
2632 exiterror( ERR_INVALID_CHAR, 1, c, c ) ;
2633
2634 default:
2635 *dest++ = c;
2636 pos++ ;
2637 }
2638 outer_loop:
2639 ;
2640 }
2641
2642 max = (int) (dest - line);
2643
2644 /* Now we can replace a ',' [spaces|comments] '\n' with the line
2645 * continuation, but check for nesting first
2646 */
2647 if (nesting)
2648 { /* Don't leave ANY spaces at EOL. That would confuse the lexer. */
2649 i = max - 1;
2650 while ((i >= 0) && rx_isspace(line[i]))
2651 i--;
2652 max = i + 1;
2653 /* Of course, there is one exception: line continuation */
2654 while ((i >= 0) && (line[i] == '`'))
2655 i-- ;
2656 if ((i >= 0) && (line[i] == ','))
2657 {
2658 contline = 1;
2659 line[i] = ' ';
2660 max = i + 1;
2661 }
2662 /* (Reference (*) )
2663 * At this point the lexer can't determine the nextline since we eat up
2664 * the \n. This leads to an incorrect count. But either the '`'-signs
2665 * are ignored or they are follows of a "token", a valid word.
2666 * Look at "say x;say y ``". This will cause the lexer to
2667 * return at least 4 tokens (SAY "x" ";" SAY) before "y" will be
2668 * returned. We can only set nextline/nextstart at "y".
2669 * Result: We set this pair at the start of the next call to
2670 * fill_buffer such that the next call to yylex will set the correct
2671 * values.
2672 */
2673 }
2674 else
2675 {
2676 i = max - 1; /* on last valid char */
2677 while (i >= 0)
2678 {
2679 if (!MY_ISBLANK(line[i]) && (line[i] != '\n'))
2680 break;
2681 i--;
2682 }
2683 /* i now -1 or on last nonblank */
2684 if ((i >= 0) && (line[i] == ','))
2685 { /* FIXME: What shall be do with "," followed by EOF? */
2686 max = i + 1;
2687 line[i] = ' ';
2688 contline = 1;
2689 }
2690 }
2691
2692 if (max_size > max)
2693 max_size = max;
2694 memcpy(buf, line, max_size);
2695 pos = max_size;
2696 return(max_size);
2697 }
2698
2699
2700 /* yywrap MAY be called by the lexer is EOF encounters, see (f)lex docu */
2701 int yywrap( void )
2702 {
2703 assert( do_level>= 0 ) ;
2704 if (do_level>0)
2705 {
2706 parser_data.tline = linenr - 1 ; /* set tline for exiterror */
2707 exiterror( ERR_INCOMPLETE_STRUCT, 0 ) ;
2708 }
2709 return 1 ;
2710 }
2711
2712 /******************************************************************************
2713 ******************************************************************************
2714 * global interface ***********************************************************
2715 ******************************************************************************
2716 *****************************************************************************/
2717
2718 /* initalize all local and global values */
2719 static void init_it_all( tsd_t *TSD )
2720 {
2721 #if defined(FLEX_SCANNER) && defined(FLEX_DEBUG)
2722 if (__reginadebug)
2723 yy_flex_debug = 1;
2724 else
2725 yy_flex_debug = 0;
2726 #endif
2727 inEOF = 0 ;
2728 in_numform = 0 ;
2729 next_numform = 0 ;
2730 expression_ended = 0 ;
2731 insert_abuttal = 0 ;
2732 obs_with = 0 ;
2733 in_do = 0 ;
2734 in_then = 0 ;
2735 inhibit_delayed_abuttal = 0 ;
2736 firstln = 0 ;
2737 in_parse = 0 ;
2738 in_trace = 0 ;
2739 itflag = 0 ;
2740 in_signal = 0 ;
2741 in_call = 0 ;
2742 in_address = not_in_address ;
2743 seek_with = no_seek_with ;
2744 kill_this_space = 0 ;
2745 ipretflag = 0 ;
2746 do_level = 0 ;
2747 singlequote = 0 ;
2748 doblequote = 0 ;
2749 cch = 0 ;
2750 bufptr = 0 ;
2751 cchmax = 0 ;
2752 ch = '\0',
2753 delayed_symbol = 0,
2754 contline = 0;
2755 extnextstart = 0;
2756 interptr = NULL ;
2757 interptrmax = NULL ;
2758 /* non-zero values */
2759 linenr = 1 ;
2760 nextline = 1;
2761 nextstart = 1;
2762 kill_next_space = 1 ;
2763 extnextline = -1 ;
2764 SymbolDetect = 0;
2765
2766 memset(&parser_data, 0, sizeof(internal_parser_type));
2767 parser_data.TSD = TSD;
2768 }
2769
2770 /* fetch may only be called by fetch_protected. The parser and lexer are
2771 * already protected by regina_parser by fetch_protected.
2772 * This function prepares the lexer and parser and call them. The
2773 * result and all generated values are stored in result. The parser
2774 * tree isn't executed here.
2775 * Exactly fptr xor str must be non-null.
2776 */
2777 static void fetch(tsd_t *TSD, FILE *fptr, const streng *str,
2778 internal_parser_type *result)
2779 {
2780 init_it_all( TSD ) ;
2781
2782 #ifdef FLEX_SCANNER
2783 yy_init = 1 ;
2784 yy_delete_buffer(YY_CURRENT_BUFFER) ;
2785 yyrestart(fptr) ;
2786 #else
2787 yysptr = yysbuf ;
2788 yyin = fptr ;
2789 #endif
2790
2791 if (str != NULL)
2792 {
2793 ipretflag = 1 ;
2794 cchmax = str->len ;
2795 interptr = str->value ;
2796 last_interptr = interptr ;
2797 interptrmax = interptr + cchmax ;
2798 parser_data.incore_source = str->value; /* fixes bug 972796 */
2799 result->incore_source = str->value;
2800 }
2801
2802 BEGIN comm ;
2803 NewProg();
2804 parser_data.result = __reginaparse();
2805
2806 #ifdef FLEX_SCANNER
2807 yy_delete_buffer(YY_CURRENT_BUFFER) ;
2808 #else
2809 yysptr = yysbuf ;
2810 #endif
2811 yyin = NULL ;
2812
2813 *result = parser_data;
2814 /* Some functions assume null values if parsing isn't running: */
2815 memset(&parser_data, 0, sizeof(internal_parser_type));
2816 }
2817
2818 /* This function serializes the parser/lexer requests of the process and
2819 * call fetch which will make the work. Look there.
2820 */
2821 static void fetch_protected( tsd_t * volatile TSD, FILE *fptr,
2822 const streng *str, internal_parser_type *result )
2823 {
2824 volatile int panicked = 0;
2825 tsd_t * volatile saved_TSD;
2826
2827 THREAD_PROTECT( regina_parser )
2828 TSD->in_protected = 1;
2829 memset(&parser_data, 0, sizeof(internal_parser_type));
2830
2831 saved_TSD = TSD; /* vars used until here */
2832 if ( setjmp( TSD->protect_return ) )
2833 {
2834 TSD = saved_TSD; /* prevents bugs like 592393 */
2835 panicked = 1;
2836 }
2837 else
2838 fetch( TSD, fptr, str, result );
2839
2840 TSD->in_protected = 0;
2841 THREAD_UNPROTECT( regina_parser )
2842
2843 if ( !panicked )
2844 return;
2845
2846 /*
2847 * We got a fatal condition while fetching the input.
2848 */
2849 memset(result, 0, sizeof(internal_parser_type));
2850
2851 /*
2852 * FIXME: Currently no time to investigate it, but we have to do
2853 * a cleanup of the node and source lines of parser_data
2854 * here. Test this with
2855 * interpret '"a='
2856 * and with
2857 * interpret 'nop;"a='
2858 */
2859 if ( TSD->delayed_error_type == PROTECTED_DelayedInterpreterExit )
2860 jump_interpreter_exit( TSD, TSD->expected_exit_error );
2861 if ( TSD->delayed_error_type == PROTECTED_DelayedRexxSignal )
2862 jump_rexx_signal( TSD );
2863 jump_script_exit( TSD, TSD->systeminfo->result );
2864 }
2865
2866 /* fetch_file reads in a REXX file from disk (or a pipe). It returns without
2867 * executing the program. The parsed tree with all needed values including
2868 * the result of the parsing is copied to result.
2869 * fptr remains open after this call.
2870 * type is either PARSE_ONLY or PARSE_AND_TIN. In the later case a tinned variant of the
2871 * parsing tree is created, too.
2872 */
2873 void fetch_file(tsd_t *TSD, FILE *fptr, internal_parser_type *result)
2874 {
2875 fetch_protected(TSD, fptr, NULL, result);
2876 }
2877
2878 /* fetch_string reads in a REXX macro from a streng. It returns without
2879 * executing the program. The parsed tree with all needed values including
2880 * the result of the parsing is copied to result.
2881 * type is either PARSE_ONLY or PARSE_AND_TIN. In the later case a tinned variant of the
2882 * parsing tree is created, too.
2883 * The function is typically called by an "INTERPRET" instruction.
2884 */
2885 void fetch_string(tsd_t *TSD, const streng *str, internal_parser_type *result)
2886 {
2887 fetch_protected(TSD, NULL, str, result);
2888 }