xref: /onnv-gate/usr/src/cmd/sgs/lex/common/parser.y (revision 6951:59445bec7ef4)
10Sstevel@tonic-gate %{
20Sstevel@tonic-gate /*
30Sstevel@tonic-gate  * CDDL HEADER START
40Sstevel@tonic-gate  *
50Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
64538Sdamico  * Common Development and Distribution License (the "License").
74538Sdamico  * You may not use this file except in compliance with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate %}
230Sstevel@tonic-gate /*
24*6951Sab196087  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
250Sstevel@tonic-gate  * Use is subject to license terms.
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
290Sstevel@tonic-gate /*	  All Rights Reserved  	*/
300Sstevel@tonic-gate 
310Sstevel@tonic-gate 
320Sstevel@tonic-gate %{
330Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
340Sstevel@tonic-gate 
35*6951Sab196087 /*
36*6951Sab196087  * Lint is unable to properly handle formats with wide strings
37*6951Sab196087  * (e.g. %ws) and misdiagnoses them as being malformed.
38*6951Sab196087  * This macro is used to work around that, by substituting
39*6951Sab196087  * a pointer to a null string when compiled by lint. This
40*6951Sab196087  * trick works because lint is not able to evaluate the
41*6951Sab196087  * variable.
42*6951Sab196087  *
43*6951Sab196087  * When lint is able to handle %ws, it would be appropriate
44*6951Sab196087  * to come back through and remove the use of this macro.
45*6951Sab196087  */
46*6951Sab196087 #if defined(__lint)
47*6951Sab196087 static const char *lint_ws_fmt = "";
48*6951Sab196087 #define	WSFMT(_fmt) lint_ws_fmt
49*6951Sab196087 #else
50*6951Sab196087 #define	WSFMT(_fmt) _fmt
51*6951Sab196087 #endif
52*6951Sab196087 
530Sstevel@tonic-gate void yyerror(char *);
540Sstevel@tonic-gate 
550Sstevel@tonic-gate %}
560Sstevel@tonic-gate /* parser.y */
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /* XCU4: add XSCON: %x exclusive start token */
590Sstevel@tonic-gate /* XCU4: add ARRAY: %a yytext is char array */
600Sstevel@tonic-gate /* XCU4: add POINTER: %p yytext is a pointer to char */
610Sstevel@tonic-gate %token CHAR CCL NCCL STR DELIM SCON ITER NEWE NULLS XSCON ARRAY POINTER
620Sstevel@tonic-gate 
630Sstevel@tonic-gate %nonassoc ARRAY POINTER
640Sstevel@tonic-gate %left XSCON SCON NEWE
650Sstevel@tonic-gate %left '/'
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate  * XCU4: lower the precedence of $ and ^ to less than the or operator
680Sstevel@tonic-gate  * per Spec. 1170
690Sstevel@tonic-gate  */
700Sstevel@tonic-gate %left '$' '^'
710Sstevel@tonic-gate %left '|'
720Sstevel@tonic-gate %left CHAR CCL NCCL '(' '.' STR NULLS
730Sstevel@tonic-gate %left ITER
740Sstevel@tonic-gate %left CAT
750Sstevel@tonic-gate %left '*' '+' '?'
760Sstevel@tonic-gate 
770Sstevel@tonic-gate %{
784538Sdamico #include "ldefs.h"
790Sstevel@tonic-gate 
800Sstevel@tonic-gate #define YYSTYPE union _yystype_
810Sstevel@tonic-gate union _yystype_
820Sstevel@tonic-gate {
830Sstevel@tonic-gate 	int	i;
840Sstevel@tonic-gate 	CHR	*cp;
850Sstevel@tonic-gate };
860Sstevel@tonic-gate int	peekon = 0; /* need this to check if "^" came in a definition section */
870Sstevel@tonic-gate 
880Sstevel@tonic-gate %}
890Sstevel@tonic-gate %%
900Sstevel@tonic-gate %{
910Sstevel@tonic-gate int i;
920Sstevel@tonic-gate int j,k;
930Sstevel@tonic-gate int g;
940Sstevel@tonic-gate CHR *p;
950Sstevel@tonic-gate static wchar_t  L_PctUpT[]= {'%', 'T', 0};
960Sstevel@tonic-gate static wchar_t  L_PctLoT[]= {'%', 't', 0};
970Sstevel@tonic-gate static wchar_t  L_PctCbr[]= {'%', '}', 0};
980Sstevel@tonic-gate %}
990Sstevel@tonic-gate acc	:	lexinput
1000Sstevel@tonic-gate 	={
1010Sstevel@tonic-gate # ifdef DEBUG
1020Sstevel@tonic-gate 		if(debug) sect2dump();
1030Sstevel@tonic-gate # endif
1040Sstevel@tonic-gate 	}
1050Sstevel@tonic-gate 	;
1060Sstevel@tonic-gate lexinput:	defns delim prods end
1070Sstevel@tonic-gate 	|	defns delim end
1080Sstevel@tonic-gate 	={
1090Sstevel@tonic-gate 		if(!funcflag)phead2();
1100Sstevel@tonic-gate 		funcflag = TRUE;
1110Sstevel@tonic-gate 	}
1120Sstevel@tonic-gate 	| error
1130Sstevel@tonic-gate 	={
1140Sstevel@tonic-gate # ifdef DEBUG
1150Sstevel@tonic-gate 		if(debug) {
1160Sstevel@tonic-gate 			sect1dump();
1170Sstevel@tonic-gate 			sect2dump();
1180Sstevel@tonic-gate 			}
1190Sstevel@tonic-gate # endif
1200Sstevel@tonic-gate 		fatal = 0;
1210Sstevel@tonic-gate 		n_error++;
1220Sstevel@tonic-gate 		error("Illegal definition");
1230Sstevel@tonic-gate 		fatal = 1;
1240Sstevel@tonic-gate 		}
1250Sstevel@tonic-gate 	;
1260Sstevel@tonic-gate end:		delim | ;
1270Sstevel@tonic-gate defns:	defns STR STR
1280Sstevel@tonic-gate 	={	scopy($2.cp,dp);
1290Sstevel@tonic-gate 		def[dptr] = dp;
1300Sstevel@tonic-gate 		dp += slength($2.cp) + 1;
1310Sstevel@tonic-gate 		scopy($3.cp,dp);
1320Sstevel@tonic-gate 		subs[dptr++] = dp;
1330Sstevel@tonic-gate 		if(dptr >= DEFSIZE)
1340Sstevel@tonic-gate 			error("Too many definitions");
1350Sstevel@tonic-gate 		dp += slength($3.cp) + 1;
1360Sstevel@tonic-gate 		if(dp >= dchar+DEFCHAR)
1370Sstevel@tonic-gate 			error("Definitions too long");
1380Sstevel@tonic-gate 		subs[dptr]=def[dptr]=0;	/* for lookup - require ending null */
1390Sstevel@tonic-gate 	}
1400Sstevel@tonic-gate 	|
1410Sstevel@tonic-gate 	;
1420Sstevel@tonic-gate delim:	DELIM
1430Sstevel@tonic-gate 	={
1440Sstevel@tonic-gate # ifdef DEBUG
1450Sstevel@tonic-gate 		if(sect == DEFSECTION && debug) sect1dump();
1460Sstevel@tonic-gate # endif
1470Sstevel@tonic-gate 		sect++;
1480Sstevel@tonic-gate 		}
1490Sstevel@tonic-gate 	;
1500Sstevel@tonic-gate prods:	prods pr
1510Sstevel@tonic-gate 	={	$$.i = mn2(RNEWE,$1.i,$2.i);
1520Sstevel@tonic-gate 		}
1530Sstevel@tonic-gate 	|	pr
1540Sstevel@tonic-gate 	={	$$.i = $1.i;}
1550Sstevel@tonic-gate 	;
1560Sstevel@tonic-gate pr:	r NEWE
1570Sstevel@tonic-gate 	={
1580Sstevel@tonic-gate 		if(divflg == TRUE)
1590Sstevel@tonic-gate 			i = mn1(S1FINAL,casecount);
1600Sstevel@tonic-gate 		else i = mn1(FINAL,casecount);
1610Sstevel@tonic-gate 		$$.i = mn2(RCAT,$1.i,i);
1620Sstevel@tonic-gate 		divflg = FALSE;
1630Sstevel@tonic-gate 		if((++casecount)>NACTIONS)
1640Sstevel@tonic-gate 			error("Too many (>%d) pattern-action rules.", NACTIONS);
1650Sstevel@tonic-gate 		}
1660Sstevel@tonic-gate 	| error NEWE
1670Sstevel@tonic-gate 	={
1680Sstevel@tonic-gate # ifdef DEBUG
1690Sstevel@tonic-gate 		if(debug) sect2dump();
1700Sstevel@tonic-gate # endif
1710Sstevel@tonic-gate 		fatal = 0;
1720Sstevel@tonic-gate 		yyline--;
1730Sstevel@tonic-gate 		n_error++;
1740Sstevel@tonic-gate 		error("Illegal rule");
1750Sstevel@tonic-gate 		fatal = 1;
1760Sstevel@tonic-gate 		yyline++;
1770Sstevel@tonic-gate 		}
1780Sstevel@tonic-gate r:	CHAR
1790Sstevel@tonic-gate 	={	$$.i = mn0($1.i); }
1800Sstevel@tonic-gate 	| STR
1810Sstevel@tonic-gate 	={
1820Sstevel@tonic-gate 		p = (CHR *)$1.cp;
1830Sstevel@tonic-gate 		i = mn0((unsigned)(*p++));
1840Sstevel@tonic-gate 		while(*p)
1850Sstevel@tonic-gate 			i = mn2(RSTR,i,(unsigned)(*p++));
1860Sstevel@tonic-gate 		$$.i = i;
1870Sstevel@tonic-gate 		}
1880Sstevel@tonic-gate 	| '.'
1890Sstevel@tonic-gate 	={
1900Sstevel@tonic-gate 		$$.i = mn0(DOT);
1910Sstevel@tonic-gate 		}
1920Sstevel@tonic-gate 	| CCL
1930Sstevel@tonic-gate 	={	$$.i = mn1(RCCL,$1.i); }
1940Sstevel@tonic-gate 	| NCCL
1950Sstevel@tonic-gate 	={	$$.i = mn1(RNCCL,$1.i); }
1960Sstevel@tonic-gate 	| r '*'
1970Sstevel@tonic-gate 	={	$$.i = mn1(STAR,$1.i); }
1980Sstevel@tonic-gate 	| r '+'
1990Sstevel@tonic-gate 	={	$$.i = mn1(PLUS,$1.i); }
2000Sstevel@tonic-gate 	| r '?'
2010Sstevel@tonic-gate 	={	$$.i = mn1(QUEST,$1.i); }
2020Sstevel@tonic-gate 	| r '|' r
2030Sstevel@tonic-gate 	={	$$.i = mn2(BAR,$1.i,$3.i); }
2040Sstevel@tonic-gate 	| r r %prec CAT
2050Sstevel@tonic-gate 	={	$$.i = mn2(RCAT,$1.i,$2.i); }
2060Sstevel@tonic-gate 	| r '/' r
2070Sstevel@tonic-gate 	={	if(!divflg){
2080Sstevel@tonic-gate 			j = mn1(S2FINAL,-casecount);
2090Sstevel@tonic-gate 			i = mn2(RCAT,$1.i,j);
2100Sstevel@tonic-gate 			$$.i = mn2(DIV,i,$3.i);
2110Sstevel@tonic-gate 			}
2120Sstevel@tonic-gate 		else {
2130Sstevel@tonic-gate 			$$.i = mn2(RCAT,$1.i,$3.i);
2140Sstevel@tonic-gate 			error("illegal extra slash");
2150Sstevel@tonic-gate 			}
2160Sstevel@tonic-gate 		divflg = TRUE;
2170Sstevel@tonic-gate 		}
2180Sstevel@tonic-gate 	| r ITER ',' ITER '}'
2190Sstevel@tonic-gate 	={	if($2.i > $4.i){
2200Sstevel@tonic-gate 			i = $2.i;
2210Sstevel@tonic-gate 			$2.i = $4.i;
2220Sstevel@tonic-gate 			$4.i = i;
2230Sstevel@tonic-gate 			}
2240Sstevel@tonic-gate 		if($4.i <= 0)
2250Sstevel@tonic-gate 			error("iteration range must be positive");
2260Sstevel@tonic-gate 		else {
2270Sstevel@tonic-gate 			j = $1.i;
2280Sstevel@tonic-gate 			for(k = 2; k<=$2.i;k++)
2290Sstevel@tonic-gate 				j = mn2(RCAT,j,dupl($1.i));
2300Sstevel@tonic-gate 			for(i = $2.i+1; i<=$4.i; i++){
2310Sstevel@tonic-gate 				g = dupl($1.i);
2320Sstevel@tonic-gate 				for(k=2;k<=i;k++)
2330Sstevel@tonic-gate 					g = mn2(RCAT,g,dupl($1.i));
2340Sstevel@tonic-gate 				j = mn2(BAR,j,g);
2350Sstevel@tonic-gate 				}
2360Sstevel@tonic-gate 			$$.i = j;
2370Sstevel@tonic-gate 			}
2380Sstevel@tonic-gate 	}
2390Sstevel@tonic-gate 	| r ITER '}'
2400Sstevel@tonic-gate 	={
2410Sstevel@tonic-gate 		if($2.i < 0)error("can't have negative iteration");
2420Sstevel@tonic-gate 		else if($2.i == 0) $$.i = mn0(RNULLS);
2430Sstevel@tonic-gate 		else {
2440Sstevel@tonic-gate 			j = $1.i;
2450Sstevel@tonic-gate 			for(k=2;k<=$2.i;k++)
2460Sstevel@tonic-gate 				j = mn2(RCAT,j,dupl($1.i));
2470Sstevel@tonic-gate 			$$.i = j;
2480Sstevel@tonic-gate 			}
2490Sstevel@tonic-gate 		}
2500Sstevel@tonic-gate 	| r ITER ',' '}'
2510Sstevel@tonic-gate 	={
2520Sstevel@tonic-gate 				/* from n to infinity */
2530Sstevel@tonic-gate 		if($2.i < 0)error("can't have negative iteration");
2540Sstevel@tonic-gate 		else if($2.i == 0) $$.i = mn1(STAR,$1.i);
2550Sstevel@tonic-gate 		else if($2.i == 1)$$.i = mn1(PLUS,$1.i);
2560Sstevel@tonic-gate 		else {		/* >= 2 iterations minimum */
2570Sstevel@tonic-gate 			j = $1.i;
2580Sstevel@tonic-gate 			for(k=2;k<$2.i;k++)
2590Sstevel@tonic-gate 				j = mn2(RCAT,j,dupl($1.i));
2600Sstevel@tonic-gate 			k = mn1(PLUS,dupl($1.i));
2610Sstevel@tonic-gate 			$$.i = mn2(RCAT,j,k);
2620Sstevel@tonic-gate 			}
2630Sstevel@tonic-gate 		}
2640Sstevel@tonic-gate 	| SCON r
2650Sstevel@tonic-gate 	={	$$.i = mn2(RSCON,$2.i,(uintptr_t)$1.cp); }
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 	/* XCU4: add XSCON */
2680Sstevel@tonic-gate 	| XSCON r
2690Sstevel@tonic-gate 	={	$$.i = mn2(RXSCON,$2.i,(uintptr_t)$1.cp); }
2700Sstevel@tonic-gate 	| '^' r
2710Sstevel@tonic-gate 	={	$$.i = mn1(CARAT,$2.i); }
2720Sstevel@tonic-gate 	| r '$'
2730Sstevel@tonic-gate 	={	i = mn0('\n');
2740Sstevel@tonic-gate 		if(!divflg){
2750Sstevel@tonic-gate 			j = mn1(S2FINAL,-casecount);
2760Sstevel@tonic-gate 			k = mn2(RCAT,$1.i,j);
2770Sstevel@tonic-gate 			$$.i = mn2(DIV,k,i);
2780Sstevel@tonic-gate 			}
2790Sstevel@tonic-gate 		else $$.i = mn2(RCAT,$1.i,i);
2800Sstevel@tonic-gate 		divflg = TRUE;
2810Sstevel@tonic-gate 		}
2820Sstevel@tonic-gate 	| '(' r ')'
2830Sstevel@tonic-gate 	={	$$.i = $2.i; }
2840Sstevel@tonic-gate 	|	NULLS
2850Sstevel@tonic-gate 	={	$$.i = mn0(RNULLS); }
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate 	/* XCU4: add ARRAY and POINTER */
2880Sstevel@tonic-gate 	| ARRAY
2890Sstevel@tonic-gate 	={ isArray = 1; };
2900Sstevel@tonic-gate 	|     POINTER
2910Sstevel@tonic-gate 	={ isArray = 0; };
2920Sstevel@tonic-gate 	;
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate %%
2950Sstevel@tonic-gate int
2960Sstevel@tonic-gate yylex(void)
2970Sstevel@tonic-gate {
2980Sstevel@tonic-gate 	CHR *p;
2990Sstevel@tonic-gate 	int  i;
3000Sstevel@tonic-gate 	CHR *xp;
3010Sstevel@tonic-gate 	int lex_startcond_lookupval;
3020Sstevel@tonic-gate 	CHR  *t, c;
3030Sstevel@tonic-gate 	int n, j = 0, k, x;
3040Sstevel@tonic-gate 	CHR ch;
3050Sstevel@tonic-gate 	static int sectbegin;
3060Sstevel@tonic-gate 	static CHR token[TOKENSIZE];
3070Sstevel@tonic-gate 	static int iter;
3080Sstevel@tonic-gate 	int ccs; /* Current CodeSet. */
3090Sstevel@tonic-gate 	CHR *ccp;
3100Sstevel@tonic-gate 	int exclusive_flag;	/* XCU4: exclusive start flag */
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate # ifdef DEBUG
3130Sstevel@tonic-gate 	yylval.i = 0;
3140Sstevel@tonic-gate # endif
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate 	if(sect == DEFSECTION) {		/* definitions section */
3170Sstevel@tonic-gate 		while(!eof) {
3180Sstevel@tonic-gate 			if(prev == '\n'){    /* next char is at beginning of line */
3190Sstevel@tonic-gate 				(void)getl(p=buf);
3200Sstevel@tonic-gate 				switch(*p){
3210Sstevel@tonic-gate 				case '%':
3220Sstevel@tonic-gate 					switch(c= *(p+1)){
3230Sstevel@tonic-gate 					case '%':
324*6951Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3250Sstevel@tonic-gate 						if(scomp(p, (CHR *)"%%")) {
3260Sstevel@tonic-gate 							p++;
3270Sstevel@tonic-gate 							while(*(++p))
3280Sstevel@tonic-gate 								if(!space(*p)) {
3290Sstevel@tonic-gate 									warning("invalid string following %%%% be ignored");
3300Sstevel@tonic-gate 									break;
3310Sstevel@tonic-gate 								}
3320Sstevel@tonic-gate 						}
3330Sstevel@tonic-gate 						lgate();
3340Sstevel@tonic-gate 						if(!ratfor)(void) fprintf(fout,"# ");
3350Sstevel@tonic-gate 						(void) fprintf(fout,"define YYNEWLINE %d\n",ctable['\n']);
3360Sstevel@tonic-gate 						if(!ratfor)(void) fprintf(fout,"int yylex(){\nint nstr; extern int yyprevious;\n");
3370Sstevel@tonic-gate 						sectbegin = TRUE;
3380Sstevel@tonic-gate 						i = treesize*(sizeof(*name)+sizeof(*left)+
3390Sstevel@tonic-gate 							sizeof(*right)+sizeof(*nullstr)+sizeof(*parent))+ALITTLEEXTRA;
3400Sstevel@tonic-gate 						c = (int)myalloc(i,1);
3410Sstevel@tonic-gate 						if(c == 0)
3420Sstevel@tonic-gate 							error("Too little core for parse tree");
3430Sstevel@tonic-gate 						p = (CHR *)c;
3440Sstevel@tonic-gate 						free(p);
345*6951Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3460Sstevel@tonic-gate 						name = (int *)myalloc(treesize,sizeof(*name));
347*6951Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3480Sstevel@tonic-gate 						left = (int *)myalloc(treesize,sizeof(*left));
349*6951Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3500Sstevel@tonic-gate 						right = (int *)myalloc(treesize,sizeof(*right));
3510Sstevel@tonic-gate 						nullstr = myalloc(treesize,sizeof(*nullstr));
352*6951Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3530Sstevel@tonic-gate 						parent = (int *)myalloc(treesize,sizeof(*parent));
3540Sstevel@tonic-gate 						if(name == 0 || left == 0 || right == 0 || parent == 0 || nullstr == 0)
3550Sstevel@tonic-gate 							error("Too little core for parse tree");
3560Sstevel@tonic-gate 						return(freturn(DELIM));
3570Sstevel@tonic-gate 					case 'p': case 'P':
3580Sstevel@tonic-gate 					        /* %p or %pointer */
3590Sstevel@tonic-gate 						if ((*(p+2) == 'o') ||
3600Sstevel@tonic-gate 						    (*(p+2) == 'O')) {
3610Sstevel@tonic-gate 						    if(lgatflg)
3620Sstevel@tonic-gate 							error("Too late for %%pointer");
3630Sstevel@tonic-gate 						    while(*p && !iswspace(*p))
3640Sstevel@tonic-gate 							p++;
3650Sstevel@tonic-gate 						    isArray = 0;
3660Sstevel@tonic-gate 						    continue;
3670Sstevel@tonic-gate 						}
3680Sstevel@tonic-gate 						/* has overridden number of positions */
3690Sstevel@tonic-gate 						p += 2;
3700Sstevel@tonic-gate 						maxpos = siconv(p);
3710Sstevel@tonic-gate 						if (maxpos<=0)error("illegal position number");
3720Sstevel@tonic-gate # ifdef DEBUG
3730Sstevel@tonic-gate 						if (debug) (void) printf("positions (%%p) now %d\n",maxpos);
3740Sstevel@tonic-gate # endif
3750Sstevel@tonic-gate 						if(report == 2)report = 1;
3760Sstevel@tonic-gate 						continue;
3770Sstevel@tonic-gate 					case 'n': case 'N':	/* has overridden number of states */
3780Sstevel@tonic-gate 						p += 2;
3790Sstevel@tonic-gate 						nstates = siconv(p);
3800Sstevel@tonic-gate 						if(nstates<=0)error("illegal state number");
3810Sstevel@tonic-gate # ifdef DEBUG
3820Sstevel@tonic-gate 						if(debug)(void) printf( " no. states (%%n) now %d\n",nstates);
3830Sstevel@tonic-gate # endif
3840Sstevel@tonic-gate 						if(report == 2)report = 1;
3850Sstevel@tonic-gate 						continue;
3860Sstevel@tonic-gate 					case 'e': case 'E':		/* has overridden number of tree nodes */
3870Sstevel@tonic-gate 						p += 2;
3880Sstevel@tonic-gate 						treesize = siconv(p);
3890Sstevel@tonic-gate 						if(treesize<=0)error("illegal number of parse tree nodes");
3900Sstevel@tonic-gate # ifdef DEBUG
3910Sstevel@tonic-gate 						if (debug) (void) printf("treesize (%%e) now %d\n",treesize);
3920Sstevel@tonic-gate # endif
3930Sstevel@tonic-gate 						if(report == 2)report = 1;
3940Sstevel@tonic-gate 						continue;
3950Sstevel@tonic-gate 					case 'o': case 'O':
3960Sstevel@tonic-gate 						p += 2;
3970Sstevel@tonic-gate 						outsize = siconv(p);
3980Sstevel@tonic-gate 						if(outsize<=0)error("illegal size of output array");
3990Sstevel@tonic-gate 						if (report ==2) report=1;
4000Sstevel@tonic-gate 						continue;
4010Sstevel@tonic-gate 					case 'a': case 'A':
4020Sstevel@tonic-gate 					        /* %a or %array */
4030Sstevel@tonic-gate 						if ((*(p+2) == 'r') ||
4040Sstevel@tonic-gate 						    (*(p+2) == 'R')) {
4050Sstevel@tonic-gate 						    if(lgatflg)
4060Sstevel@tonic-gate 							error("Too late for %%array");
4070Sstevel@tonic-gate 						    while(*p && !iswspace(*p))
4080Sstevel@tonic-gate 							p++;
4090Sstevel@tonic-gate 						    isArray = 1;
4100Sstevel@tonic-gate 						    continue;
4110Sstevel@tonic-gate 						}
4120Sstevel@tonic-gate 						/* has overridden number of transitions */
4130Sstevel@tonic-gate 						p += 2;
4140Sstevel@tonic-gate 						ntrans = siconv(p);
4150Sstevel@tonic-gate 						if(ntrans<=0)error("illegal translation number");
4160Sstevel@tonic-gate # ifdef DEBUG
4170Sstevel@tonic-gate 						if (debug)(void) printf("N. trans (%%a) now %d\n",ntrans);
4180Sstevel@tonic-gate # endif
4190Sstevel@tonic-gate 						if(report == 2)report = 1;
4200Sstevel@tonic-gate 						continue;
4210Sstevel@tonic-gate 					case 'k': case 'K': /* overriden packed char classes */
4220Sstevel@tonic-gate 						p += 2;
4230Sstevel@tonic-gate 						free(pchar);
4240Sstevel@tonic-gate 						pchlen = siconv(p);
4250Sstevel@tonic-gate 						if(pchlen<=0)error("illegal number of packed character class");
4260Sstevel@tonic-gate # ifdef DEBUG
4270Sstevel@tonic-gate 						if (debug) (void) printf( "Size classes (%%k) now %d\n",pchlen);
4280Sstevel@tonic-gate # endif
429*6951Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
4300Sstevel@tonic-gate 						pchar=pcptr=(CHR *)myalloc(pchlen, sizeof(*pchar));
4310Sstevel@tonic-gate 						if (report==2) report=1;
4320Sstevel@tonic-gate 						continue;
4330Sstevel@tonic-gate 					case 't': case 'T': 	/* character set specifier */
4340Sstevel@tonic-gate 						if(handleeuc)
4350Sstevel@tonic-gate 							error("\
4360Sstevel@tonic-gate Character table (%t) is supported only in ASCII compatibility mode.\n");
4370Sstevel@tonic-gate 						ZCH = watoi(p+2);
4380Sstevel@tonic-gate 						if (ZCH < NCH) ZCH = NCH;
4390Sstevel@tonic-gate 						if (ZCH > 2*NCH) error("ch table needs redeclaration");
4400Sstevel@tonic-gate 						chset = TRUE;
4410Sstevel@tonic-gate 						for(i = 0; i<ZCH; i++)
4420Sstevel@tonic-gate 							ctable[i] = 0;
4430Sstevel@tonic-gate 						while(getl(p) && scomp(p,L_PctUpT) != 0 && scomp(p,L_PctLoT) != 0){
4440Sstevel@tonic-gate 							if((n = siconv(p)) <= 0 || n > ZCH){
4450Sstevel@tonic-gate 								error("Character value %d out of range",n);
4460Sstevel@tonic-gate 								continue;
4470Sstevel@tonic-gate 								}
4480Sstevel@tonic-gate 							while(digit(*p)) p++;
4490Sstevel@tonic-gate 							if(!iswspace(*p)) error("bad translation format");
4500Sstevel@tonic-gate 							while(iswspace(*p)) p++;
4510Sstevel@tonic-gate 							t = p;
4520Sstevel@tonic-gate 							while(*t){
4530Sstevel@tonic-gate 								c = ctrans(&t);
4540Sstevel@tonic-gate 								if(ctable[(unsigned)c]){
4550Sstevel@tonic-gate 									if (iswprint(c))
4560Sstevel@tonic-gate 										warning("Character '%wc' used twice",c);
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate 									else
4590Sstevel@tonic-gate 										error("Chararter %o used twice",c);
4600Sstevel@tonic-gate 									}
4610Sstevel@tonic-gate 								else ctable[(unsigned)c] = n;
4620Sstevel@tonic-gate 								t++;
4630Sstevel@tonic-gate 								}
4640Sstevel@tonic-gate 							p = buf;
4650Sstevel@tonic-gate 							}
4660Sstevel@tonic-gate 						{
4670Sstevel@tonic-gate 						char chused[2*NCH]; int kr;
4680Sstevel@tonic-gate 						for(i=0; i<ZCH; i++)
4690Sstevel@tonic-gate 							chused[i]=0;
4700Sstevel@tonic-gate 						for(i=0; i<NCH; i++)
4710Sstevel@tonic-gate 							chused[ctable[i]]=1;
4720Sstevel@tonic-gate 						for(kr=i=1; i<NCH; i++)
4730Sstevel@tonic-gate 							if (ctable[i]==0)
4740Sstevel@tonic-gate 								{
4750Sstevel@tonic-gate 								while (chused[kr] == 0)
4760Sstevel@tonic-gate 									kr++;
4770Sstevel@tonic-gate 								ctable[i]=kr;
4780Sstevel@tonic-gate 								chused[kr]=1;
4790Sstevel@tonic-gate 								}
4800Sstevel@tonic-gate 						}
4810Sstevel@tonic-gate 						lgate();
4820Sstevel@tonic-gate 						continue;
4830Sstevel@tonic-gate 					case 'r': case 'R':
4840Sstevel@tonic-gate 						c = 'r';
4850Sstevel@tonic-gate 						/* FALLTHRU */
4860Sstevel@tonic-gate 					case 'c': case 'C':
4870Sstevel@tonic-gate 						if(lgatflg)
4880Sstevel@tonic-gate 							error("Too late for language specifier");
4890Sstevel@tonic-gate 						ratfor = (c == 'r');
4900Sstevel@tonic-gate 						continue;
4910Sstevel@tonic-gate 					case '{':
4920Sstevel@tonic-gate 						lgate();
4930Sstevel@tonic-gate 						while(getl(p) && scomp(p, L_PctCbr) != 0)
4940Sstevel@tonic-gate 							if(p[0]=='/' && p[1]=='*')
4950Sstevel@tonic-gate 								cpycom(p);
4960Sstevel@tonic-gate 							else
497*6951Sab196087 								(void) fprintf(fout,WSFMT("%ws\n"),p);
4980Sstevel@tonic-gate 						if(p[0] == '%') continue;
4990Sstevel@tonic-gate 						if (*p) error("EOF before %%%%");
5000Sstevel@tonic-gate 						else error("EOF before %%}");
5010Sstevel@tonic-gate 						break;
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate 					case 'x': case 'X':		/* XCU4: exclusive start conditions */
5040Sstevel@tonic-gate 						exclusive_flag = 1;
5050Sstevel@tonic-gate 						goto start;
5060Sstevel@tonic-gate 
5070Sstevel@tonic-gate 					case 's': case 'S':		/* start conditions */
5080Sstevel@tonic-gate 						exclusive_flag = 0;
5090Sstevel@tonic-gate start:
5100Sstevel@tonic-gate 						lgate();
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate 						while(*p && !iswspace(*p) && ((*p) != (wchar_t)',')) p++;
5130Sstevel@tonic-gate 						n = TRUE;
5140Sstevel@tonic-gate 						while(n){
5150Sstevel@tonic-gate 							while(*p && (iswspace(*p) || ((*p) == (wchar_t)','))) p++;
5160Sstevel@tonic-gate 							t = p;
5170Sstevel@tonic-gate 							while(*p && !iswspace(*p) && ((*p) != (wchar_t)',')) {
5180Sstevel@tonic-gate 							    if(!isascii(*p))
5190Sstevel@tonic-gate 								error("None-ASCII characters in start condition.");
5200Sstevel@tonic-gate 							    p++;
5210Sstevel@tonic-gate 							}
5220Sstevel@tonic-gate 							if(!*p) n = FALSE;
5230Sstevel@tonic-gate 							*p++ = 0;
5240Sstevel@tonic-gate 							if (*t == 0) continue;
5250Sstevel@tonic-gate 							i = sptr*2;
5260Sstevel@tonic-gate 							if(!ratfor)(void) fprintf(fout,"# ");
527*6951Sab196087 							(void) fprintf(fout,WSFMT("define %ws %d\n"),t,i);
5280Sstevel@tonic-gate 							scopy(t,sp);
5290Sstevel@tonic-gate 							sname[sptr] = sp;
5300Sstevel@tonic-gate 							/* XCU4: save exclusive flag with start name */
5310Sstevel@tonic-gate 							exclusive[sptr++] = exclusive_flag;
5320Sstevel@tonic-gate 							sname[sptr] = 0;	/* required by lookup */
5330Sstevel@tonic-gate 							if(sptr >= STARTSIZE)
5340Sstevel@tonic-gate 								error("Too many start conditions");
5350Sstevel@tonic-gate 							sp += slength(sp) + 1;
5360Sstevel@tonic-gate 							if(sp >= schar+STARTCHAR)
5370Sstevel@tonic-gate 								error("Start conditions too long");
5380Sstevel@tonic-gate 							}
5390Sstevel@tonic-gate 						continue;
5400Sstevel@tonic-gate 					default:
5410Sstevel@tonic-gate 						error("Invalid request %s",p);
5420Sstevel@tonic-gate 						continue;
5430Sstevel@tonic-gate 						}	/* end of switch after seeing '%' */
5440Sstevel@tonic-gate 					break;
5450Sstevel@tonic-gate 				case ' ': case '\t':		/* must be code */
5460Sstevel@tonic-gate 					lgate();
5470Sstevel@tonic-gate 					if( p[1]=='/' && p[2]=='*' ) cpycom(p);
548*6951Sab196087 					else (void) fprintf(fout, WSFMT("%ws\n"),p);
5490Sstevel@tonic-gate 					continue;
5500Sstevel@tonic-gate 				case '/':	/* look for comments */
5510Sstevel@tonic-gate 					lgate();
5520Sstevel@tonic-gate 					if((*(p+1))=='*') cpycom(p);
5530Sstevel@tonic-gate 					/* FALLTHRU */
5540Sstevel@tonic-gate 				default:		/* definition */
5550Sstevel@tonic-gate 					while(*p && !iswspace(*p)) p++;
5560Sstevel@tonic-gate 					if(*p == 0)
5570Sstevel@tonic-gate 						continue;
5580Sstevel@tonic-gate 					prev = *p;
5590Sstevel@tonic-gate 					*p = 0;
5600Sstevel@tonic-gate 					bptr = p+1;
5610Sstevel@tonic-gate 					yylval.cp = (CHR *)buf;
5620Sstevel@tonic-gate 					if(digit(buf[0]))
5630Sstevel@tonic-gate 						warning("Substitution strings may not begin with digits");
5640Sstevel@tonic-gate 					return(freturn(STR));
5650Sstevel@tonic-gate 				}
5660Sstevel@tonic-gate 			} else { /* still sect 1, but prev != '\n' */
5670Sstevel@tonic-gate 				p = bptr;
5680Sstevel@tonic-gate 				while(*p && iswspace(*p)) p++;
5690Sstevel@tonic-gate 				if(*p == 0)
5700Sstevel@tonic-gate 					warning("No translation given - null string assumed");
5710Sstevel@tonic-gate 				scopy(p,token);
5720Sstevel@tonic-gate 				yylval.cp = (CHR *)token;
5730Sstevel@tonic-gate 				prev = '\n';
5740Sstevel@tonic-gate 				return(freturn(STR));
5750Sstevel@tonic-gate 				}
5760Sstevel@tonic-gate 			}
5770Sstevel@tonic-gate 		error("unexpected EOF before %%%%");
5780Sstevel@tonic-gate 		/* end of section one processing */
5790Sstevel@tonic-gate 	} else if(sect == RULESECTION){		/* rules and actions */
5800Sstevel@tonic-gate 		lgate();
5810Sstevel@tonic-gate 		while(!eof){
5820Sstevel@tonic-gate 			static int first_test=TRUE, first_value;
5830Sstevel@tonic-gate 			static int reverse=FALSE;
5840Sstevel@tonic-gate 			switch(c=gch()){
5850Sstevel@tonic-gate 			case '\0':
5860Sstevel@tonic-gate 				if(n_error)error_tail();
5870Sstevel@tonic-gate 				return(freturn(0));
5880Sstevel@tonic-gate 			case '\n':
5890Sstevel@tonic-gate 				if(prev == '\n') continue;
5900Sstevel@tonic-gate 				x = NEWE;
5910Sstevel@tonic-gate 				break;
5920Sstevel@tonic-gate 			case ' ':
5930Sstevel@tonic-gate 			case '\t':
5940Sstevel@tonic-gate 				if(prev == '\n') copy_line = TRUE;
5950Sstevel@tonic-gate 				if(sectbegin == TRUE){
5960Sstevel@tonic-gate 					(void)cpyact();
5970Sstevel@tonic-gate 					copy_line = FALSE;
598*6951Sab196087 					/*LINTED: E_EQUALITY_NOT_ASSIGNMENT*/
5990Sstevel@tonic-gate 					while((c=gch()) && c != '\n');
6000Sstevel@tonic-gate 					continue;
6010Sstevel@tonic-gate 					}
6020Sstevel@tonic-gate 				if(!funcflag)phead2();
6030Sstevel@tonic-gate 				funcflag = TRUE;
6040Sstevel@tonic-gate 				if(ratfor)(void) fprintf(fout,"%d\n",30000+casecount);
6050Sstevel@tonic-gate 				else (void) fprintf(fout,"case %d:\n",casecount);
6060Sstevel@tonic-gate 				if(cpyact()){
6070Sstevel@tonic-gate 					if(ratfor)(void) fprintf(fout,"goto 30997\n");
6080Sstevel@tonic-gate 					else (void) fprintf(fout,"break;\n");
6090Sstevel@tonic-gate 					}
610*6951Sab196087 				/*LINTED: E_EQUALITY_NOT_ASSIGNMENT*/
6110Sstevel@tonic-gate 				while((c=gch()) && c != '\n') {
6120Sstevel@tonic-gate 					if (c=='/') {
6130Sstevel@tonic-gate 						if((c=gch())=='*') {
6140Sstevel@tonic-gate 							c=gch();
6150Sstevel@tonic-gate 							while(c !=EOF) {
6160Sstevel@tonic-gate 								while (c=='*')
6170Sstevel@tonic-gate 									if ((c=gch()) == '/') goto w_loop;
6180Sstevel@tonic-gate 								c = gch();
6190Sstevel@tonic-gate 							}
6200Sstevel@tonic-gate 							error("EOF inside comment");
6210Sstevel@tonic-gate 						} else
6220Sstevel@tonic-gate 							warning("undefined string");
6230Sstevel@tonic-gate 					} else if (c=='}')
6240Sstevel@tonic-gate 						error("illegal extra \"}\"");
6250Sstevel@tonic-gate 				w_loop: ;
6260Sstevel@tonic-gate 				}
6270Sstevel@tonic-gate 				/* while ((c=gch())== ' ' || c == '\t') ; */
6280Sstevel@tonic-gate 				/* if (!space(c)) error("undefined action string"); */
6290Sstevel@tonic-gate 				if(peek == ' ' || peek == '\t' || sectbegin == TRUE){
6300Sstevel@tonic-gate 					fatal = 0;
6310Sstevel@tonic-gate 					n_error++;
6320Sstevel@tonic-gate 					error("executable statements should occur right after %%%%");
6330Sstevel@tonic-gate 					fatal = 1;
6340Sstevel@tonic-gate 					continue;
6350Sstevel@tonic-gate 					}
6360Sstevel@tonic-gate 				x = NEWE;
6370Sstevel@tonic-gate 				break;
6380Sstevel@tonic-gate 			case '%':
6390Sstevel@tonic-gate 				if(prev != '\n') goto character;
6400Sstevel@tonic-gate 				if(peek == '{'){	/* included code */
6410Sstevel@tonic-gate 					(void)getl(buf);
6420Sstevel@tonic-gate 					while(!eof&& getl(buf) && scomp(L_PctCbr,buf)!=0)
6430Sstevel@tonic-gate 						if(buf[0]=='/' && buf[1]=='*')
6440Sstevel@tonic-gate 							cpycom(buf);
6450Sstevel@tonic-gate 						else
646*6951Sab196087 							(void) fprintf(fout,WSFMT("%ws\n"),buf);
6470Sstevel@tonic-gate 					continue;
6480Sstevel@tonic-gate 					}
6490Sstevel@tonic-gate 				if(peek == '%'){
6500Sstevel@tonic-gate 					c = gch();
6510Sstevel@tonic-gate 					c = gch();
6520Sstevel@tonic-gate 					x = DELIM;
6530Sstevel@tonic-gate 					break;
6540Sstevel@tonic-gate 					}
6550Sstevel@tonic-gate 				goto character;
6560Sstevel@tonic-gate 			case '|':
6570Sstevel@tonic-gate 				if(peek == ' ' || peek == '\t' || peek == '\n'){
6580Sstevel@tonic-gate 					if(ratfor)(void) fprintf(fout,"%d\n",30000+casecount++);
6590Sstevel@tonic-gate 					else (void) fprintf(fout,"case %d:\n",casecount++);
6600Sstevel@tonic-gate 					continue;
6610Sstevel@tonic-gate 					}
6620Sstevel@tonic-gate 				x = '|';
6630Sstevel@tonic-gate 				break;
6640Sstevel@tonic-gate 			case '$':
6650Sstevel@tonic-gate 				if(peek == '\n' || peek == ' ' || peek == '\t' || peek == '|' || peek == '/'){
6660Sstevel@tonic-gate 					x = c;
6670Sstevel@tonic-gate 					break;
6680Sstevel@tonic-gate 					}
6690Sstevel@tonic-gate 				goto character;
6700Sstevel@tonic-gate 			case '^':
6710Sstevel@tonic-gate                                 if(peekon && (prev == '}')){
6720Sstevel@tonic-gate                                         x = c;
6730Sstevel@tonic-gate                                         break;
6740Sstevel@tonic-gate                                 }
6750Sstevel@tonic-gate 				if(prev != '\n' && scon != TRUE) goto character;
6760Sstevel@tonic-gate 				/* valid only at line begin */
6770Sstevel@tonic-gate 				x = c;
6780Sstevel@tonic-gate 				break;
6790Sstevel@tonic-gate 			case '?':
6800Sstevel@tonic-gate 			case '+':
6810Sstevel@tonic-gate 			case '*':
6820Sstevel@tonic-gate 				if(prev == '\n' ) {
6830Sstevel@tonic-gate 					fatal = 0;
6840Sstevel@tonic-gate 					n_error++;
6850Sstevel@tonic-gate 					error("illegal operator -- %c",c);
6860Sstevel@tonic-gate 					fatal = 1;
6870Sstevel@tonic-gate 				}
6880Sstevel@tonic-gate 				/* FALLTHRU */
6890Sstevel@tonic-gate 			case '.':
6900Sstevel@tonic-gate 			case '(':
6910Sstevel@tonic-gate 			case ')':
6920Sstevel@tonic-gate 			case ',':
6930Sstevel@tonic-gate 			case '/':
6940Sstevel@tonic-gate 				x = c;
6950Sstevel@tonic-gate 				break;
6960Sstevel@tonic-gate 			case '}':
6970Sstevel@tonic-gate 				iter = FALSE;
6980Sstevel@tonic-gate 				x = c;
6990Sstevel@tonic-gate 				break;
7000Sstevel@tonic-gate 			case '{':	/* either iteration or definition */
7010Sstevel@tonic-gate 				if(digit(c=gch())){	/* iteration */
7020Sstevel@tonic-gate 					iter = TRUE;
7030Sstevel@tonic-gate 					if(prev=='{') first_test = TRUE;
7040Sstevel@tonic-gate 				ieval:
7050Sstevel@tonic-gate 					i = 0;
7060Sstevel@tonic-gate 					while(digit(c)){
7070Sstevel@tonic-gate 						token[i++] = c;
7080Sstevel@tonic-gate 						c = gch();
7090Sstevel@tonic-gate 						}
7100Sstevel@tonic-gate 					token[i] = 0;
7110Sstevel@tonic-gate 					yylval.i = siconv(token);
7120Sstevel@tonic-gate 					if(first_test) {
7130Sstevel@tonic-gate 						first_test = FALSE;
7140Sstevel@tonic-gate 						first_value = yylval.i;
7150Sstevel@tonic-gate 					} else
7160Sstevel@tonic-gate 						if(first_value>yylval.i)warning("the values between braces are reversed");
7170Sstevel@tonic-gate 					ch = c;
7180Sstevel@tonic-gate 					munput('c',&ch);
7190Sstevel@tonic-gate 					x = ITER;
7200Sstevel@tonic-gate 					break;
7210Sstevel@tonic-gate 					}
7220Sstevel@tonic-gate 				else {		/* definition */
7230Sstevel@tonic-gate 					i = 0;
7240Sstevel@tonic-gate 					while(c && c!='}'){
7250Sstevel@tonic-gate 						token[i++] = c;
7260Sstevel@tonic-gate 						if(i >= TOKENSIZE)
7270Sstevel@tonic-gate 							error("definition too long");
7280Sstevel@tonic-gate 						c = gch();
7290Sstevel@tonic-gate 						}
7300Sstevel@tonic-gate 					token[i] = 0;
7310Sstevel@tonic-gate 					i = lookup(token,def);
7320Sstevel@tonic-gate 					if(i < 0)
7330Sstevel@tonic-gate 						error("definition %ws not found",token);
7340Sstevel@tonic-gate 					else
7350Sstevel@tonic-gate 						munput('s',(CHR *)(subs[i]));
7360Sstevel@tonic-gate             				if (peek == '^')
7370Sstevel@tonic-gate                                                 peekon = 1;
7380Sstevel@tonic-gate 					continue;
7390Sstevel@tonic-gate 					}
7400Sstevel@tonic-gate 			case '<':		/* start condition ? */
7410Sstevel@tonic-gate 				if(prev != '\n')  /* not at line begin, not start */
7420Sstevel@tonic-gate 					goto character;
7430Sstevel@tonic-gate 				t = slptr;
7440Sstevel@tonic-gate 				do {
7450Sstevel@tonic-gate 					i = 0;
7460Sstevel@tonic-gate 					if(!isascii(c = gch()))
7470Sstevel@tonic-gate 					    error("Non-ASCII characters in start condition.");
7480Sstevel@tonic-gate 					while(c != ',' && c && c != '>'){
7490Sstevel@tonic-gate 						token[i++] = c;
7500Sstevel@tonic-gate 						if(i >= TOKENSIZE)
7510Sstevel@tonic-gate 							error("string name too long");
7520Sstevel@tonic-gate 						if(!isascii(c = gch()))
7530Sstevel@tonic-gate 						    error("None-ASCII characters in start condition.");
7540Sstevel@tonic-gate 						}
7550Sstevel@tonic-gate 					token[i] = 0;
7560Sstevel@tonic-gate 					if(i == 0)
7570Sstevel@tonic-gate 						goto character;
7580Sstevel@tonic-gate 					i = lookup(token,sname);
7590Sstevel@tonic-gate 					lex_startcond_lookupval = i;
7600Sstevel@tonic-gate 					if(i < 0) {
7610Sstevel@tonic-gate 						fatal = 0;
7620Sstevel@tonic-gate 						n_error++;
7630Sstevel@tonic-gate 						error("undefined start condition %ws",token);
7640Sstevel@tonic-gate 						fatal = 1;
7650Sstevel@tonic-gate 						continue;
7660Sstevel@tonic-gate 						}
7670Sstevel@tonic-gate 					*slptr++ = i+1;
7680Sstevel@tonic-gate 					} while(c && c != '>');
7690Sstevel@tonic-gate 				*slptr++ = 0;
7700Sstevel@tonic-gate 				/* check if previous value re-usable */
7710Sstevel@tonic-gate 				for (xp=slist; xp<t; )
7720Sstevel@tonic-gate 					{
7730Sstevel@tonic-gate 					if (scomp(xp, t)==0)
7740Sstevel@tonic-gate 						break;
7750Sstevel@tonic-gate 					while (*xp++);
7760Sstevel@tonic-gate 					}
7770Sstevel@tonic-gate 				if (xp<t)
7780Sstevel@tonic-gate 					{
7790Sstevel@tonic-gate 					/* re-use previous pointer to string */
7800Sstevel@tonic-gate 					slptr=t;
7810Sstevel@tonic-gate 					t=xp;
7820Sstevel@tonic-gate 					}
7830Sstevel@tonic-gate 				if(slptr > slist+STARTSIZE)	/* note not packed */
7840Sstevel@tonic-gate 					error("Too many start conditions used");
7850Sstevel@tonic-gate 				yylval.cp = (CHR *)t;
7860Sstevel@tonic-gate 
7870Sstevel@tonic-gate 				/* XCU4: add XSCON */
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate 				if (exclusive[lex_startcond_lookupval])
7900Sstevel@tonic-gate 					x = XSCON;
7910Sstevel@tonic-gate 				else
7920Sstevel@tonic-gate 					x = SCON;
7930Sstevel@tonic-gate 				break;
7940Sstevel@tonic-gate 			case '"':
7950Sstevel@tonic-gate 				i = 0;
796*6951Sab196087 				/*LINTED: E_EQUALITY_NOT_ASSIGNMENT*/
7970Sstevel@tonic-gate 				while((c=gch()) && c != '"' && c != '\n'){
7980Sstevel@tonic-gate 					if(c == '\\') c = usescape(c=gch());
7990Sstevel@tonic-gate 					remch(c);
8000Sstevel@tonic-gate 					token[i++] = c;
8010Sstevel@tonic-gate 					if(i >= TOKENSIZE){
8020Sstevel@tonic-gate 						warning("String too long");
8030Sstevel@tonic-gate 						i = TOKENSIZE-1;
8040Sstevel@tonic-gate 						break;
8050Sstevel@tonic-gate 						}
8060Sstevel@tonic-gate 					}
8070Sstevel@tonic-gate 				if(c == '\n') {
8080Sstevel@tonic-gate 					yyline--;
8090Sstevel@tonic-gate 					warning("Non-terminated string");
8100Sstevel@tonic-gate 					yyline++;
8110Sstevel@tonic-gate 					}
8120Sstevel@tonic-gate 				token[i] = 0;
8130Sstevel@tonic-gate 				if(i == 0)x = NULLS;
8140Sstevel@tonic-gate 				else if(i == 1){
8150Sstevel@tonic-gate 					yylval.i = (unsigned)token[0];
8160Sstevel@tonic-gate 					x = CHAR;
8170Sstevel@tonic-gate 					}
8180Sstevel@tonic-gate 				else {
8190Sstevel@tonic-gate 					yylval.cp = (CHR *)token;
8200Sstevel@tonic-gate 					x = STR;
8210Sstevel@tonic-gate 					}
8220Sstevel@tonic-gate 				break;
8230Sstevel@tonic-gate 			case '[':
8240Sstevel@tonic-gate 				reverse = FALSE;
8250Sstevel@tonic-gate 				x = CCL;
8260Sstevel@tonic-gate 				if((c = gch()) == '^'){
8270Sstevel@tonic-gate 					x = NCCL;
8280Sstevel@tonic-gate 					reverse = TRUE;
8290Sstevel@tonic-gate 					c = gch();
8300Sstevel@tonic-gate 					}
8310Sstevel@tonic-gate 				i = 0;
8320Sstevel@tonic-gate 				while(c != ']' && c){
8330Sstevel@tonic-gate 					static int light=TRUE, ESCAPE=FALSE;
8340Sstevel@tonic-gate 					if(c == '-' && prev == '^' && reverse){
8350Sstevel@tonic-gate 						symbol[(unsigned)c] = 1;
8360Sstevel@tonic-gate 						c = gch();
8370Sstevel@tonic-gate 						continue;
8380Sstevel@tonic-gate 					}
8390Sstevel@tonic-gate 					if(c == '\\') {
8400Sstevel@tonic-gate 						c = usescape(c=gch());
8410Sstevel@tonic-gate 						ESCAPE = TRUE;
8420Sstevel@tonic-gate 					}
8430Sstevel@tonic-gate 					if(c=='-' && !ESCAPE && prev!='[' && peek!=']'){
8440Sstevel@tonic-gate 					/* range specified */
8450Sstevel@tonic-gate 						if (light) {
8460Sstevel@tonic-gate 							c = gch();
8470Sstevel@tonic-gate 							if(c == '\\')
8480Sstevel@tonic-gate 								c=usescape(c=gch());
8490Sstevel@tonic-gate 							remch(c);
8500Sstevel@tonic-gate 							k = c;
8510Sstevel@tonic-gate 							ccs=wcsetno(k);
8520Sstevel@tonic-gate 							if(wcsetno(j)!=ccs)
8530Sstevel@tonic-gate 							    error("\
8540Sstevel@tonic-gate Character range specified between different codesets.");
8550Sstevel@tonic-gate 							if((unsigned)j > (unsigned)k) {
8560Sstevel@tonic-gate 								n = j;
8570Sstevel@tonic-gate 								j = k;
8580Sstevel@tonic-gate 								k = n;
8590Sstevel@tonic-gate 								}
8600Sstevel@tonic-gate 							if(!handleeuc)
8610Sstevel@tonic-gate 							if(!(('A'<=j && k<='Z') ||
8620Sstevel@tonic-gate 						     	     ('a'<=j && k<='z') ||
8630Sstevel@tonic-gate 						     	     ('0'<=j && k<='9')))
8640Sstevel@tonic-gate 								warning("Non-portable Character Class");
8650Sstevel@tonic-gate 							token[i++] = RANGE;
8660Sstevel@tonic-gate 							token[i++] = j;
8670Sstevel@tonic-gate 							token[i++] = k;
8680Sstevel@tonic-gate 							light = FALSE;
8690Sstevel@tonic-gate 						} else {
8700Sstevel@tonic-gate 							error("unmatched hyphen");
8710Sstevel@tonic-gate 							if(symbol[(unsigned)c])warning("\"%c\" redefined inside brackets",c);
8720Sstevel@tonic-gate 							else symbol[(unsigned)c] = 1;
8730Sstevel@tonic-gate 						}
8740Sstevel@tonic-gate 						ESCAPE = FALSE;
8750Sstevel@tonic-gate 					} else {
8760Sstevel@tonic-gate 						j = c;
8770Sstevel@tonic-gate 						remch(c);
8780Sstevel@tonic-gate 						token[i++] = c; /* Remember whatever.*/
8790Sstevel@tonic-gate 						light = TRUE;
8800Sstevel@tonic-gate 						ESCAPE = FALSE;
8810Sstevel@tonic-gate 					}
8820Sstevel@tonic-gate 					c = gch();
8830Sstevel@tonic-gate 				}
8840Sstevel@tonic-gate 				/* try to pack ccl's */
8850Sstevel@tonic-gate 
8860Sstevel@tonic-gate 				token[i] = 0;
8870Sstevel@tonic-gate 				ccp = ccl;
8880Sstevel@tonic-gate 				while (ccp < ccptr && scomp(token, ccp) != 0) ccp++;
8890Sstevel@tonic-gate 				if (ccp < ccptr) {  /* found in ccl */
8900Sstevel@tonic-gate 				    yylval.cp = ccp;
8910Sstevel@tonic-gate 				} else {            /* not in ccl, add it */
8920Sstevel@tonic-gate 				    scopy(token,ccptr);
8930Sstevel@tonic-gate 				    yylval.cp = ccptr;
8940Sstevel@tonic-gate 				    ccptr += slength(token) + 1;
8950Sstevel@tonic-gate 				    if(ccptr >= ccl+CCLSIZE)
8960Sstevel@tonic-gate 				      error("Too many large character classes");
8970Sstevel@tonic-gate 				}
8980Sstevel@tonic-gate 				break;
8990Sstevel@tonic-gate 			case '\\':
9000Sstevel@tonic-gate 				c = usescape(c=gch());
9010Sstevel@tonic-gate 			default:
9020Sstevel@tonic-gate 			character:
9030Sstevel@tonic-gate 				if(iter){	/* second part of an iteration */
9040Sstevel@tonic-gate 					iter = FALSE;
9050Sstevel@tonic-gate 					if('0' <= c && c <= '9')
9060Sstevel@tonic-gate 						goto ieval;
9070Sstevel@tonic-gate 					}
9080Sstevel@tonic-gate 				remch(c);
9090Sstevel@tonic-gate 				if(alpha(peek)){
9100Sstevel@tonic-gate 					i = 0;
9110Sstevel@tonic-gate 					yylval.cp = (CHR *)token;
9120Sstevel@tonic-gate 					token[i++] = c;
9130Sstevel@tonic-gate 					while(alpha(peek)) {
9140Sstevel@tonic-gate 						remch(token[i++] = gch());
9150Sstevel@tonic-gate 						if(i >= TOKENSIZE) {
9160Sstevel@tonic-gate 							warning("string too long");
9170Sstevel@tonic-gate 							i = TOKENSIZE - 1;
9180Sstevel@tonic-gate 							break;
9190Sstevel@tonic-gate 							}
9200Sstevel@tonic-gate 						}
9210Sstevel@tonic-gate 					if(peek == '?' || peek == '*' || peek == '+')
9220Sstevel@tonic-gate 						munput('c',&token[--i]);
9230Sstevel@tonic-gate 					token[i] = 0;
9240Sstevel@tonic-gate 					if(i == 1){
9250Sstevel@tonic-gate 						yylval.i = (unsigned)(token[0]);
9260Sstevel@tonic-gate 						x = CHAR;
9270Sstevel@tonic-gate 						}
9280Sstevel@tonic-gate 					else x = STR;
9290Sstevel@tonic-gate 					}
9300Sstevel@tonic-gate 				else {
9310Sstevel@tonic-gate 					yylval.i = (unsigned)c;
9320Sstevel@tonic-gate 					x = CHAR;
9330Sstevel@tonic-gate 					}
9340Sstevel@tonic-gate 				}
9350Sstevel@tonic-gate 			scon = FALSE;
9360Sstevel@tonic-gate 			peekon = 0;
9370Sstevel@tonic-gate 			if((x == SCON) || (x == XSCON))
9380Sstevel@tonic-gate 				scon = TRUE;
9390Sstevel@tonic-gate 			sectbegin = FALSE;
9400Sstevel@tonic-gate 			return(freturn(x));
9410Sstevel@tonic-gate 			/* NOTREACHED */
9420Sstevel@tonic-gate 			}
9430Sstevel@tonic-gate 		}
9440Sstevel@tonic-gate 	/* section three */
9450Sstevel@tonic-gate 	lgate();
9460Sstevel@tonic-gate 	ptail();
9470Sstevel@tonic-gate # ifdef DEBUG
9480Sstevel@tonic-gate 	if(debug)
9490Sstevel@tonic-gate 		(void) fprintf(fout,"\n/*this comes from section three - debug */\n");
9500Sstevel@tonic-gate # endif
9510Sstevel@tonic-gate 
9520Sstevel@tonic-gate 	if(getl(buf) && !eof) {
9530Sstevel@tonic-gate   		if (sargv[optind] == NULL)
9540Sstevel@tonic-gate 			(void) fprintf(fout, "\n# line %d\n", yyline-1);
9550Sstevel@tonic-gate 		else
9560Sstevel@tonic-gate 			(void) fprintf(fout,
9570Sstevel@tonic-gate 				"\n# line %d \"%s\"\n", yyline-1, sargv[optind]);
958*6951Sab196087 		(void) fprintf(fout,WSFMT("%ws\n"),buf);
9590Sstevel@tonic-gate 		while(getl(buf) && !eof)
960*6951Sab196087 			(void) fprintf(fout,WSFMT("%ws\n"),buf);
9610Sstevel@tonic-gate         }
9620Sstevel@tonic-gate 
9630Sstevel@tonic-gate 	return(freturn(0));
9640Sstevel@tonic-gate 	}
9650Sstevel@tonic-gate /* end of yylex */
9660Sstevel@tonic-gate # ifdef DEBUG
freturn(i)9670Sstevel@tonic-gate freturn(i)
9680Sstevel@tonic-gate   int i; {
9690Sstevel@tonic-gate 	if(yydebug) {
9700Sstevel@tonic-gate 		(void) printf("now return ");
9710Sstevel@tonic-gate 		if((unsigned)i < NCH) allprint(i);
9720Sstevel@tonic-gate 		else (void) printf("%d",i);
9730Sstevel@tonic-gate 		(void) printf("   yylval = ");
9740Sstevel@tonic-gate 		switch(i){
9750Sstevel@tonic-gate 			case STR: case CCL: case NCCL:
9760Sstevel@tonic-gate 				strpt(yylval.cp);
9770Sstevel@tonic-gate 				break;
9780Sstevel@tonic-gate 			case CHAR:
9790Sstevel@tonic-gate 				allprint(yylval.i);
9800Sstevel@tonic-gate 				break;
9810Sstevel@tonic-gate 			default:
9820Sstevel@tonic-gate 				(void) printf("%d",yylval.i);
9830Sstevel@tonic-gate 				break;
9840Sstevel@tonic-gate 			}
9850Sstevel@tonic-gate 		(void) putchar('\n');
9860Sstevel@tonic-gate 		}
9870Sstevel@tonic-gate 	return(i);
9880Sstevel@tonic-gate 	}
9890Sstevel@tonic-gate # endif
990