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