xref: /illumos-gate/usr/src/cmd/sgs/lex/common/parser.y (revision 724c5feb)
17c478bd9Sstevel@tonic-gate %{
27c478bd9Sstevel@tonic-gate /*
37c478bd9Sstevel@tonic-gate  * CDDL HEADER START
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
667298654Sdamico  * Common Development and Distribution License (the "License").
767298654Sdamico  * You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate %}
23*724c5febSToomas Soome 
247c478bd9Sstevel@tonic-gate /*
251dd08564Sab196087  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
307c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate %{
33*724c5febSToomas Soome #include "ldefs.h"
347c478bd9Sstevel@tonic-gate 
35*724c5febSToomas Soome #define YYSTYPE union _yystype_
36*724c5febSToomas Soome union _yystype_
37*724c5febSToomas Soome {
38*724c5febSToomas Soome 	int	i;
39*724c5febSToomas Soome 	CHR	*cp;
40*724c5febSToomas Soome };
41*724c5febSToomas Soome int	peekon = 0; /* need this to check if "^" came in a definition section */
42*724c5febSToomas Soome int i;
43*724c5febSToomas Soome int j,k;
44*724c5febSToomas Soome int g;
45*724c5febSToomas Soome CHR *p;
46*724c5febSToomas Soome static wchar_t  L_PctUpT[]= {'%', 'T', 0};
47*724c5febSToomas Soome static wchar_t  L_PctLoT[]= {'%', 't', 0};
48*724c5febSToomas Soome static wchar_t  L_PctCbr[]= {'%', '}', 0};
491dd08564Sab196087 
507c478bd9Sstevel@tonic-gate void yyerror(char *);
517c478bd9Sstevel@tonic-gate %}
52*724c5febSToomas Soome 
537c478bd9Sstevel@tonic-gate /* parser.y */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /* XCU4: add XSCON: %x exclusive start token */
567c478bd9Sstevel@tonic-gate /* XCU4: add ARRAY: %a yytext is char array */
577c478bd9Sstevel@tonic-gate /* XCU4: add POINTER: %p yytext is a pointer to char */
587c478bd9Sstevel@tonic-gate %token CHAR CCL NCCL STR DELIM SCON ITER NEWE NULLS XSCON ARRAY POINTER
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate %nonassoc ARRAY POINTER
617c478bd9Sstevel@tonic-gate %left XSCON SCON NEWE
627c478bd9Sstevel@tonic-gate %left '/'
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * XCU4: lower the precedence of $ and ^ to less than the or operator
657c478bd9Sstevel@tonic-gate  * per Spec. 1170
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate %left '$' '^'
687c478bd9Sstevel@tonic-gate %left '|'
697c478bd9Sstevel@tonic-gate %left CHAR CCL NCCL '(' '.' STR NULLS
707c478bd9Sstevel@tonic-gate %left ITER
717c478bd9Sstevel@tonic-gate %left CAT
727c478bd9Sstevel@tonic-gate %left '*' '+' '?'
737c478bd9Sstevel@tonic-gate %%
74*724c5febSToomas Soome 
757c478bd9Sstevel@tonic-gate acc	:	lexinput
76*724c5febSToomas Soome 	{
777c478bd9Sstevel@tonic-gate # ifdef DEBUG
787c478bd9Sstevel@tonic-gate 		if(debug) sect2dump();
797c478bd9Sstevel@tonic-gate # endif
807c478bd9Sstevel@tonic-gate 	}
817c478bd9Sstevel@tonic-gate 	;
827c478bd9Sstevel@tonic-gate lexinput:	defns delim prods end
837c478bd9Sstevel@tonic-gate 	|	defns delim end
84*724c5febSToomas Soome 	{
857c478bd9Sstevel@tonic-gate 		if(!funcflag)phead2();
867c478bd9Sstevel@tonic-gate 		funcflag = TRUE;
877c478bd9Sstevel@tonic-gate 	}
887c478bd9Sstevel@tonic-gate 	| error
89*724c5febSToomas Soome 	{
907c478bd9Sstevel@tonic-gate # ifdef DEBUG
917c478bd9Sstevel@tonic-gate 		if(debug) {
927c478bd9Sstevel@tonic-gate 			sect1dump();
937c478bd9Sstevel@tonic-gate 			sect2dump();
947c478bd9Sstevel@tonic-gate 			}
957c478bd9Sstevel@tonic-gate # endif
967c478bd9Sstevel@tonic-gate 		fatal = 0;
977c478bd9Sstevel@tonic-gate 		n_error++;
987c478bd9Sstevel@tonic-gate 		error("Illegal definition");
997c478bd9Sstevel@tonic-gate 		fatal = 1;
1007c478bd9Sstevel@tonic-gate 		}
1017c478bd9Sstevel@tonic-gate 	;
1027c478bd9Sstevel@tonic-gate end:		delim | ;
1037c478bd9Sstevel@tonic-gate defns:	defns STR STR
104*724c5febSToomas Soome 	{	scopy($2.cp,dp);
1057c478bd9Sstevel@tonic-gate 		def[dptr] = dp;
1067c478bd9Sstevel@tonic-gate 		dp += slength($2.cp) + 1;
1077c478bd9Sstevel@tonic-gate 		scopy($3.cp,dp);
1087c478bd9Sstevel@tonic-gate 		subs[dptr++] = dp;
1097c478bd9Sstevel@tonic-gate 		if(dptr >= DEFSIZE)
1107c478bd9Sstevel@tonic-gate 			error("Too many definitions");
1117c478bd9Sstevel@tonic-gate 		dp += slength($3.cp) + 1;
1127c478bd9Sstevel@tonic-gate 		if(dp >= dchar+DEFCHAR)
1137c478bd9Sstevel@tonic-gate 			error("Definitions too long");
1147c478bd9Sstevel@tonic-gate 		subs[dptr]=def[dptr]=0;	/* for lookup - require ending null */
1157c478bd9Sstevel@tonic-gate 	}
1167c478bd9Sstevel@tonic-gate 	|
1177c478bd9Sstevel@tonic-gate 	;
1187c478bd9Sstevel@tonic-gate delim:	DELIM
119*724c5febSToomas Soome 	{
1207c478bd9Sstevel@tonic-gate # ifdef DEBUG
1217c478bd9Sstevel@tonic-gate 		if(sect == DEFSECTION && debug) sect1dump();
1227c478bd9Sstevel@tonic-gate # endif
1237c478bd9Sstevel@tonic-gate 		sect++;
1247c478bd9Sstevel@tonic-gate 		}
1257c478bd9Sstevel@tonic-gate 	;
1267c478bd9Sstevel@tonic-gate prods:	prods pr
127*724c5febSToomas Soome 	{	$$.i = mn2(RNEWE,$1.i,$2.i);
1287c478bd9Sstevel@tonic-gate 		}
1297c478bd9Sstevel@tonic-gate 	|	pr
130*724c5febSToomas Soome 	{	$$.i = $1.i;}
1317c478bd9Sstevel@tonic-gate 	;
1327c478bd9Sstevel@tonic-gate pr:	r NEWE
133*724c5febSToomas Soome 	{
1347c478bd9Sstevel@tonic-gate 		if(divflg == TRUE)
1357c478bd9Sstevel@tonic-gate 			i = mn1(S1FINAL,casecount);
1367c478bd9Sstevel@tonic-gate 		else i = mn1(FINAL,casecount);
1377c478bd9Sstevel@tonic-gate 		$$.i = mn2(RCAT,$1.i,i);
1387c478bd9Sstevel@tonic-gate 		divflg = FALSE;
1397c478bd9Sstevel@tonic-gate 		if((++casecount)>NACTIONS)
1407c478bd9Sstevel@tonic-gate 			error("Too many (>%d) pattern-action rules.", NACTIONS);
1417c478bd9Sstevel@tonic-gate 		}
1427c478bd9Sstevel@tonic-gate 	| error NEWE
143*724c5febSToomas Soome 	{
1447c478bd9Sstevel@tonic-gate # ifdef DEBUG
1457c478bd9Sstevel@tonic-gate 		if(debug) sect2dump();
1467c478bd9Sstevel@tonic-gate # endif
1477c478bd9Sstevel@tonic-gate 		fatal = 0;
1487c478bd9Sstevel@tonic-gate 		yyline--;
1497c478bd9Sstevel@tonic-gate 		n_error++;
1507c478bd9Sstevel@tonic-gate 		error("Illegal rule");
1517c478bd9Sstevel@tonic-gate 		fatal = 1;
1527c478bd9Sstevel@tonic-gate 		yyline++;
1537c478bd9Sstevel@tonic-gate 		}
1547c478bd9Sstevel@tonic-gate r:	CHAR
155*724c5febSToomas Soome 	{	$$.i = mn0($1.i); }
1567c478bd9Sstevel@tonic-gate 	| STR
157*724c5febSToomas Soome 	{
1587c478bd9Sstevel@tonic-gate 		p = (CHR *)$1.cp;
1597c478bd9Sstevel@tonic-gate 		i = mn0((unsigned)(*p++));
1607c478bd9Sstevel@tonic-gate 		while(*p)
1617c478bd9Sstevel@tonic-gate 			i = mn2(RSTR,i,(unsigned)(*p++));
1627c478bd9Sstevel@tonic-gate 		$$.i = i;
1637c478bd9Sstevel@tonic-gate 		}
1647c478bd9Sstevel@tonic-gate 	| '.'
165*724c5febSToomas Soome 	{
1667c478bd9Sstevel@tonic-gate 		$$.i = mn0(DOT);
1677c478bd9Sstevel@tonic-gate 		}
1687c478bd9Sstevel@tonic-gate 	| CCL
169*724c5febSToomas Soome 	{	$$.i = mn1(RCCL,$1.i); }
1707c478bd9Sstevel@tonic-gate 	| NCCL
171*724c5febSToomas Soome 	{	$$.i = mn1(RNCCL,$1.i); }
1727c478bd9Sstevel@tonic-gate 	| r '*'
173*724c5febSToomas Soome 	{	$$.i = mn1(STAR,$1.i); }
1747c478bd9Sstevel@tonic-gate 	| r '+'
175*724c5febSToomas Soome 	{	$$.i = mn1(PLUS,$1.i); }
1767c478bd9Sstevel@tonic-gate 	| r '?'
177*724c5febSToomas Soome 	{	$$.i = mn1(QUEST,$1.i); }
1787c478bd9Sstevel@tonic-gate 	| r '|' r
179*724c5febSToomas Soome 	{	$$.i = mn2(BAR,$1.i,$3.i); }
1807c478bd9Sstevel@tonic-gate 	| r r %prec CAT
181*724c5febSToomas Soome 	{	$$.i = mn2(RCAT,$1.i,$2.i); }
1827c478bd9Sstevel@tonic-gate 	| r '/' r
183*724c5febSToomas Soome 	{	if(!divflg){
1847c478bd9Sstevel@tonic-gate 			j = mn1(S2FINAL,-casecount);
1857c478bd9Sstevel@tonic-gate 			i = mn2(RCAT,$1.i,j);
1867c478bd9Sstevel@tonic-gate 			$$.i = mn2(DIV,i,$3.i);
1877c478bd9Sstevel@tonic-gate 			}
1887c478bd9Sstevel@tonic-gate 		else {
1897c478bd9Sstevel@tonic-gate 			$$.i = mn2(RCAT,$1.i,$3.i);
1907c478bd9Sstevel@tonic-gate 			error("illegal extra slash");
1917c478bd9Sstevel@tonic-gate 			}
1927c478bd9Sstevel@tonic-gate 		divflg = TRUE;
1937c478bd9Sstevel@tonic-gate 		}
1947c478bd9Sstevel@tonic-gate 	| r ITER ',' ITER '}'
195*724c5febSToomas Soome 	{	if($2.i > $4.i){
1967c478bd9Sstevel@tonic-gate 			i = $2.i;
1977c478bd9Sstevel@tonic-gate 			$2.i = $4.i;
1987c478bd9Sstevel@tonic-gate 			$4.i = i;
1997c478bd9Sstevel@tonic-gate 			}
2007c478bd9Sstevel@tonic-gate 		if($4.i <= 0)
2017c478bd9Sstevel@tonic-gate 			error("iteration range must be positive");
2027c478bd9Sstevel@tonic-gate 		else {
2037c478bd9Sstevel@tonic-gate 			j = $1.i;
2047c478bd9Sstevel@tonic-gate 			for(k = 2; k<=$2.i;k++)
2057c478bd9Sstevel@tonic-gate 				j = mn2(RCAT,j,dupl($1.i));
2067c478bd9Sstevel@tonic-gate 			for(i = $2.i+1; i<=$4.i; i++){
2077c478bd9Sstevel@tonic-gate 				g = dupl($1.i);
2087c478bd9Sstevel@tonic-gate 				for(k=2;k<=i;k++)
2097c478bd9Sstevel@tonic-gate 					g = mn2(RCAT,g,dupl($1.i));
2107c478bd9Sstevel@tonic-gate 				j = mn2(BAR,j,g);
2117c478bd9Sstevel@tonic-gate 				}
2127c478bd9Sstevel@tonic-gate 			$$.i = j;
2137c478bd9Sstevel@tonic-gate 			}
2147c478bd9Sstevel@tonic-gate 	}
2157c478bd9Sstevel@tonic-gate 	| r ITER '}'
216*724c5febSToomas Soome 	{
2177c478bd9Sstevel@tonic-gate 		if($2.i < 0)error("can't have negative iteration");
2187c478bd9Sstevel@tonic-gate 		else if($2.i == 0) $$.i = mn0(RNULLS);
2197c478bd9Sstevel@tonic-gate 		else {
2207c478bd9Sstevel@tonic-gate 			j = $1.i;
2217c478bd9Sstevel@tonic-gate 			for(k=2;k<=$2.i;k++)
2227c478bd9Sstevel@tonic-gate 				j = mn2(RCAT,j,dupl($1.i));
2237c478bd9Sstevel@tonic-gate 			$$.i = j;
2247c478bd9Sstevel@tonic-gate 			}
2257c478bd9Sstevel@tonic-gate 		}
2267c478bd9Sstevel@tonic-gate 	| r ITER ',' '}'
227*724c5febSToomas Soome 	{
2287c478bd9Sstevel@tonic-gate 				/* from n to infinity */
2297c478bd9Sstevel@tonic-gate 		if($2.i < 0)error("can't have negative iteration");
2307c478bd9Sstevel@tonic-gate 		else if($2.i == 0) $$.i = mn1(STAR,$1.i);
2317c478bd9Sstevel@tonic-gate 		else if($2.i == 1)$$.i = mn1(PLUS,$1.i);
2327c478bd9Sstevel@tonic-gate 		else {		/* >= 2 iterations minimum */
2337c478bd9Sstevel@tonic-gate 			j = $1.i;
2347c478bd9Sstevel@tonic-gate 			for(k=2;k<$2.i;k++)
2357c478bd9Sstevel@tonic-gate 				j = mn2(RCAT,j,dupl($1.i));
2367c478bd9Sstevel@tonic-gate 			k = mn1(PLUS,dupl($1.i));
2377c478bd9Sstevel@tonic-gate 			$$.i = mn2(RCAT,j,k);
2387c478bd9Sstevel@tonic-gate 			}
2397c478bd9Sstevel@tonic-gate 		}
2407c478bd9Sstevel@tonic-gate 	| SCON r
241*724c5febSToomas Soome 	{	$$.i = mn2(RSCON,$2.i,(uintptr_t)$1.cp); }
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	/* XCU4: add XSCON */
2447c478bd9Sstevel@tonic-gate 	| XSCON r
245*724c5febSToomas Soome 	{	$$.i = mn2(RXSCON,$2.i,(uintptr_t)$1.cp); }
2467c478bd9Sstevel@tonic-gate 	| '^' r
247*724c5febSToomas Soome 	{	$$.i = mn1(CARAT,$2.i); }
2487c478bd9Sstevel@tonic-gate 	| r '$'
249*724c5febSToomas Soome 	{	i = mn0('\n');
2507c478bd9Sstevel@tonic-gate 		if(!divflg){
2517c478bd9Sstevel@tonic-gate 			j = mn1(S2FINAL,-casecount);
2527c478bd9Sstevel@tonic-gate 			k = mn2(RCAT,$1.i,j);
2537c478bd9Sstevel@tonic-gate 			$$.i = mn2(DIV,k,i);
2547c478bd9Sstevel@tonic-gate 			}
2557c478bd9Sstevel@tonic-gate 		else $$.i = mn2(RCAT,$1.i,i);
2567c478bd9Sstevel@tonic-gate 		divflg = TRUE;
2577c478bd9Sstevel@tonic-gate 		}
2587c478bd9Sstevel@tonic-gate 	| '(' r ')'
259*724c5febSToomas Soome 	{	$$.i = $2.i; }
2607c478bd9Sstevel@tonic-gate 	|	NULLS
261*724c5febSToomas Soome 	{	$$.i = mn0(RNULLS); }
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	/* XCU4: add ARRAY and POINTER */
2647c478bd9Sstevel@tonic-gate 	| ARRAY
265*724c5febSToomas Soome 	{ isArray = 1; };
2667c478bd9Sstevel@tonic-gate 	|     POINTER
267*724c5febSToomas Soome 	{ isArray = 0; };
2687c478bd9Sstevel@tonic-gate 	;
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate %%
2717c478bd9Sstevel@tonic-gate int
2727c478bd9Sstevel@tonic-gate yylex(void)
2737c478bd9Sstevel@tonic-gate {
2747c478bd9Sstevel@tonic-gate 	CHR *p;
2757c478bd9Sstevel@tonic-gate 	int  i;
2767c478bd9Sstevel@tonic-gate 	CHR *xp;
2777c478bd9Sstevel@tonic-gate 	int lex_startcond_lookupval;
2787c478bd9Sstevel@tonic-gate 	CHR  *t, c;
2797c478bd9Sstevel@tonic-gate 	int n, j = 0, k, x;
2807c478bd9Sstevel@tonic-gate 	CHR ch;
2817c478bd9Sstevel@tonic-gate 	static int sectbegin;
2827c478bd9Sstevel@tonic-gate 	static CHR token[TOKENSIZE];
2837c478bd9Sstevel@tonic-gate 	static int iter;
2847c478bd9Sstevel@tonic-gate 	int ccs; /* Current CodeSet. */
2857c478bd9Sstevel@tonic-gate 	CHR *ccp;
2867c478bd9Sstevel@tonic-gate 	int exclusive_flag;	/* XCU4: exclusive start flag */
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate # ifdef DEBUG
2897c478bd9Sstevel@tonic-gate 	yylval.i = 0;
2907c478bd9Sstevel@tonic-gate # endif
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 	if(sect == DEFSECTION) {		/* definitions section */
2937c478bd9Sstevel@tonic-gate 		while(!eof) {
2947c478bd9Sstevel@tonic-gate 			if(prev == '\n'){    /* next char is at beginning of line */
2957c478bd9Sstevel@tonic-gate 				(void)getl(p=buf);
2967c478bd9Sstevel@tonic-gate 				switch(*p){
2977c478bd9Sstevel@tonic-gate 				case '%':
2987c478bd9Sstevel@tonic-gate 					switch(c= *(p+1)){
2997c478bd9Sstevel@tonic-gate 					case '%':
3001dd08564Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3017c478bd9Sstevel@tonic-gate 						if(scomp(p, (CHR *)"%%")) {
3027c478bd9Sstevel@tonic-gate 							p++;
3037c478bd9Sstevel@tonic-gate 							while(*(++p))
3047c478bd9Sstevel@tonic-gate 								if(!space(*p)) {
3057c478bd9Sstevel@tonic-gate 									warning("invalid string following %%%% be ignored");
3067c478bd9Sstevel@tonic-gate 									break;
3077c478bd9Sstevel@tonic-gate 								}
3087c478bd9Sstevel@tonic-gate 						}
3097c478bd9Sstevel@tonic-gate 						lgate();
3107c478bd9Sstevel@tonic-gate 						if(!ratfor)(void) fprintf(fout,"# ");
3117c478bd9Sstevel@tonic-gate 						(void) fprintf(fout,"define YYNEWLINE %d\n",ctable['\n']);
3127c478bd9Sstevel@tonic-gate 						if(!ratfor)(void) fprintf(fout,"int yylex(){\nint nstr; extern int yyprevious;\n");
3137c478bd9Sstevel@tonic-gate 						sectbegin = TRUE;
3147c478bd9Sstevel@tonic-gate 						i = treesize*(sizeof(*name)+sizeof(*left)+
3157c478bd9Sstevel@tonic-gate 							sizeof(*right)+sizeof(*nullstr)+sizeof(*parent))+ALITTLEEXTRA;
3167c478bd9Sstevel@tonic-gate 						c = (int)myalloc(i,1);
3177c478bd9Sstevel@tonic-gate 						if(c == 0)
3187c478bd9Sstevel@tonic-gate 							error("Too little core for parse tree");
3197c478bd9Sstevel@tonic-gate 						p = (CHR *)c;
3207c478bd9Sstevel@tonic-gate 						free(p);
3211dd08564Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3227c478bd9Sstevel@tonic-gate 						name = (int *)myalloc(treesize,sizeof(*name));
3231dd08564Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3247c478bd9Sstevel@tonic-gate 						left = (int *)myalloc(treesize,sizeof(*left));
3251dd08564Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3267c478bd9Sstevel@tonic-gate 						right = (int *)myalloc(treesize,sizeof(*right));
3277c478bd9Sstevel@tonic-gate 						nullstr = myalloc(treesize,sizeof(*nullstr));
3281dd08564Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
3297c478bd9Sstevel@tonic-gate 						parent = (int *)myalloc(treesize,sizeof(*parent));
3307c478bd9Sstevel@tonic-gate 						if(name == 0 || left == 0 || right == 0 || parent == 0 || nullstr == 0)
3317c478bd9Sstevel@tonic-gate 							error("Too little core for parse tree");
3327c478bd9Sstevel@tonic-gate 						return(freturn(DELIM));
3337c478bd9Sstevel@tonic-gate 					case 'p': case 'P':
3347c478bd9Sstevel@tonic-gate 					        /* %p or %pointer */
3357c478bd9Sstevel@tonic-gate 						if ((*(p+2) == 'o') ||
3367c478bd9Sstevel@tonic-gate 						    (*(p+2) == 'O')) {
3377c478bd9Sstevel@tonic-gate 						    if(lgatflg)
3387c478bd9Sstevel@tonic-gate 							error("Too late for %%pointer");
3397c478bd9Sstevel@tonic-gate 						    while(*p && !iswspace(*p))
3407c478bd9Sstevel@tonic-gate 							p++;
3417c478bd9Sstevel@tonic-gate 						    isArray = 0;
3427c478bd9Sstevel@tonic-gate 						    continue;
3437c478bd9Sstevel@tonic-gate 						}
3447c478bd9Sstevel@tonic-gate 						/* has overridden number of positions */
3457c478bd9Sstevel@tonic-gate 						p += 2;
3467c478bd9Sstevel@tonic-gate 						maxpos = siconv(p);
3477c478bd9Sstevel@tonic-gate 						if (maxpos<=0)error("illegal position number");
3487c478bd9Sstevel@tonic-gate # ifdef DEBUG
3497c478bd9Sstevel@tonic-gate 						if (debug) (void) printf("positions (%%p) now %d\n",maxpos);
3507c478bd9Sstevel@tonic-gate # endif
3517c478bd9Sstevel@tonic-gate 						if(report == 2)report = 1;
3527c478bd9Sstevel@tonic-gate 						continue;
3537c478bd9Sstevel@tonic-gate 					case 'n': case 'N':	/* has overridden number of states */
3547c478bd9Sstevel@tonic-gate 						p += 2;
3557c478bd9Sstevel@tonic-gate 						nstates = siconv(p);
3567c478bd9Sstevel@tonic-gate 						if(nstates<=0)error("illegal state number");
3577c478bd9Sstevel@tonic-gate # ifdef DEBUG
3587c478bd9Sstevel@tonic-gate 						if(debug)(void) printf( " no. states (%%n) now %d\n",nstates);
3597c478bd9Sstevel@tonic-gate # endif
3607c478bd9Sstevel@tonic-gate 						if(report == 2)report = 1;
3617c478bd9Sstevel@tonic-gate 						continue;
3627c478bd9Sstevel@tonic-gate 					case 'e': case 'E':		/* has overridden number of tree nodes */
3637c478bd9Sstevel@tonic-gate 						p += 2;
3647c478bd9Sstevel@tonic-gate 						treesize = siconv(p);
3657c478bd9Sstevel@tonic-gate 						if(treesize<=0)error("illegal number of parse tree nodes");
3667c478bd9Sstevel@tonic-gate # ifdef DEBUG
3677c478bd9Sstevel@tonic-gate 						if (debug) (void) printf("treesize (%%e) now %d\n",treesize);
3687c478bd9Sstevel@tonic-gate # endif
3697c478bd9Sstevel@tonic-gate 						if(report == 2)report = 1;
3707c478bd9Sstevel@tonic-gate 						continue;
3717c478bd9Sstevel@tonic-gate 					case 'o': case 'O':
3727c478bd9Sstevel@tonic-gate 						p += 2;
3737c478bd9Sstevel@tonic-gate 						outsize = siconv(p);
3747c478bd9Sstevel@tonic-gate 						if(outsize<=0)error("illegal size of output array");
3757c478bd9Sstevel@tonic-gate 						if (report ==2) report=1;
3767c478bd9Sstevel@tonic-gate 						continue;
3777c478bd9Sstevel@tonic-gate 					case 'a': case 'A':
3787c478bd9Sstevel@tonic-gate 					        /* %a or %array */
3797c478bd9Sstevel@tonic-gate 						if ((*(p+2) == 'r') ||
3807c478bd9Sstevel@tonic-gate 						    (*(p+2) == 'R')) {
3817c478bd9Sstevel@tonic-gate 						    if(lgatflg)
3827c478bd9Sstevel@tonic-gate 							error("Too late for %%array");
3837c478bd9Sstevel@tonic-gate 						    while(*p && !iswspace(*p))
3847c478bd9Sstevel@tonic-gate 							p++;
3857c478bd9Sstevel@tonic-gate 						    isArray = 1;
3867c478bd9Sstevel@tonic-gate 						    continue;
3877c478bd9Sstevel@tonic-gate 						}
3887c478bd9Sstevel@tonic-gate 						/* has overridden number of transitions */
3897c478bd9Sstevel@tonic-gate 						p += 2;
3907c478bd9Sstevel@tonic-gate 						ntrans = siconv(p);
3917c478bd9Sstevel@tonic-gate 						if(ntrans<=0)error("illegal translation number");
3927c478bd9Sstevel@tonic-gate # ifdef DEBUG
3937c478bd9Sstevel@tonic-gate 						if (debug)(void) printf("N. trans (%%a) now %d\n",ntrans);
3947c478bd9Sstevel@tonic-gate # endif
3957c478bd9Sstevel@tonic-gate 						if(report == 2)report = 1;
3967c478bd9Sstevel@tonic-gate 						continue;
3977c478bd9Sstevel@tonic-gate 					case 'k': case 'K': /* overriden packed char classes */
3987c478bd9Sstevel@tonic-gate 						p += 2;
3997c478bd9Sstevel@tonic-gate 						free(pchar);
4007c478bd9Sstevel@tonic-gate 						pchlen = siconv(p);
4017c478bd9Sstevel@tonic-gate 						if(pchlen<=0)error("illegal number of packed character class");
4027c478bd9Sstevel@tonic-gate # ifdef DEBUG
4037c478bd9Sstevel@tonic-gate 						if (debug) (void) printf( "Size classes (%%k) now %d\n",pchlen);
4047c478bd9Sstevel@tonic-gate # endif
4051dd08564Sab196087 						/*LINTED: E_BAD_PTR_CAST_ALIGN*/
4067c478bd9Sstevel@tonic-gate 						pchar=pcptr=(CHR *)myalloc(pchlen, sizeof(*pchar));
4077c478bd9Sstevel@tonic-gate 						if (report==2) report=1;
4087c478bd9Sstevel@tonic-gate 						continue;
4097c478bd9Sstevel@tonic-gate 					case 't': case 'T':	/* character set specifier */
4107c478bd9Sstevel@tonic-gate 						if(handleeuc)
4117c478bd9Sstevel@tonic-gate 							error("\
4127c478bd9Sstevel@tonic-gate Character table (%t) is supported only in ASCII compatibility mode.\n");
4137c478bd9Sstevel@tonic-gate 						ZCH = watoi(p+2);
4147c478bd9Sstevel@tonic-gate 						if (ZCH < NCH) ZCH = NCH;
4157c478bd9Sstevel@tonic-gate 						if (ZCH > 2*NCH) error("ch table needs redeclaration");
4167c478bd9Sstevel@tonic-gate 						chset = TRUE;
4177c478bd9Sstevel@tonic-gate 						for(i = 0; i<ZCH; i++)
4187c478bd9Sstevel@tonic-gate 							ctable[i] = 0;
4197c478bd9Sstevel@tonic-gate 						while(getl(p) && scomp(p,L_PctUpT) != 0 && scomp(p,L_PctLoT) != 0){
4207c478bd9Sstevel@tonic-gate 							if((n = siconv(p)) <= 0 || n > ZCH){
4217c478bd9Sstevel@tonic-gate 								error("Character value %d out of range",n);
4227c478bd9Sstevel@tonic-gate 								continue;
4237c478bd9Sstevel@tonic-gate 								}
4247c478bd9Sstevel@tonic-gate 							while(digit(*p)) p++;
4257c478bd9Sstevel@tonic-gate 							if(!iswspace(*p)) error("bad translation format");
4267c478bd9Sstevel@tonic-gate 							while(iswspace(*p)) p++;
4277c478bd9Sstevel@tonic-gate 							t = p;
4287c478bd9Sstevel@tonic-gate 							while(*t){
4297c478bd9Sstevel@tonic-gate 								c = ctrans(&t);
4307c478bd9Sstevel@tonic-gate 								if(ctable[(unsigned)c]){
4317c478bd9Sstevel@tonic-gate 									if (iswprint(c))
4327c478bd9Sstevel@tonic-gate 										warning("Character '%wc' used twice",c);
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 									else
4357c478bd9Sstevel@tonic-gate 										error("Chararter %o used twice",c);
4367c478bd9Sstevel@tonic-gate 									}
4377c478bd9Sstevel@tonic-gate 								else ctable[(unsigned)c] = n;
4387c478bd9Sstevel@tonic-gate 								t++;
4397c478bd9Sstevel@tonic-gate 								}
4407c478bd9Sstevel@tonic-gate 							p = buf;
4417c478bd9Sstevel@tonic-gate 							}
4427c478bd9Sstevel@tonic-gate 						{
4437c478bd9Sstevel@tonic-gate 						char chused[2*NCH]; int kr;
4447c478bd9Sstevel@tonic-gate 						for(i=0; i<ZCH; i++)
4457c478bd9Sstevel@tonic-gate 							chused[i]=0;
4467c478bd9Sstevel@tonic-gate 						for(i=0; i<NCH; i++)
4477c478bd9Sstevel@tonic-gate 							chused[ctable[i]]=1;
4487c478bd9Sstevel@tonic-gate 						for(kr=i=1; i<NCH; i++)
4497c478bd9Sstevel@tonic-gate 							if (ctable[i]==0)
4507c478bd9Sstevel@tonic-gate 								{
4517c478bd9Sstevel@tonic-gate 								while (chused[kr] == 0)
4527c478bd9Sstevel@tonic-gate 									kr++;
4537c478bd9Sstevel@tonic-gate 								ctable[i]=kr;
4547c478bd9Sstevel@tonic-gate 								chused[kr]=1;
4557c478bd9Sstevel@tonic-gate 								}
4567c478bd9Sstevel@tonic-gate 						}
4577c478bd9Sstevel@tonic-gate 						lgate();
4587c478bd9Sstevel@tonic-gate 						continue;
4597c478bd9Sstevel@tonic-gate 					case 'r': case 'R':
4607c478bd9Sstevel@tonic-gate 						c = 'r';
4617c478bd9Sstevel@tonic-gate 						/* FALLTHRU */
4627c478bd9Sstevel@tonic-gate 					case 'c': case 'C':
4637c478bd9Sstevel@tonic-gate 						if(lgatflg)
4647c478bd9Sstevel@tonic-gate 							error("Too late for language specifier");
4657c478bd9Sstevel@tonic-gate 						ratfor = (c == 'r');
4667c478bd9Sstevel@tonic-gate 						continue;
4677c478bd9Sstevel@tonic-gate 					case '{':
4687c478bd9Sstevel@tonic-gate 						lgate();
4697c478bd9Sstevel@tonic-gate 						while(getl(p) && scomp(p, L_PctCbr) != 0)
4707c478bd9Sstevel@tonic-gate 							if(p[0]=='/' && p[1]=='*')
4717c478bd9Sstevel@tonic-gate 								cpycom(p);
4727c478bd9Sstevel@tonic-gate 							else
473*724c5febSToomas Soome 								(void) fprintf(fout, "%ws\n", p);
4747c478bd9Sstevel@tonic-gate 						if(p[0] == '%') continue;
4757c478bd9Sstevel@tonic-gate 						if (*p) error("EOF before %%%%");
4767c478bd9Sstevel@tonic-gate 						else error("EOF before %%}");
4777c478bd9Sstevel@tonic-gate 						break;
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 					case 'x': case 'X':		/* XCU4: exclusive start conditions */
4807c478bd9Sstevel@tonic-gate 						exclusive_flag = 1;
4817c478bd9Sstevel@tonic-gate 						goto start;
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate 					case 's': case 'S':		/* start conditions */
4847c478bd9Sstevel@tonic-gate 						exclusive_flag = 0;
4857c478bd9Sstevel@tonic-gate start:
4867c478bd9Sstevel@tonic-gate 						lgate();
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 						while(*p && !iswspace(*p) && ((*p) != (wchar_t)',')) p++;
4897c478bd9Sstevel@tonic-gate 						n = TRUE;
4907c478bd9Sstevel@tonic-gate 						while(n){
4917c478bd9Sstevel@tonic-gate 							while(*p && (iswspace(*p) || ((*p) == (wchar_t)','))) p++;
4927c478bd9Sstevel@tonic-gate 							t = p;
4937c478bd9Sstevel@tonic-gate 							while(*p && !iswspace(*p) && ((*p) != (wchar_t)',')) {
4947c478bd9Sstevel@tonic-gate 							    if(!isascii(*p))
4957c478bd9Sstevel@tonic-gate 								error("None-ASCII characters in start condition.");
4967c478bd9Sstevel@tonic-gate 							    p++;
4977c478bd9Sstevel@tonic-gate 							}
4987c478bd9Sstevel@tonic-gate 							if(!*p) n = FALSE;
4997c478bd9Sstevel@tonic-gate 							*p++ = 0;
5007c478bd9Sstevel@tonic-gate 							if (*t == 0) continue;
5017c478bd9Sstevel@tonic-gate 							i = sptr*2;
5027c478bd9Sstevel@tonic-gate 							if(!ratfor)(void) fprintf(fout,"# ");
503*724c5febSToomas Soome 							(void) fprintf(fout, "define %ws %d\n", t, i);
5047c478bd9Sstevel@tonic-gate 							scopy(t,sp);
5057c478bd9Sstevel@tonic-gate 							sname[sptr] = sp;
5067c478bd9Sstevel@tonic-gate 							/* XCU4: save exclusive flag with start name */
5077c478bd9Sstevel@tonic-gate 							exclusive[sptr++] = exclusive_flag;
5087c478bd9Sstevel@tonic-gate 							sname[sptr] = 0;	/* required by lookup */
5097c478bd9Sstevel@tonic-gate 							if(sptr >= STARTSIZE)
5107c478bd9Sstevel@tonic-gate 								error("Too many start conditions");
5117c478bd9Sstevel@tonic-gate 							sp += slength(sp) + 1;
5127c478bd9Sstevel@tonic-gate 							if(sp >= schar+STARTCHAR)
5137c478bd9Sstevel@tonic-gate 								error("Start conditions too long");
5147c478bd9Sstevel@tonic-gate 							}
5157c478bd9Sstevel@tonic-gate 						continue;
5167c478bd9Sstevel@tonic-gate 					default:
5177c478bd9Sstevel@tonic-gate 						error("Invalid request %s",p);
5187c478bd9Sstevel@tonic-gate 						continue;
5197c478bd9Sstevel@tonic-gate 						}	/* end of switch after seeing '%' */
5207c478bd9Sstevel@tonic-gate 					break;
5217c478bd9Sstevel@tonic-gate 				case ' ': case '\t':		/* must be code */
5227c478bd9Sstevel@tonic-gate 					lgate();
5237c478bd9Sstevel@tonic-gate 					if( p[1]=='/' && p[2]=='*' ) cpycom(p);
524*724c5febSToomas Soome 					else (void) fprintf(fout, "%ws\n", p);
5257c478bd9Sstevel@tonic-gate 					continue;
5267c478bd9Sstevel@tonic-gate 				case '/':	/* look for comments */
5277c478bd9Sstevel@tonic-gate 					lgate();
5287c478bd9Sstevel@tonic-gate 					if((*(p+1))=='*') cpycom(p);
5297c478bd9Sstevel@tonic-gate 					/* FALLTHRU */
5307c478bd9Sstevel@tonic-gate 				default:		/* definition */
5317c478bd9Sstevel@tonic-gate 					while(*p && !iswspace(*p)) p++;
5327c478bd9Sstevel@tonic-gate 					if(*p == 0)
5337c478bd9Sstevel@tonic-gate 						continue;
5347c478bd9Sstevel@tonic-gate 					prev = *p;
5357c478bd9Sstevel@tonic-gate 					*p = 0;
5367c478bd9Sstevel@tonic-gate 					bptr = p+1;
5377c478bd9Sstevel@tonic-gate 					yylval.cp = (CHR *)buf;
5387c478bd9Sstevel@tonic-gate 					if(digit(buf[0]))
5397c478bd9Sstevel@tonic-gate 						warning("Substitution strings may not begin with digits");
5407c478bd9Sstevel@tonic-gate 					return(freturn(STR));
5417c478bd9Sstevel@tonic-gate 				}
5427c478bd9Sstevel@tonic-gate 			} else { /* still sect 1, but prev != '\n' */
5437c478bd9Sstevel@tonic-gate 				p = bptr;
5447c478bd9Sstevel@tonic-gate 				while(*p && iswspace(*p)) p++;
5457c478bd9Sstevel@tonic-gate 				if(*p == 0)
5467c478bd9Sstevel@tonic-gate 					warning("No translation given - null string assumed");
5477c478bd9Sstevel@tonic-gate 				scopy(p,token);
5487c478bd9Sstevel@tonic-gate 				yylval.cp = (CHR *)token;
5497c478bd9Sstevel@tonic-gate 				prev = '\n';
5507c478bd9Sstevel@tonic-gate 				return(freturn(STR));
5517c478bd9Sstevel@tonic-gate 				}
5527c478bd9Sstevel@tonic-gate 			}
5537c478bd9Sstevel@tonic-gate 		error("unexpected EOF before %%%%");
5547c478bd9Sstevel@tonic-gate 		/* end of section one processing */
5557c478bd9Sstevel@tonic-gate 	} else if(sect == RULESECTION){		/* rules and actions */
5567c478bd9Sstevel@tonic-gate 		lgate();
5577c478bd9Sstevel@tonic-gate 		while(!eof){
5587c478bd9Sstevel@tonic-gate 			static int first_test=TRUE, first_value;
5597c478bd9Sstevel@tonic-gate 			static int reverse=FALSE;
5607c478bd9Sstevel@tonic-gate 			switch(c=gch()){
5617c478bd9Sstevel@tonic-gate 			case '\0':
5627c478bd9Sstevel@tonic-gate 				if(n_error)error_tail();
5637c478bd9Sstevel@tonic-gate 				return(freturn(0));
5647c478bd9Sstevel@tonic-gate 			case '\n':
5657c478bd9Sstevel@tonic-gate 				if(prev == '\n') continue;
5667c478bd9Sstevel@tonic-gate 				x = NEWE;
5677c478bd9Sstevel@tonic-gate 				break;
5687c478bd9Sstevel@tonic-gate 			case ' ':
5697c478bd9Sstevel@tonic-gate 			case '\t':
5707c478bd9Sstevel@tonic-gate 				if(prev == '\n') copy_line = TRUE;
5717c478bd9Sstevel@tonic-gate 				if(sectbegin == TRUE){
5727c478bd9Sstevel@tonic-gate 					(void)cpyact();
5737c478bd9Sstevel@tonic-gate 					copy_line = FALSE;
5741dd08564Sab196087 					/*LINTED: E_EQUALITY_NOT_ASSIGNMENT*/
5757c478bd9Sstevel@tonic-gate 					while((c=gch()) && c != '\n');
5767c478bd9Sstevel@tonic-gate 					continue;
5777c478bd9Sstevel@tonic-gate 					}
5787c478bd9Sstevel@tonic-gate 				if(!funcflag)phead2();
5797c478bd9Sstevel@tonic-gate 				funcflag = TRUE;
5807c478bd9Sstevel@tonic-gate 				if(ratfor)(void) fprintf(fout,"%d\n",30000+casecount);
5817c478bd9Sstevel@tonic-gate 				else (void) fprintf(fout,"case %d:\n",casecount);
5827c478bd9Sstevel@tonic-gate 				if(cpyact()){
5837c478bd9Sstevel@tonic-gate 					if(ratfor)(void) fprintf(fout,"goto 30997\n");
5847c478bd9Sstevel@tonic-gate 					else (void) fprintf(fout,"break;\n");
5857c478bd9Sstevel@tonic-gate 					}
5861dd08564Sab196087 				/*LINTED: E_EQUALITY_NOT_ASSIGNMENT*/
5877c478bd9Sstevel@tonic-gate 				while((c=gch()) && c != '\n') {
5887c478bd9Sstevel@tonic-gate 					if (c=='/') {
5897c478bd9Sstevel@tonic-gate 						if((c=gch())=='*') {
5907c478bd9Sstevel@tonic-gate 							c=gch();
5917c478bd9Sstevel@tonic-gate 							while(c !=EOF) {
5927c478bd9Sstevel@tonic-gate 								while (c=='*')
5937c478bd9Sstevel@tonic-gate 									if ((c=gch()) == '/') goto w_loop;
5947c478bd9Sstevel@tonic-gate 								c = gch();
5957c478bd9Sstevel@tonic-gate 							}
5967c478bd9Sstevel@tonic-gate 							error("EOF inside comment");
5977c478bd9Sstevel@tonic-gate 						} else
5987c478bd9Sstevel@tonic-gate 							warning("undefined string");
5997c478bd9Sstevel@tonic-gate 					} else if (c=='}')
6007c478bd9Sstevel@tonic-gate 						error("illegal extra \"}\"");
6017c478bd9Sstevel@tonic-gate 				w_loop: ;
6027c478bd9Sstevel@tonic-gate 				}
6037c478bd9Sstevel@tonic-gate 				/* while ((c=gch())== ' ' || c == '\t') ; */
6047c478bd9Sstevel@tonic-gate 				/* if (!space(c)) error("undefined action string"); */
6057c478bd9Sstevel@tonic-gate 				if(peek == ' ' || peek == '\t' || sectbegin == TRUE){
6067c478bd9Sstevel@tonic-gate 					fatal = 0;
6077c478bd9Sstevel@tonic-gate 					n_error++;
6087c478bd9Sstevel@tonic-gate 					error("executable statements should occur right after %%%%");
6097c478bd9Sstevel@tonic-gate 					fatal = 1;
6107c478bd9Sstevel@tonic-gate 					continue;
6117c478bd9Sstevel@tonic-gate 					}
6127c478bd9Sstevel@tonic-gate 				x = NEWE;
6137c478bd9Sstevel@tonic-gate 				break;
6147c478bd9Sstevel@tonic-gate 			case '%':
6157c478bd9Sstevel@tonic-gate 				if(prev != '\n') goto character;
6167c478bd9Sstevel@tonic-gate 				if(peek == '{'){	/* included code */
6177c478bd9Sstevel@tonic-gate 					(void)getl(buf);
6187c478bd9Sstevel@tonic-gate 					while(!eof&& getl(buf) && scomp(L_PctCbr,buf)!=0)
6197c478bd9Sstevel@tonic-gate 						if(buf[0]=='/' && buf[1]=='*')
6207c478bd9Sstevel@tonic-gate 							cpycom(buf);
6217c478bd9Sstevel@tonic-gate 						else
622*724c5febSToomas Soome 							(void) fprintf(fout, "%ws\n", buf);
6237c478bd9Sstevel@tonic-gate 					continue;
6247c478bd9Sstevel@tonic-gate 					}
6257c478bd9Sstevel@tonic-gate 				if(peek == '%'){
6267c478bd9Sstevel@tonic-gate 					c = gch();
6277c478bd9Sstevel@tonic-gate 					c = gch();
6287c478bd9Sstevel@tonic-gate 					x = DELIM;
6297c478bd9Sstevel@tonic-gate 					break;
6307c478bd9Sstevel@tonic-gate 					}
6317c478bd9Sstevel@tonic-gate 				goto character;
6327c478bd9Sstevel@tonic-gate 			case '|':
6337c478bd9Sstevel@tonic-gate 				if(peek == ' ' || peek == '\t' || peek == '\n'){
6347c478bd9Sstevel@tonic-gate 					if(ratfor)(void) fprintf(fout,"%d\n",30000+casecount++);
6357c478bd9Sstevel@tonic-gate 					else (void) fprintf(fout,"case %d:\n",casecount++);
6367c478bd9Sstevel@tonic-gate 					continue;
6377c478bd9Sstevel@tonic-gate 					}
6387c478bd9Sstevel@tonic-gate 				x = '|';
6397c478bd9Sstevel@tonic-gate 				break;
6407c478bd9Sstevel@tonic-gate 			case '$':
6417c478bd9Sstevel@tonic-gate 				if(peek == '\n' || peek == ' ' || peek == '\t' || peek == '|' || peek == '/'){
6427c478bd9Sstevel@tonic-gate 					x = c;
6437c478bd9Sstevel@tonic-gate 					break;
6447c478bd9Sstevel@tonic-gate 					}
6457c478bd9Sstevel@tonic-gate 				goto character;
6467c478bd9Sstevel@tonic-gate 			case '^':
6477c478bd9Sstevel@tonic-gate                                 if(peekon && (prev == '}')){
6487c478bd9Sstevel@tonic-gate                                         x = c;
6497c478bd9Sstevel@tonic-gate                                         break;
6507c478bd9Sstevel@tonic-gate                                 }
6517c478bd9Sstevel@tonic-gate 				if(prev != '\n' && scon != TRUE) goto character;
6527c478bd9Sstevel@tonic-gate 				/* valid only at line begin */
6537c478bd9Sstevel@tonic-gate 				x = c;
6547c478bd9Sstevel@tonic-gate 				break;
6557c478bd9Sstevel@tonic-gate 			case '?':
6567c478bd9Sstevel@tonic-gate 			case '+':
6577c478bd9Sstevel@tonic-gate 			case '*':
6587c478bd9Sstevel@tonic-gate 				if(prev == '\n' ) {
6597c478bd9Sstevel@tonic-gate 					fatal = 0;
6607c478bd9Sstevel@tonic-gate 					n_error++;
6617c478bd9Sstevel@tonic-gate 					error("illegal operator -- %c",c);
6627c478bd9Sstevel@tonic-gate 					fatal = 1;
6637c478bd9Sstevel@tonic-gate 				}
6647c478bd9Sstevel@tonic-gate 				/* FALLTHRU */
6657c478bd9Sstevel@tonic-gate 			case '.':
6667c478bd9Sstevel@tonic-gate 			case '(':
6677c478bd9Sstevel@tonic-gate 			case ')':
6687c478bd9Sstevel@tonic-gate 			case ',':
6697c478bd9Sstevel@tonic-gate 			case '/':
6707c478bd9Sstevel@tonic-gate 				x = c;
6717c478bd9Sstevel@tonic-gate 				break;
6727c478bd9Sstevel@tonic-gate 			case '}':
6737c478bd9Sstevel@tonic-gate 				iter = FALSE;
6747c478bd9Sstevel@tonic-gate 				x = c;
6757c478bd9Sstevel@tonic-gate 				break;
6767c478bd9Sstevel@tonic-gate 			case '{':	/* either iteration or definition */
6777c478bd9Sstevel@tonic-gate 				if(digit(c=gch())){	/* iteration */
6787c478bd9Sstevel@tonic-gate 					iter = TRUE;
6797c478bd9Sstevel@tonic-gate 					if(prev=='{') first_test = TRUE;
6807c478bd9Sstevel@tonic-gate 				ieval:
6817c478bd9Sstevel@tonic-gate 					i = 0;
6827c478bd9Sstevel@tonic-gate 					while(digit(c)){
6837c478bd9Sstevel@tonic-gate 						token[i++] = c;
6847c478bd9Sstevel@tonic-gate 						c = gch();
6857c478bd9Sstevel@tonic-gate 						}
6867c478bd9Sstevel@tonic-gate 					token[i] = 0;
6877c478bd9Sstevel@tonic-gate 					yylval.i = siconv(token);
6887c478bd9Sstevel@tonic-gate 					if(first_test) {
6897c478bd9Sstevel@tonic-gate 						first_test = FALSE;
6907c478bd9Sstevel@tonic-gate 						first_value = yylval.i;
6917c478bd9Sstevel@tonic-gate 					} else
6927c478bd9Sstevel@tonic-gate 						if(first_value>yylval.i)warning("the values between braces are reversed");
6937c478bd9Sstevel@tonic-gate 					ch = c;
6947c478bd9Sstevel@tonic-gate 					munput('c',&ch);
6957c478bd9Sstevel@tonic-gate 					x = ITER;
6967c478bd9Sstevel@tonic-gate 					break;
6977c478bd9Sstevel@tonic-gate 					}
6987c478bd9Sstevel@tonic-gate 				else {		/* definition */
6997c478bd9Sstevel@tonic-gate 					i = 0;
7007c478bd9Sstevel@tonic-gate 					while(c && c!='}'){
7017c478bd9Sstevel@tonic-gate 						token[i++] = c;
7027c478bd9Sstevel@tonic-gate 						if(i >= TOKENSIZE)
7037c478bd9Sstevel@tonic-gate 							error("definition too long");
7047c478bd9Sstevel@tonic-gate 						c = gch();
7057c478bd9Sstevel@tonic-gate 						}
7067c478bd9Sstevel@tonic-gate 					token[i] = 0;
7077c478bd9Sstevel@tonic-gate 					i = lookup(token,def);
7087c478bd9Sstevel@tonic-gate 					if(i < 0)
7097c478bd9Sstevel@tonic-gate 						error("definition %ws not found",token);
7107c478bd9Sstevel@tonic-gate 					else
7117c478bd9Sstevel@tonic-gate 						munput('s',(CHR *)(subs[i]));
7127c478bd9Sstevel@tonic-gate 					if (peek == '^')
7137c478bd9Sstevel@tonic-gate                                                 peekon = 1;
7147c478bd9Sstevel@tonic-gate 					continue;
7157c478bd9Sstevel@tonic-gate 					}
7167c478bd9Sstevel@tonic-gate 			case '<':		/* start condition ? */
7177c478bd9Sstevel@tonic-gate 				if(prev != '\n')  /* not at line begin, not start */
7187c478bd9Sstevel@tonic-gate 					goto character;
7197c478bd9Sstevel@tonic-gate 				t = slptr;
7207c478bd9Sstevel@tonic-gate 				do {
7217c478bd9Sstevel@tonic-gate 					i = 0;
7227c478bd9Sstevel@tonic-gate 					if(!isascii(c = gch()))
7237c478bd9Sstevel@tonic-gate 					    error("Non-ASCII characters in start condition.");
7247c478bd9Sstevel@tonic-gate 					while(c != ',' && c && c != '>'){
7257c478bd9Sstevel@tonic-gate 						token[i++] = c;
7267c478bd9Sstevel@tonic-gate 						if(i >= TOKENSIZE)
7277c478bd9Sstevel@tonic-gate 							error("string name too long");
7287c478bd9Sstevel@tonic-gate 						if(!isascii(c = gch()))
7297c478bd9Sstevel@tonic-gate 						    error("None-ASCII characters in start condition.");
7307c478bd9Sstevel@tonic-gate 						}
7317c478bd9Sstevel@tonic-gate 					token[i] = 0;
7327c478bd9Sstevel@tonic-gate 					if(i == 0)
7337c478bd9Sstevel@tonic-gate 						goto character;
7347c478bd9Sstevel@tonic-gate 					i = lookup(token,sname);
7357c478bd9Sstevel@tonic-gate 					lex_startcond_lookupval = i;
7367c478bd9Sstevel@tonic-gate 					if(i < 0) {
7377c478bd9Sstevel@tonic-gate 						fatal = 0;
7387c478bd9Sstevel@tonic-gate 						n_error++;
7397c478bd9Sstevel@tonic-gate 						error("undefined start condition %ws",token);
7407c478bd9Sstevel@tonic-gate 						fatal = 1;
7417c478bd9Sstevel@tonic-gate 						continue;
7427c478bd9Sstevel@tonic-gate 						}
7437c478bd9Sstevel@tonic-gate 					*slptr++ = i+1;
7447c478bd9Sstevel@tonic-gate 					} while(c && c != '>');
7457c478bd9Sstevel@tonic-gate 				*slptr++ = 0;
7467c478bd9Sstevel@tonic-gate 				/* check if previous value re-usable */
7477c478bd9Sstevel@tonic-gate 				for (xp=slist; xp<t; )
7487c478bd9Sstevel@tonic-gate 					{
7497c478bd9Sstevel@tonic-gate 					if (scomp(xp, t)==0)
7507c478bd9Sstevel@tonic-gate 						break;
7517c478bd9Sstevel@tonic-gate 					while (*xp++);
7527c478bd9Sstevel@tonic-gate 					}
7537c478bd9Sstevel@tonic-gate 				if (xp<t)
7547c478bd9Sstevel@tonic-gate 					{
7557c478bd9Sstevel@tonic-gate 					/* re-use previous pointer to string */
7567c478bd9Sstevel@tonic-gate 					slptr=t;
7577c478bd9Sstevel@tonic-gate 					t=xp;
7587c478bd9Sstevel@tonic-gate 					}
7597c478bd9Sstevel@tonic-gate 				if(slptr > slist+STARTSIZE)	/* note not packed */
7607c478bd9Sstevel@tonic-gate 					error("Too many start conditions used");
7617c478bd9Sstevel@tonic-gate 				yylval.cp = (CHR *)t;
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate 				/* XCU4: add XSCON */
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate 				if (exclusive[lex_startcond_lookupval])
7667c478bd9Sstevel@tonic-gate 					x = XSCON;
7677c478bd9Sstevel@tonic-gate 				else
7687c478bd9Sstevel@tonic-gate 					x = SCON;
7697c478bd9Sstevel@tonic-gate 				break;
7707c478bd9Sstevel@tonic-gate 			case '"':
7717c478bd9Sstevel@tonic-gate 				i = 0;
7721dd08564Sab196087 				/*LINTED: E_EQUALITY_NOT_ASSIGNMENT*/
7737c478bd9Sstevel@tonic-gate 				while((c=gch()) && c != '"' && c != '\n'){
7747c478bd9Sstevel@tonic-gate 					if(c == '\\') c = usescape(c=gch());
7757c478bd9Sstevel@tonic-gate 					remch(c);
7767c478bd9Sstevel@tonic-gate 					token[i++] = c;
7777c478bd9Sstevel@tonic-gate 					if(i >= TOKENSIZE){
7787c478bd9Sstevel@tonic-gate 						warning("String too long");
7797c478bd9Sstevel@tonic-gate 						i = TOKENSIZE-1;
7807c478bd9Sstevel@tonic-gate 						break;
7817c478bd9Sstevel@tonic-gate 						}
7827c478bd9Sstevel@tonic-gate 					}
7837c478bd9Sstevel@tonic-gate 				if(c == '\n') {
7847c478bd9Sstevel@tonic-gate 					yyline--;
7857c478bd9Sstevel@tonic-gate 					warning("Non-terminated string");
7867c478bd9Sstevel@tonic-gate 					yyline++;
7877c478bd9Sstevel@tonic-gate 					}
7887c478bd9Sstevel@tonic-gate 				token[i] = 0;
7897c478bd9Sstevel@tonic-gate 				if(i == 0)x = NULLS;
7907c478bd9Sstevel@tonic-gate 				else if(i == 1){
7917c478bd9Sstevel@tonic-gate 					yylval.i = (unsigned)token[0];
7927c478bd9Sstevel@tonic-gate 					x = CHAR;
7937c478bd9Sstevel@tonic-gate 					}
7947c478bd9Sstevel@tonic-gate 				else {
7957c478bd9Sstevel@tonic-gate 					yylval.cp = (CHR *)token;
7967c478bd9Sstevel@tonic-gate 					x = STR;
7977c478bd9Sstevel@tonic-gate 					}
7987c478bd9Sstevel@tonic-gate 				break;
7997c478bd9Sstevel@tonic-gate 			case '[':
8007c478bd9Sstevel@tonic-gate 				reverse = FALSE;
8017c478bd9Sstevel@tonic-gate 				x = CCL;
8027c478bd9Sstevel@tonic-gate 				if((c = gch()) == '^'){
8037c478bd9Sstevel@tonic-gate 					x = NCCL;
8047c478bd9Sstevel@tonic-gate 					reverse = TRUE;
8057c478bd9Sstevel@tonic-gate 					c = gch();
8067c478bd9Sstevel@tonic-gate 					}
8077c478bd9Sstevel@tonic-gate 				i = 0;
8087c478bd9Sstevel@tonic-gate 				while(c != ']' && c){
8097c478bd9Sstevel@tonic-gate 					static int light=TRUE, ESCAPE=FALSE;
8107c478bd9Sstevel@tonic-gate 					if(c == '-' && prev == '^' && reverse){
8117c478bd9Sstevel@tonic-gate 						symbol[(unsigned)c] = 1;
8127c478bd9Sstevel@tonic-gate 						c = gch();
8137c478bd9Sstevel@tonic-gate 						continue;
8147c478bd9Sstevel@tonic-gate 					}
8157c478bd9Sstevel@tonic-gate 					if(c == '\\') {
8167c478bd9Sstevel@tonic-gate 						c = usescape(c=gch());
8177c478bd9Sstevel@tonic-gate 						ESCAPE = TRUE;
8187c478bd9Sstevel@tonic-gate 					}
8197c478bd9Sstevel@tonic-gate 					if(c=='-' && !ESCAPE && prev!='[' && peek!=']'){
8207c478bd9Sstevel@tonic-gate 					/* range specified */
8217c478bd9Sstevel@tonic-gate 						if (light) {
8227c478bd9Sstevel@tonic-gate 							c = gch();
8237c478bd9Sstevel@tonic-gate 							if(c == '\\')
8247c478bd9Sstevel@tonic-gate 								c=usescape(c=gch());
8257c478bd9Sstevel@tonic-gate 							remch(c);
8267c478bd9Sstevel@tonic-gate 							k = c;
8277c478bd9Sstevel@tonic-gate 							ccs=wcsetno(k);
8287c478bd9Sstevel@tonic-gate 							if(wcsetno(j)!=ccs)
8297c478bd9Sstevel@tonic-gate 							    error("\
8307c478bd9Sstevel@tonic-gate Character range specified between different codesets.");
8317c478bd9Sstevel@tonic-gate 							if((unsigned)j > (unsigned)k) {
8327c478bd9Sstevel@tonic-gate 								n = j;
8337c478bd9Sstevel@tonic-gate 								j = k;
8347c478bd9Sstevel@tonic-gate 								k = n;
8357c478bd9Sstevel@tonic-gate 								}
8367c478bd9Sstevel@tonic-gate 							if(!handleeuc)
8377c478bd9Sstevel@tonic-gate 							if(!(('A'<=j && k<='Z') ||
8387c478bd9Sstevel@tonic-gate 							    ('a'<=j && k<='z') ||
8397c478bd9Sstevel@tonic-gate 							    ('0'<=j && k<='9')))
8407c478bd9Sstevel@tonic-gate 								warning("Non-portable Character Class");
8417c478bd9Sstevel@tonic-gate 							token[i++] = RANGE;
8427c478bd9Sstevel@tonic-gate 							token[i++] = j;
8437c478bd9Sstevel@tonic-gate 							token[i++] = k;
8447c478bd9Sstevel@tonic-gate 							light = FALSE;
8457c478bd9Sstevel@tonic-gate 						} else {
8467c478bd9Sstevel@tonic-gate 							error("unmatched hyphen");
8477c478bd9Sstevel@tonic-gate 							if(symbol[(unsigned)c])warning("\"%c\" redefined inside brackets",c);
8487c478bd9Sstevel@tonic-gate 							else symbol[(unsigned)c] = 1;
8497c478bd9Sstevel@tonic-gate 						}
8507c478bd9Sstevel@tonic-gate 						ESCAPE = FALSE;
8517c478bd9Sstevel@tonic-gate 					} else {
8527c478bd9Sstevel@tonic-gate 						j = c;
8537c478bd9Sstevel@tonic-gate 						remch(c);
8547c478bd9Sstevel@tonic-gate 						token[i++] = c; /* Remember whatever.*/
8557c478bd9Sstevel@tonic-gate 						light = TRUE;
8567c478bd9Sstevel@tonic-gate 						ESCAPE = FALSE;
8577c478bd9Sstevel@tonic-gate 					}
8587c478bd9Sstevel@tonic-gate 					c = gch();
8597c478bd9Sstevel@tonic-gate 				}
8607c478bd9Sstevel@tonic-gate 				/* try to pack ccl's */
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 				token[i] = 0;
8637c478bd9Sstevel@tonic-gate 				ccp = ccl;
8647c478bd9Sstevel@tonic-gate 				while (ccp < ccptr && scomp(token, ccp) != 0) ccp++;
8657c478bd9Sstevel@tonic-gate 				if (ccp < ccptr) {  /* found in ccl */
8667c478bd9Sstevel@tonic-gate 				    yylval.cp = ccp;
8677c478bd9Sstevel@tonic-gate 				} else {            /* not in ccl, add it */
8687c478bd9Sstevel@tonic-gate 				    scopy(token,ccptr);
8697c478bd9Sstevel@tonic-gate 				    yylval.cp = ccptr;
8707c478bd9Sstevel@tonic-gate 				    ccptr += slength(token) + 1;
8717c478bd9Sstevel@tonic-gate 				    if(ccptr >= ccl+CCLSIZE)
8727c478bd9Sstevel@tonic-gate 				      error("Too many large character classes");
8737c478bd9Sstevel@tonic-gate 				}
8747c478bd9Sstevel@tonic-gate 				break;
8757c478bd9Sstevel@tonic-gate 			case '\\':
8767c478bd9Sstevel@tonic-gate 				c = usescape(c=gch());
8771e819975SToomas Soome 				/* FALLTHROUGH */
8787c478bd9Sstevel@tonic-gate 			default:
8797c478bd9Sstevel@tonic-gate 			character:
8807c478bd9Sstevel@tonic-gate 				if(iter){	/* second part of an iteration */
8817c478bd9Sstevel@tonic-gate 					iter = FALSE;
8827c478bd9Sstevel@tonic-gate 					if('0' <= c && c <= '9')
8837c478bd9Sstevel@tonic-gate 						goto ieval;
8847c478bd9Sstevel@tonic-gate 					}
8857c478bd9Sstevel@tonic-gate 				remch(c);
8867c478bd9Sstevel@tonic-gate 				if(alpha(peek)){
8877c478bd9Sstevel@tonic-gate 					i = 0;
8887c478bd9Sstevel@tonic-gate 					yylval.cp = (CHR *)token;
8897c478bd9Sstevel@tonic-gate 					token[i++] = c;
8907c478bd9Sstevel@tonic-gate 					while(alpha(peek)) {
8917c478bd9Sstevel@tonic-gate 						remch(token[i++] = gch());
8927c478bd9Sstevel@tonic-gate 						if(i >= TOKENSIZE) {
8937c478bd9Sstevel@tonic-gate 							warning("string too long");
8947c478bd9Sstevel@tonic-gate 							i = TOKENSIZE - 1;
8957c478bd9Sstevel@tonic-gate 							break;
8967c478bd9Sstevel@tonic-gate 							}
8977c478bd9Sstevel@tonic-gate 						}
8987c478bd9Sstevel@tonic-gate 					if(peek == '?' || peek == '*' || peek == '+')
8997c478bd9Sstevel@tonic-gate 						munput('c',&token[--i]);
9007c478bd9Sstevel@tonic-gate 					token[i] = 0;
9017c478bd9Sstevel@tonic-gate 					if(i == 1){
9027c478bd9Sstevel@tonic-gate 						yylval.i = (unsigned)(token[0]);
9037c478bd9Sstevel@tonic-gate 						x = CHAR;
9047c478bd9Sstevel@tonic-gate 						}
9057c478bd9Sstevel@tonic-gate 					else x = STR;
9067c478bd9Sstevel@tonic-gate 					}
9077c478bd9Sstevel@tonic-gate 				else {
9087c478bd9Sstevel@tonic-gate 					yylval.i = (unsigned)c;
9097c478bd9Sstevel@tonic-gate 					x = CHAR;
9107c478bd9Sstevel@tonic-gate 					}
9117c478bd9Sstevel@tonic-gate 				}
9127c478bd9Sstevel@tonic-gate 			scon = FALSE;
9137c478bd9Sstevel@tonic-gate 			peekon = 0;
9147c478bd9Sstevel@tonic-gate 			if((x == SCON) || (x == XSCON))
9157c478bd9Sstevel@tonic-gate 				scon = TRUE;
9167c478bd9Sstevel@tonic-gate 			sectbegin = FALSE;
9177c478bd9Sstevel@tonic-gate 			return(freturn(x));
9187c478bd9Sstevel@tonic-gate 			/* NOTREACHED */
9197c478bd9Sstevel@tonic-gate 			}
9207c478bd9Sstevel@tonic-gate 		}
9217c478bd9Sstevel@tonic-gate 	/* section three */
9227c478bd9Sstevel@tonic-gate 	lgate();
9237c478bd9Sstevel@tonic-gate 	ptail();
9247c478bd9Sstevel@tonic-gate # ifdef DEBUG
9257c478bd9Sstevel@tonic-gate 	if(debug)
9267c478bd9Sstevel@tonic-gate 		(void) fprintf(fout,"\n/*this comes from section three - debug */\n");
9277c478bd9Sstevel@tonic-gate # endif
9287c478bd9Sstevel@tonic-gate 
9297c478bd9Sstevel@tonic-gate 	if(getl(buf) && !eof) {
9307c478bd9Sstevel@tonic-gate 		if (sargv[optind] == NULL)
9317c478bd9Sstevel@tonic-gate 			(void) fprintf(fout, "\n# line %d\n", yyline-1);
9327c478bd9Sstevel@tonic-gate 		else
9337c478bd9Sstevel@tonic-gate 			(void) fprintf(fout,
9347c478bd9Sstevel@tonic-gate 				"\n# line %d \"%s\"\n", yyline-1, sargv[optind]);
935*724c5febSToomas Soome 		(void) fprintf(fout, "%ws\n", buf);
9367c478bd9Sstevel@tonic-gate 		while(getl(buf) && !eof)
937*724c5febSToomas Soome 			(void) fprintf(fout, "%ws\n", buf);
9387c478bd9Sstevel@tonic-gate         }
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 	return(freturn(0));
9417c478bd9Sstevel@tonic-gate 	}
9427c478bd9Sstevel@tonic-gate /* end of yylex */
9437c478bd9Sstevel@tonic-gate # ifdef DEBUG
freturn(i)9447c478bd9Sstevel@tonic-gate freturn(i)
9457c478bd9Sstevel@tonic-gate   int i; {
9467c478bd9Sstevel@tonic-gate 	if(yydebug) {
9477c478bd9Sstevel@tonic-gate 		(void) printf("now return ");
9487c478bd9Sstevel@tonic-gate 		if((unsigned)i < NCH) allprint(i);
9497c478bd9Sstevel@tonic-gate 		else (void) printf("%d",i);
9507c478bd9Sstevel@tonic-gate 		(void) printf("   yylval = ");
9517c478bd9Sstevel@tonic-gate 		switch(i){
9527c478bd9Sstevel@tonic-gate 			case STR: case CCL: case NCCL:
9537c478bd9Sstevel@tonic-gate 				strpt(yylval.cp);
9547c478bd9Sstevel@tonic-gate 				break;
9557c478bd9Sstevel@tonic-gate 			case CHAR:
9567c478bd9Sstevel@tonic-gate 				allprint(yylval.i);
9577c478bd9Sstevel@tonic-gate 				break;
9587c478bd9Sstevel@tonic-gate 			default:
9597c478bd9Sstevel@tonic-gate 				(void) printf("%d",yylval.i);
9607c478bd9Sstevel@tonic-gate 				break;
9617c478bd9Sstevel@tonic-gate 			}
9627c478bd9Sstevel@tonic-gate 		(void) putchar('\n');
9637c478bd9Sstevel@tonic-gate 		}
9647c478bd9Sstevel@tonic-gate 	return(i);
9657c478bd9Sstevel@tonic-gate 	}
9667c478bd9Sstevel@tonic-gate # endif
967