%token CHAR CCL NCCL STR DELIM SCON ITER NEWE NULLS
%left CHAR CCL NCCL '(' '.' STR NULLS
lexinput: defns delim prods end
error("Too many definitions");
error("Definitions too long");
subs[dptr]=def[dptr]=0; /* for lookup - require ending null */
if(sect == DEFSECTION && debug) sect1dump();
={ $$ = mn2(RNEWE,$1,$2);
i = mn1(S1FINAL,casecount);
else i = mn1(FINAL,casecount);
error("Too many large character classes");
={ $$ = mn2(BAR,$1,$3); }
={ $$ = mn2(RCAT,$1,$2); }
j = mn1(S2FINAL,-casecount);
warning("Extra slash removed");
warning("Iteration range must be positive");
j = mn2(RCAT,j,dupl($1));
for(i = $2+1; i<=$4; i++){
g = mn2(RCAT,g,dupl($1));
if($2 < 0)warning("Can't have negative iteration");
else if($2 == 0) $$ = mn0(RNULLS);
j = mn2(RCAT,j,dupl($1));
if($2 < 0)warning("Can't have negative iteration");
else if($2 == 0) $$ = mn1(STAR,$1);
else if($2 == 1)$$ = mn1(PLUS,$1);
else { /* >= 2 iterations minimum */
j = mn2(RCAT,j,dupl($1));
={ $$ = mn2(RSCON,$2,$1); }
j = mn1(S2FINAL,-casecount);
else $$ = mn2(RCAT,$1,i);
static char token[TOKENSIZE];
if(sect == DEFSECTION) { /* definitions section */
if(prev == '\n'){ /* next char is at beginning of line */
if(!ratfor)fprintf(fout,"# ");
fprintf(fout,"define YYNEWLINE %d\n",ctable['\n']);
if(!ratfor)fprintf(fout,"yylex(){\nint nstr; extern int yyprevious;\n");
i = treesize*(sizeof(*name)+sizeof(*left)+
sizeof(*right)+sizeof(*nullstr)+sizeof(*parent))+ALITTLEEXTRA;
error("Too little core for parse tree");
name = myalloc(treesize,sizeof(*name));
left = myalloc(treesize,sizeof(*left));
right = myalloc(treesize,sizeof(*right));
nullstr = myalloc(treesize,sizeof(*nullstr));
parent = myalloc(treesize,sizeof(*parent));
if(name == 0 || left == 0 || right == 0 || parent == 0 || nullstr == 0)
error("Too little core for parse tree");
case 'p': case 'P': /* has overridden number of positions */
while(*p && !digit(*p))p++;
if (debug) printf("positions (%%p) now %d\n",maxpos);
if(report == 2)report = 1;
case 'n': case 'N': /* has overridden number of states */
while(*p && !digit(*p))p++;
if(debug)printf( " no. states (%%n) now %d\n",nstates);
if(report == 2)report = 1;
case 'e': case 'E': /* has overridden number of tree nodes */
while(*p && !digit(*p))p++;
if (debug) printf("treesize (%%e) now %d\n",treesize);
if(report == 2)report = 1;
while (*p && !digit(*p))p++;
if (report ==2) report=1;
case 'a': case 'A': /* has overridden number of transitions */
while(*p && !digit(*p))p++;
if(report == 2)report = 1;
if (debug)printf("N. trans (%%a) now %d\n",ntrans);
case 'k': case 'K': /* overriden packed char classes */
while (*p && !digit(*p))p++;
cfree(pchar, pchlen, sizeof(*pchar));
if (debug) printf( "Size classes (%%k) now %d\n",pchlen);
pchar=pcptr=myalloc(pchlen, sizeof(*pchar));
case 't': case 'T': /* character set specifier */
if (ZCH < NCH) ZCH = NCH;
if (ZCH > 2*NCH) error("ch table needs redeclaration");
while(getl(p) && scomp(p,"%T") != 0 && scomp(p,"%t") != 0){
if((n = siconv(p)) <= 0 || n > ZCH){
warning("Character value %d out of range",n);
while(!space(*p) && *p) p++;
warning("Character '%c' used twice",c);
warning("Character %o used twice",c);
char chused[2*NCH]; int kr;
error("Too late for language specifier");
while(getl(p) && scomp(p,"%}") != 0)
if(p[0] == '%') continue;
case 's': case 'S': /* start conditions */
while(*p && index(*p," \t,") < 0) p++;
while(*p && index(*p," \t,") >= 0) p++;
while(*p && index(*p," \t,") < 0)p++;
if(!ratfor)fprintf(fout,"# ");
fprintf(fout,"define %s %d\n",t,i);
sname[sptr] = 0; /* required by lookup */
error("Too many start conditions");
if(sp >= schar+STARTCHAR)
error("Start conditions too long");
warning("Invalid request %s",p);
} /* end of switch after seeing '%' */
case ' ': case '\t': /* must be code */
default: /* definition */
while(*p && !space(*p)) p++;
warning("Substitution strings may not begin with digits");
/* still sect 1, but prev != '\n' */
while(*p && space(*p)) p++;
warning("No translation given - null string assumed");
/* end of section one processing */
else if(sect == RULESECTION){ /* rules and actions */
if(prev == '\n') continue;
while((c=gch()) && c != '\n');
if(ratfor)fprintf(fout,"%d\n",30000+casecount);
else fprintf(fout,"case %d:\n",casecount);
if(ratfor)fprintf(fout,"goto 30997\n");
else fprintf(fout,"break;\n");
while((c=gch()) && c != '\n');
if(peek == ' ' || peek == '\t' || sectbegin == TRUE){
warning("Executable statements should occur right after %%");
if(prev != '\n') goto character;
if(peek == '{'){ /* included code */
while(!eof && getl(buf) && scomp("%}",buf) != 0)
fprintf(fout,"%s\n",buf);
if(peek == ' ' || peek == '\t' || peek == '\n'){
if(ratfor)fprintf(fout,"%d\n",30000+casecount++);
else fprintf(fout,"case %d:\n",casecount++);
if(peek == '\n' || peek == ' ' || peek == '\t' || peek == '|' || peek == '/'){
if(prev != '\n' && scon != TRUE) goto character; /* valid only at line begin */
case '{': /* either iteration or definition */
if(digit(c=gch())){ /* iteration */
warning("Definition %s not found",token);
case '<': /* start condition ? */
if(prev != '\n') /* not at line begin, not start */
while(c != ',' && c && c != '>'){
warning("Undefined start condition %s",token);
/* check if previous value re-usable */
/* re-use previous pointer to string */
if(slptr > slist+STARTSIZE) /* note not packed ! */
error("Too many start conditions used");
while((c=gch()) && c != '"' && c != '\n'){
if(c == '\\') c = usescape(c=gch());
warning("String too long");
warning("Non-terminated string");
for(i=1;i<NCH;i++) symbol[i] = 0;
if(c == '\\') c = usescape(c=gch());
if((c=gch()) == '-' && peek != ']'){ /* range specified */
if(c == '\\') c = usescape(c=gch());
if(!(('A' <= j && k <= 'Z') ||
('a' <= j && k <= 'z') ||
warning("Non-portable Character Class");
symbol[n] = 1; /* implementation dependent */
if(symbol[j])token[i++] = j;
while(p <ccptr && scomp(token,p) != 0)p++;
if(p < ccptr) /* found it */
ccptr =+ slength(token) + 1;
error("Too many large character classes");
if(iter){ /* second part of an iteration */
if(peek == '?' || peek == '*' || peek == '+')
if(x == SCON)scon = TRUE;
fprintf(fout,"\n/*this comes from section three - debug */\n");
fprintf(fout,"%s\n",buf);
case STR: case CCL: case NCCL: