4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1988 AT&T */
27 /* All Rights Reserved */
29 #pragma ident "%Z%%M% %I% %E% SMI"
35 * return next line of input, throw away trailing '\n'
36 * and also throw away trailing blanks (spaces and tabs)
37 * returns 0 if eof is had immediately
48 while (((c
= gch()) != 0) && c
!= '\n') {
50 error("definitions too long");
51 if (c
== ' ' || c
== '\t') {
88 return (c
>= '0' && c
<= '9');
99 (void) fprintf(errorf
, "Command line: ");
101 (void) fprintf(errorf
,
102 !no_input
? "" : "\"%s\":", sargv
[optind
]);
103 (void) fprintf(errorf
, "line %d: ", yyline
);
105 (void) fprintf(errorf
, "Error: ");
106 /*LINTED: E_SEC_PRINTF_VAR_FMT*/
107 (void) fprintf(errorf
, s
, p
, d
);
108 (void) putc('\n', errorf
);
117 if (debug
&& sect
!= ENDSECTION
) {
137 (void) fprintf(errorf
, "Command line: ");
139 (void) fprintf(errorf
,
140 !no_input
?"":"\"%s\":", sargv
[optind
]);
141 (void) fprintf(errorf
,
142 "line %d: ", yyline
);
144 (void) fprintf(errorf
, "Warning: ");
145 /*LINTED: E_SEC_PRINTF_VAR_FMT*/
146 (void) fprintf(errorf
, s
, p
, d
);
147 (void) putc('\n', errorf
);
148 (void) fflush(errorf
);
151 (void) fflush(stdout
);
155 * This function is apparently unused, but lint flags the fact
156 * that it does not have the same signature as the libc function
157 * of the same name. So, take it out of view for lint.
164 for (k
= 0; s
[k
]; k
++)
174 return ('a' <= c
&& c
<= 'z' ||
175 'A' <= c
&& c
<= 'Z');
181 return (c
> 040 && c
< 0177);
193 (void) sprintf(fname
, "lex.yy.%c", ratfor
? 'r' : 'c');
194 fout
= fopen(fname
, "w");
197 error("Can't open %s", fname
);
199 (void) fprintf(fout
, "#\n");
204 * scopy(ptr to str, ptr to str) - copy first arg str to second
205 * returns ptr to second arg
208 scopy(CHR
*s
, CHR
*t
)
217 * convert string t, return integer value
227 if (!digit(*s
) && *s
!= '-')
228 error("missing translation value");
235 error("incomplete translation format");
237 while ('0' <= *s
&& *s
<= '9')
238 i
= i
* 10 + (*(s
++)-'0');
239 return (sw
? -i
: i
);
243 * slength(ptr to str) - return integer length of string arg
244 * excludes '\0' terminator
252 for (n
= 0; *t
++; n
++)
258 * scomp(x,y) - return -1 if x < y,
260 * return 1 if x > y, all lexicographically
263 scomp(CHR
*x
, CHR
*y
)
283 if ((c
= **ss
) != '\\')
285 switch (c
= *++*ss
) {
288 warning("\\a is ANSI C \"alert\" character");
290 case 'v': c
= '\v'; break;
291 case 'n': c
= '\n'; break;
292 case 't': c
= '\t'; break;
293 case 'r': c
= '\r'; break;
294 case 'b': c
= '\b'; break;
295 case 'f': c
= 014; break; /* form feed for ascii */
296 case '\\': c
= '\\'; break;
299 warning("\\x is ANSI C hex escape");
300 if (digit((dd
= *++*ss
)) ||
301 ('a' <= dd
&& dd
<= 'f') ||
302 ('A' <= dd
&& dd
<= 'F')) {
305 ('A' <= dd
&& dd
<= 'F') ||
306 ('a' <= dd
&& dd
<= 'f')) {
310 c
= c
*16 + 10 + dd
- 'a';
312 c
= c
*16 + 10 + dd
- 'A';
319 case '0': case '1': case '2': case '3':
320 case '4': case '5': case '6': case '7':
322 while ((k
= *(*ss
+1)) >= '0' && k
<= '7') {
337 if (!sw
) { /* is NCCL */
338 for (i
= 1; i
< ncg
; i
++)
339 symbol
[i
] ^= 1; /* reverse value */
341 for (i
= 1; i
< ncg
; i
++)
347 /* see if ccl is already in our table */
350 for (j
= 1; j
< ncg
; j
++) {
351 if ((symbol
[j
] && cindex
[j
] != i
) ||
352 (!symbol
[j
] && cindex
[j
] == i
))
357 return; /* already in */
360 for (i
= 1; i
< ncg
; i
++) {
370 /* m == 1 implies last value of ccount has been used */
374 return; /* is now in as ccount wholly */
375 /* intersection must be computed */
376 for (i
= 1; i
< ncg
; i
++) {
379 j
= cindex
[i
]; /* will be non-zero */
380 for (k
= 1; k
< ncg
; k
++) {
381 if (cindex
[k
] == j
) {
403 warning("\\a is ANSI C \"alert\" character"); break;
404 case 'v': c
= '\v'; break;
405 case 'n': c
= '\n'; break;
406 case 'r': c
= '\r'; break;
407 case 't': c
= '\t'; break;
408 case 'b': c
= '\b'; break;
409 case 'f': c
= 014; break; /* form feed for ascii */
412 if (digit((dd
= gch())) ||
413 ('A' <= dd
&& dd
<= 'F') ||
414 ('a' <= dd
&& dd
<= 'f')) {
417 ('A' <= dd
&& dd
<= 'F') ||
418 ('a' <= dd
&& dd
<= 'f')) {
422 c
= c
*16 + 10 + dd
- 'a';
424 c
= c
*16 + 10 + dd
- 'A';
426 !('A' <= peek
&& peek
<= 'F') &&
427 !('a' <= peek
&& peek
<= 'f'))
436 case '0': case '1': case '2': case '3':
437 case '4': case '5': case '6': case '7':
439 while ('0' <= (d
= gch()) && d
<= '7') {
441 if (!('0' <= peek
&& peek
<= '7')) break;
447 if (handleeuc
&& !isascii(c
)) {
448 char tmpchar
= c
& 0x00ff;
449 (void) mbtowc((wchar_t *)&c
, &tmpchar
, sizeof (tmpchar
));
455 lookup(CHR
*s
, CHR
**t
)
460 if (scomp(s
, *t
) == 0)
475 if (sargv
[optind
] == NULL
)
476 (void) fprintf(fout
, "\n# line %d\n", yyline
);
479 "\n# line %d \"%s\"\n", yyline
, sargv
[optind
]);
481 (void) putc(*t
++, fout
);
482 (void) putc(*t
++, fout
);
485 (void) putc(*t
++, fout
);
490 * FIX BUG #1058428, not parsing comments correctly
491 * that span more than one line
494 (void) putc(*t
++, fout
);
496 (void) putc('\n', fout
);
499 (void) putc((char)c
, fout
);
500 if ((c
= gch()) == '/') {
501 while ((c
= gch()) == ' ' || c
== '\t')
504 error("unacceptable statement");
509 (void) putc((char)c
, fout
);
511 error("unexpected EOF inside comment");
513 (void) putc('/', fout
);
514 (void) putc('\n', fout
);
518 * copy C action to the next ; or closing
524 static int sw
, savline
;
530 if (sargv
[optind
] == NULL
)
531 (void) fprintf(fout
, "\n# line %d\n", yyline
);
534 "\n# line %d \"%s\"\n", yyline
, sargv
[optind
]);
541 if (brac
== 0 && sw
== TRUE
) {
543 (void) gch(); /* eat up an extra '|' */
549 (void) putwc(c
, fout
);
550 (void) putc('\n', fout
);
561 (void) putwc(c
, fout
);
562 (void) putc('\n', fout
);
567 (void) putwc(c
, fout
);
571 (void) putwc(c
, fout
);
575 (void) putwc(c
, fout
);
576 if ((c
= gch()) == '/') {
577 (void) putc('/', fout
);
578 while ((c
= gch()) == ' ' ||
579 c
== '\t' || c
== '\n')
580 (void) putwc(c
, fout
);
584 (void) putc((char)c
, fout
);
587 error("EOF inside comment");
590 case '\'': /* character constant */
591 case '"': /* character string */
593 (void) putwc(c
, fout
);
596 (void) putwc(c
, fout
);
602 (void) putwc(c
, fout
);
606 "Non-terminated string or character constant");
609 error("EOF in string or character constant");
614 error("Action does not terminate");
618 break; /* usual character */
621 if (c
!= ' ' && c
!= '\t' && c
!= '\n')
623 (void) putwc(c
, fout
);
624 if (peek
== '\n' && !brac
&& copy_line
) {
625 (void) putc('\n', fout
);
629 error("Premature EOF");
639 peek
= pushptr
> pushc
? *--pushptr
: getwc(fin
);
640 while (peek
== EOF
) {
643 error("Cannot read from -- %s",
645 if (optind
< sargc
-1) {
649 fin
= fopen(sargv
[++optind
], "r");
651 error("Cannot open file -- %s",
660 error("Cannot read from -- standard input");
675 mn2(int a
, int d
, int c
)
677 if (tptr
>= treesize
) {
679 error("Parse tree too big %s",
680 (treesize
== TREESIZE
? "\nTry using %e num" : ""));
683 error("Parse error");
696 if (nullstr
[d
] || nullstr
[c
])
697 nullstr
[tptr
] = TRUE
;
698 parent
[d
] = parent
[c
] = tptr
;
702 if (nullstr
[d
] && nullstr
[c
])
703 nullstr
[tptr
] = TRUE
;
704 parent
[d
] = parent
[c
] = tptr
;
706 /* XCU4: add RXSCON */
710 nullstr
[tptr
] = nullstr
[d
];
714 warning("bad switch mn2 %d %d", a
, d
);
724 if (tptr
>= treesize
) {
726 error("Parse tree too big %s",
727 (treesize
== TREESIZE
? "\nTry using %e num" : ""));
736 if (slength((CHR
*)d
) == 0)
737 nullstr
[tptr
] = TRUE
;
741 nullstr
[tptr
] = TRUE
;
746 nullstr
[tptr
] = nullstr
[d
];
750 nullstr
[tptr
] = TRUE
;
757 warning("bad switch mn1 %d %d", a
, d
);
767 if (tptr
>= treesize
) {
769 error("Parse tree too big %s",
770 (treesize
== TREESIZE
? "\nTry using %e num" : ""));
779 case RNULLS
: nullstr
[tptr
] = TRUE
; break;
782 warning("bad switch mn0 %d", a
);
791 munput(int t
, CHR
*p
)
797 } else if (t
== 's') {
801 for (j
= i
- 1; j
>= 1; j
--)
804 if (pushptr
>= pushc
+ TOKENSIZE
)
805 error("Too many characters pushed");
811 /* duplicate the subtree whose root is n, return ptr to it */
820 case RCCL
: case RNCCL
: case FINAL
: case S1FINAL
: case S2FINAL
:
821 return (mn1(i
, left
[n
]));
822 case STAR
: case QUEST
: case PLUS
: case CARAT
:
823 return (mn1(i
, dupl(left
[n
])));
825 /* XCU4: add RXSCON */
826 case RSTR
: case RSCON
: case RXSCON
:
827 return (mn2(i
, dupl(left
[n
]), right
[n
]));
828 case BAR
: case RNEWE
: case RCAT
: case DIV
:
829 return (mn2(i
, dupl(left
[n
]), dupl(right
[n
])));
840 (void) printf("\\f");
844 (void) printf("\\n");
848 (void) printf("\\t");
852 (void) printf("\\b");
856 (void) printf("\\_");
860 printf("\\x%-2x", c
); /* up to fashion. */
863 (void) putwc(c
, stdout
);
875 if (charc
> LINESIZE
) {
877 (void) printf("\n\t");
886 (void) printf("Sect 1:\n");
888 (void) printf("str trans\n");
891 (void) printf("%ws\t%ws\n", def
[i
], subs
[i
]);
894 (void) printf("start names\n");
897 (void) printf("%ws\n", sname
[i
]);
900 (void) printf("char set changed\n");
901 for (i
= 1; i
< NCH
; i
++) {
902 if (i
!= ctable
[i
]) {
905 iswprint(ctable
[i
]) ?
906 (void) putwc(ctable
[i
], stdout
) :
907 (void) printf("%d", ctable
[i
]);
908 (void) putchar('\n');
917 (void) printf("Sect 2:\n");
926 (void) printf("treedump %d nodes:\n", tptr
);
927 for (t
= 0; t
< tptr
; t
++) {
928 (void) printf("%4d ", t
);
929 parent
[t
] ? (void) printf("p=%4d", parent
[t
]) :
932 if (!ISOPERATOR(name
[t
])) {
937 (void) printf("%d ", left
[t
]);
941 (void) printf("ccl ");
945 (void) printf("nccl ");
949 (void) printf("/ %d %d", left
[t
], right
[t
]);
952 (void) printf("| %d %d", left
[t
], right
[t
]);
955 (void) printf("cat %d %d", left
[t
], right
[t
]);
958 (void) printf("+ %d", left
[t
]);
961 (void) printf("* %d", left
[t
]);
964 (void) printf("^ %d", left
[t
]);
967 (void) printf("? %d", left
[t
]);
970 (void) printf("nullstring");
973 (void) printf("final %d", left
[t
]);
976 (void) printf("s1final %d", left
[t
]);
979 (void) printf("s2final %d", left
[t
]);
982 (void) printf("new %d %d", left
[t
], right
[t
]);
985 /* XCU4: add RXSCON */
988 (void) printf("exstart %s", sname
[*p
++-1]);
990 (void) printf(", %ws", sname
[*p
++-1]);
991 (void) printf(" %d", left
[t
]);
995 (void) printf("start %s", sname
[*p
++-1]);
997 (void) printf(", %ws", sname
[*p
++-1]);
998 (void) printf(" %d", left
[t
]);
1005 "unknown %d %d %d", name
[t
], left
[t
], right
[t
]);
1009 (void) printf("\t(null poss.)");
1010 (void) putchar('\n');