58 if (
saw_eof || (c = getc(f)) == EOF)
79 if (c ==
'\n') {
cptr =
line;
return; }
101 register char *p, *s, *t;
103 if (
line == 0)
return (0);
105 while (*s !=
'\n') ++s;
111 while ((*t++ = *s++) !=
'\n')
continue;
122 char *st_cptr = st_line + (
cptr -
line);
127 if (*s ==
'*' && s[1] ==
'/')
165 if (
line == 0)
return (EOF);
191 else if (s[1] ==
'/')
194 if (
line == 0)
return (EOF);
222 if (isupper(c)) c = tolower(c);
225 else if (isdigit(c) || c ==
'_' || c ==
'.' || c ==
'$')
233 if (strcmp(
cache,
"token") == 0 || strcmp(
cache,
"term") == 0)
235 if (strcmp(
cache,
"type") == 0)
237 if (strcmp(
cache,
"left") == 0)
239 if (strcmp(
cache,
"right") == 0)
241 if (strcmp(
cache,
"nonassoc") == 0 || strcmp(
cache,
"binary") == 0)
243 if (strcmp(
cache,
"start") == 0)
245 if (strcmp(
cache,
"union") == 0)
247 if (strcmp(
cache,
"ident") == 0)
255 if (c ==
'%' || c ==
'\\')
280 fprintf(f,
"#ident \"");
305 int need_newline = 0;
308 char *t_cptr = t_line + (
cptr -
line - 2);
335 char *s_cptr = s_line + (
cptr -
line - 1);
372 while ((c = *++
cptr) !=
'\n')
374 if (c ==
'*' &&
cptr[1] ==
'/')
386 char *c_cptr = c_line + (
cptr -
line - 1);
394 if (c ==
'*' && *
cptr ==
'/')
416 if (need_newline) putc(
'\n', f);
438 char *u_cptr = u_line + (
cptr -
line - 6);
480 char *s_cptr = s_line + (
cptr -
line - 1);
516 while ((c = *++
cptr) !=
'\n')
518 if (c ==
'*' &&
cptr[1] ==
'/')
537 char *c_cptr = c_line + (
cptr -
line - 1);
547 if (c ==
'*' && *
cptr ==
'/')
575 if (c >=
'0' && c <=
'9')
577 if (c >=
'A' && c <=
'F')
578 return (c -
'A' + 10);
579 if (c >=
'a' && c <=
'f')
580 return (c -
'a' + 10);
588 register int c, quote;
595 char *s_cptr = s_line + (
cptr -
line);
602 if (c == quote)
break;
606 char *c_cptr =
cptr - 1;
616 case '0':
case '1':
case '2':
case '3':
617 case '4':
case '5':
case '6':
case '7':
622 n = (n << 3) + (c -
'0');
626 n = (n << 3) + (c -
'0');
637 if (n < 0 || n >= 16)
643 if (i < 0 || i >= 16)
break;
651 case 'a': c = 7;
break;
652 case 'b': c =
'\b';
break;
653 case 'f': c =
'\f';
break;
654 case 'n': c =
'\n';
break;
655 case 'r': c =
'\r';
break;
656 case 't': c =
'\t';
break;
657 case 'v': c =
'\v';
break;
668 for (i = 0; i < n; ++i)
677 for (i = 0; i < n; ++i)
679 c = ((
unsigned char *)s)[i];
680 if (c ==
'\\' || c ==
cache[0])
692 case 7:
cachec(
'a');
break;
693 case '\b':
cachec(
'b');
break;
694 case '\f':
cachec(
'f');
break;
695 case '\n':
cachec(
'n');
break;
696 case '\r':
cachec(
'r');
break;
697 case '\t':
cachec(
't');
break;
698 case '\v':
cachec(
'v');
break;
700 cachec(((c >> 6) & 7) +
'0');
701 cachec(((c >> 3) & 7) +
'0');
717 bp->
value = *(
unsigned char *)s;
730 if (strcmp(name,
".") == 0 ||
731 strcmp(name,
"$accept") == 0 ||
732 strcmp(name,
"$end") == 0)
735 if (name[0] ==
'$' && name[1] ==
'$' && isdigit(name[2]))
738 while (isdigit(*s)) ++s;
739 if (*s ==
NUL)
return (1);
769 for (c = *
cptr; isdigit(c); c = *++
cptr)
770 n = 10*n + (c -
'0');
784 char *t_cptr = t_line + (
cptr -
line);
789 if (!isalpha(c) && c !=
'_' && c !=
'$')
802 for (i = 0; i <
ntags; ++i)
848 if (isalpha(c) || c ==
'_' || c ==
'.' || c ==
'$')
850 else if (c ==
'\'' || c ==
'"')
860 if (bp->
tag && tag != bp->
tag)
903 if (isalpha(c) || c ==
'_' || c ==
'.' || c ==
'$')
905 else if (c ==
'\'' || c ==
'"')
910 if (bp->
tag && tag != bp->
tag)
924 if (!isalpha(c) && c !=
'_' && c !=
'.' && c !=
'$')
929 if (goal && goal != bp)
1045 if (c !=
'%')
break;
1066 if (!isalpha(c) && c !=
'_' && c !=
'.' && c !=
'_')
1089 if (bp->class ==
TERM)
1106 for (i =
nitems - 1; pitem[i]; --i)
continue;
1107 if (pitem[i+1] == 0 || pitem[i+1]->tag != plhs[
nrules]->tag)
1121 register bucket *bp, **bpp;
1133 bpp = pitem +
nitems - 1;
1135 while (bpp[0] = bpp[-1]) --bpp;
1155 if (c ==
'\'' || c ==
'"')
1189 char *a_cptr = a_line + (
cptr -
line);
1195 fprintf(f,
"case %d:\n",
nrules - 2);
1201 for (i =
nitems - 1; pitem[i]; --i) ++n;
1212 char *d_cptr = d_line + (
cptr -
line);
1219 fprintf(f,
"yyval.%s", tag);
1224 else if (isdigit(c))
1228 fprintf(f,
"yyvsp[%d].%s", i - n, tag);
1232 else if (c ==
'-' && isdigit(cptr[1]))
1236 fprintf(f,
"yyvsp[%d].%s", i, tag);
1243 else if (
cptr[1] ==
'$')
1249 fprintf(f,
"yyval.%s", tag);
1252 fprintf(f,
"yyval");
1256 else if (isdigit(
cptr[1]))
1262 if (i <= 0 || i > n)
1266 fprintf(f,
"yyvsp[%d].%s", i - n, tag);
1272 fprintf(f,
"yyvsp[%d]", i - n);
1276 else if (
cptr[1] ==
'-')
1282 fprintf(f,
"yyvsp[%d]", -i - n);
1286 if (isalpha(c) || c ==
'_' || c ==
'$')
1292 }
while (isalnum(c) || c ==
'_' || c ==
'$');
1302 if (
line)
goto loop;
1306 if (depth > 0)
goto loop;
1307 fprintf(f,
"\nbreak;\n");
1315 if (--depth > 0)
goto loop;
1316 fprintf(f,
"\nbreak;\n");
1324 char *s_cptr = s_line + (
cptr -
line - 1);
1357 while ((c = *++
cptr) !=
'\n')
1359 if (c ==
'*' &&
cptr[1] ==
'/')
1371 char *c_cptr = c_line + (
cptr -
line - 1);
1379 if (c ==
'*' && *
cptr ==
'/')
1409 if (c ==
'%' || c ==
'\\')
1417 else if ((c ==
'p' || c ==
'P') &&
1418 ((c =
cptr[2]) ==
'r' || c ==
'R') &&
1419 ((c =
cptr[3]) ==
'e' || c ==
'E') &&
1420 ((c =
cptr[4]) ==
'c' || c ==
'C') &&
1427 if (isalpha(c) || c ==
'_' || c ==
'.' || c ==
'$')
1429 else if (c ==
'\'' || c ==
'"')
1456 if (c == EOF)
break;
1457 if (isalpha(c) || c ==
'_' || c ==
'.' || c ==
'$' || c ==
'\'' ||
1460 else if (c ==
'{' || c ==
'=')
1485 for (i = 0; i <
ntags; ++i)
1510 register char *p, *s, *t;
1525 while (*t++ = *s++)
continue;
1557 register int i, j, k, n;
1593 assert(i == ntokens && j ==
nsyms);
1664 for (++i; i <
nsyms; ++i)
1708 for (i = 3; i <
nrules; ++i)
1717 if (pitem[j]->
class ==
TERM)
1719 prec = pitem[j]->
prec;
1720 assoc = pitem[j]->
assoc;
1741 register int i, j, k;
1748 for (i = 2; i <
nrules; ++i)
1752 if (i != 2) fprintf(f,
"\n");
1758 fprintf(f,
"%4d ", i - 2);
1760 while (--j >= 0) putc(
' ', f);
1764 while (
ritem[k] >= 0)
unterminated_string(int s_lineno, char *s_line, char *s_cptr)
illegal_character(char *c_cptr)
unterminated_action(int a_lineno, char *a_line, char *a_cptr)
short * rlhs
List of left-hand sides of all rules.
int ntokens
The number of tokens (terminals) in the grammar.
dollar_error(int a_lineno, char *a_line, char *a_cptr)
unterminated_union(int u_lineno, char *u_line, char *u_cptr)
terminal_lhs(int s_lineno)
revalued_warning(char *s)
dollar_warning(int a_lineno, int i)
illegal_tag(int t_lineno, char *t_line, char *t_cptr)
int nrules
The number of rules in the grammar.
undefined_symbol_warning(char *s)
int nvars
The number of variables (non-terminals) in the grammar.
int is_reserved(char *name)
int nsyms
The number of symbols (terminals + non-terminals) in the grammar.
short * rrhs
List of right-hand sides of all rules.
short * ritem
Representation of all productions (and items)
unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
syntax_error(int st_lineno, char *st_line, char *st_cptr)
unterminated_text(int t_lineno, char *t_line, char *t_cptr)
int start_symbol
Index of the starting symbol of the grammar.
untyped_rhs(int i, char *s)
declare_tokens(int assoc)
over_unionized(char *u_cptr)
char ** symbol_name
Array of symbol names.
start_rule(bucket *bp, int s_lineno)