sub1.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc.
* All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include "ldefs.c"
#include <limits.h>
/*
* return next line of input, throw away trailing '\n'
* and also throw away trailing blanks (spaces and tabs)
* returns 0 if eof is had immediately
*/
CHR *
{
int c;
CHR *s, *t, *u;
int blank = 0;
t = s = p;
while (((c = gch()) != 0) && c != '\n') {
if (t >= &p[BUF_SIZ])
error("definitions too long");
if (c == ' ' || c == '\t') {
if (!blank) {
blank = 1;
u = t;
}
} else
blank = 0;
*t++ = c;
}
if (blank)
*u = 0;
else
*t = 0;
if (c == 0 && s == t)
return ((CHR *) 0);
prev = '\n';
pres = '\n';
return (s);
}
int
{
switch (ch) {
case ' ':
case '\t':
case '\n':
return (1);
}
return (0);
}
int
digit(int c)
{
return (c >= '0' && c <= '9');
}
/* VARARGS1 */
void
error(s, p, d)
char *s;
int p, d;
{
/* if(!eof) */
if (!yyline)
else {
}
if (fatal)
error_tail();
}
void
error_tail(void)
{
#ifdef DEBUG
sect1dump();
sect2dump();
}
#endif
if (report == 1)
statistics();
exit(1);
/* NOTREACHED */
}
/* VARARGS1 */
void
warning(s, p, d)
char *s;
int p, d;
{
if (!eof)
if (!yyline)
else {
"line %d: ", yyline);
}
if (fout)
}
int
{
int k;
for (k = 0; s[k]; k++)
if (s[k] == a)
return (k);
return (-1);
}
int
alpha(int c)
{
return ('a' <= c && c <= 'z' ||
'A' <= c && c <= 'Z');
}
int
printable(int c)
{
return (c > 040 && c < 0177);
}
void
lgate(void)
{
char fname[20];
if (lgatflg)
return;
lgatflg = 1;
}
if (ratfor)
phead1();
}
/*
* scopy(ptr to str, ptr to str) - copy first arg str to second
* returns ptr to second arg
*/
void
{
CHR *i;
i = t;
while (*i++ = *s++);
}
/*
* convert string t, return integer value
*/
int
{
int i, sw;
CHR *s;
s = t;
while (space(*s))
s++;
if (!digit(*s) && *s != '-')
error("missing translation value");
sw = 0;
if (*s == '-') {
sw = 1;
s++;
}
if (!digit(*s))
error("incomplete translation format");
i = 0;
while ('0' <= *s && *s <= '9')
i = i * 10 + (*(s++)-'0');
return (sw ? -i : i);
}
/*
* slength(ptr to str) - return integer length of string arg
* excludes '\0' terminator
*/
int
{
int n;
CHR *t;
t = s;
for (n = 0; *t++; n++);
return (n);
}
/*
* scomp(x,y) - return -1 if x < y,
* 0 if x == y,
* return 1 if x > y, all lexicographically
*/
int
{
CHR *a, *d;
a = (CHR *) x;
d = (CHR *) y;
while (*a || *d) {
if (*a > *d)
return (1);
if (*a < *d)
return (-1);
a++;
d++;
}
return (0);
}
int
{
int c, k;
if ((c = **ss) != '\\')
return (c);
switch (c = *++*ss) {
case 'a':
c = '\a';
warning("\\a is ANSI C \"alert\" character");
break;
case 'v': c = '\v'; break;
case 'n': c = '\n'; break;
case 't': c = '\t'; break;
case 'r': c = '\r'; break;
case 'b': c = '\b'; break;
case 'f': c = 014; break; /* form feed for ascii */
case '\\': c = '\\'; break;
case 'x': {
int dd;
warning("\\x is ANSI C hex escape");
c = 0;
else if (dd >= 'a')
else
}
} else
c = 'x';
break;
}
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
c -= '0';
c = c*8 + k - '0';
(*ss)++;
}
break;
}
return (c);
}
void
{
/* sw = 1 ==> ccl */
int i, j, k;
int m;
if (!sw) { /* is NCCL */
for (i = 1; i < ncg; i++)
}
for (i = 1; i < ncg; i++)
if (symbol[i])
break;
if (i >= ncg)
return;
i = cindex[i];
/* see if ccl is already in our table */
j = 0;
if (i) {
for (j = 1; j < ncg; j++) {
break;
}
}
if (j >= ncg)
return; /* already in */
m = 0;
k = 0;
for (i = 1; i < ncg; i++) {
if (symbol[i]) {
if (!cindex[i]) {
symbol[i] = 0;
m = 1;
} else
k = 1;
}
}
/* m == 1 implies last value of ccount has been used */
if (m)
ccount++;
if (k == 0)
return; /* is now in as ccount wholly */
/* intersection must be computed */
for (i = 1; i < ncg; i++) {
if (symbol[i]) {
m = 0;
j = cindex[i]; /* will be non-zero */
for (k = 1; k < ncg; k++) {
if (cindex[k] == j) {
if (symbol[k])
symbol[k] = 0;
else {
m = 1;
}
}
}
if (m)
ccount++;
}
}
}
int
usescape(int c)
{
char d;
switch (c) {
case 'a':
c = '\a';
warning("\\a is ANSI C \"alert\" character"); break;
case 'v': c = '\v'; break;
case 'n': c = '\n'; break;
case 'r': c = '\r'; break;
case 't': c = '\t'; break;
case 'b': c = '\b'; break;
case 'f': c = 014; break; /* form feed for ascii */
case 'x': {
int dd;
c = 0;
else if (dd >= 'a')
else
break;
}
} else
c = 'x';
break;
}
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
c -= '0';
c = c * 8 + (d-'0');
}
break;
}
char tmpchar = c & 0x00ff;
}
return (c);
}
int
{
int i;
i = 0;
while (*t) {
if (scomp(s, *t) == 0)
return (i);
i++;
t++;
}
return (-1);
}
void
{
static CHR *t;
static int c;
t = p;
else
while (*t) {
while (*t == '*') {
if (*t == '/')
goto backcall;
}
/*
* FIX BUG #1058428, not parsing comments correctly
* that span more than one line
*/
if (*t != NULL)
}
while (c = gch()) {
while (c == '*') {
if ((c = gch()) == '/') {
if (!space(c))
error("unacceptable statement");
prev = '\n';
goto backcall;
}
}
}
error("unexpected EOF inside comment");
}
/*
* copy C action to the next ; or closing
*/
int
cpyact(void)
{
brac = 0;
else
while (!eof) {
c = gch();
swt:
switch (c) {
case '|':
if (peek == '|')
(void) gch(); /* eat up an extra '|' */
return (0);
}
break;
case ';':
if (brac == 0) {
return (1);
}
break;
case '{':
brac++;
break;
case '}':
brac--;
if (brac == 0) {
return (1);
}
break;
case '/':
c = gch();
if (c != '*')
goto swt;
while (c = gch()) {
while (c == '*') {
if ((c = gch()) == '/') {
while ((c = gch()) == ' ' ||
c == '\t' || c == '\n')
goto swt;
}
}
}
error("EOF inside comment");
/* NOTREACHED */
break;
case '\'': /* character constant */
case '"': /* character string */
mth = c;
while (c = gch()) {
if (c == '\\') {
c = gch();
}
else
if (c == mth)
goto loop;
if (c == '\n') {
yyline--;
"Non-terminated string or character constant");
}
}
error("EOF in string or character constant");
/* NOTREACHED */
break;
case '\0':
error("Action does not terminate");
/* NOTREACHED */
break;
default:
break; /* usual character */
}
loop:
if (c != ' ' && c != '\t' && c != '\n')
return (1);
}
}
error("Premature EOF");
return (0);
}
int
gch(void)
{
int c;
if (no_input) {
if (!yyline)
error("Cannot read from -- %s",
yyline = 0;
error("Cannot open file -- %s",
} else
break;
} else {
if (!yyline)
error("Cannot read from -- standard input");
else
break;
}
}
if (c == EOF) {
return (0);
}
if (c == '\n')
yyline++;
return (c);
}
int
mn2(int a, int d, int c)
{
tptr++;
error("Parse tree too big %s",
}
if (d >= treesize) {
error("Parse error");
}
switch (a) {
case RSTR:
break;
case BAR:
case RNEWE:
break;
case RCAT:
case DIV:
break;
/* XCU4: add RXSCON */
case RXSCON:
case RSCON:
break;
#ifdef DEBUG
default:
warning("bad switch mn2 %d %d", a, d);
break;
#endif
}
return (tptr++);
}
int
mn1(int a, int d)
{
tptr++;
error("Parse tree too big %s",
}
switch (a) {
case RCCL:
case RNCCL:
break;
case STAR:
case QUEST:
break;
case PLUS:
case CARAT:
break;
case S2FINAL:
break;
#ifdef DEBUG
case FINAL:
case S1FINAL:
break;
default:
warning("bad switch mn1 %d %d", a, d);
break;
#endif
}
return (tptr++);
}
int
mn0(int a)
{
tptr++;
error("Parse tree too big %s",
}
if (ISOPERATOR(a)) {
switch (a) {
case DOT: break;
#ifdef DEBUG
default:
warning("bad switch mn0 %d", a);
break;
#endif
}
}
return (tptr++);
}
void
{
int i, j;
if (t == 'c') {
peek = *p;
} else if (t == 's') {
peek = p[0];
i = slength(p);
for (j = i - 1; j >= 1; j--)
*pushptr++ = p[j];
}
error("Too many characters pushed");
}
int
dupl(int n)
{
/* duplicate the subtree whose root is n, return ptr to it */
int i;
i = name[n];
if (!ISOPERATOR(i))
return (mn0(i));
switch (i) {
case DOT:
case RNULLS:
return (mn0(i));
/* XCU4: add RXSCON */
}
return (0);
}
#ifdef DEBUG
void
{
switch (c) {
case 014:
(void) printf("\\f");
charc++;
break;
case '\n':
(void) printf("\\n");
charc++;
break;
case '\t':
(void) printf("\\t");
charc++;
break;
case '\b':
(void) printf("\\b");
charc++;
break;
case ' ':
(void) printf("\\_");
break;
default:
if (!iswprint(c)) {
charc += 3;
} else
break;
}
charc++;
}
void
{
charc = 0;
while (*s) {
allprint(*s++);
charc = 0;
(void) printf("\n\t");
}
}
}
void
sect1dump(void)
{
int i;
(void) printf("Sect 1:\n");
if (def[0]) {
(void) printf("str trans\n");
i = -1;
while (def[++i])
}
if (sname[0]) {
(void) printf("start names\n");
i = -1;
while (sname[++i])
}
(void) printf("char set changed\n");
for (i = 1; i < NCH; i++) {
if (i != ctable[i]) {
allprint(i);
(void) putchar(' ');
(void) putchar('\n');
}
}
}
}
void
sect2dump(void)
{
(void) printf("Sect 2:\n");
treedump();
}
void
treedump(void)
{
int t;
CHR *p;
for (t = 0; t < tptr; t++) {
(void) printf("%4d ", t);
(void) printf(" ");
(void) printf(" ");
if (!ISOPERATOR(name[t])) {
} else
switch (name[t]) {
case RSTR:
break;
case RCCL:
(void) printf("ccl ");
break;
case RNCCL:
(void) printf("nccl ");
break;
case DIV:
break;
case BAR:
break;
case RCAT:
break;
case PLUS:
break;
case STAR:
break;
case CARAT:
break;
case QUEST:
break;
case RNULLS:
(void) printf("nullstring");
break;
case FINAL:
break;
case S1FINAL:
break;
case S2FINAL:
break;
case RNEWE:
break;
/* XCU4: add RXSCON */
case RXSCON:
while (*p)
break;
case RSCON:
while (*p)
break;
case DOT:
printf("dot");
break;
default:
(void) printf(
break;
}
if (nullstr[t])
(void) printf("\t(null poss.)");
(void) putchar('\n');
}
}
#endif