46 static void start_rule(
bucket *bp,
int s_lineno);
71 if (
saw_eof || (c = getc(f)) == EOF)
92 if (c ==
'\n') {
cptr =
line;
return; }
116 if (
line == 0)
return (0);
118 while (*s !=
'\n') ++s;
124 while ((*t++ = *s++) !=
'\n')
continue;
135 char *st_line = dup_line();
136 char *st_cptr = st_line + (
cptr -
line);
141 if (*s ==
'*' && s[1] ==
'/')
179 if (
line == 0)
return (EOF);
205 else if (s[1] ==
'/')
208 if (
line == 0)
return (EOF);
236 if (isupper(c)) c = tolower(c);
239 else if (isdigit(c) || c ==
'_' || c ==
'.' || c ==
'$')
247 if (strcmp(
cache,
"token") == 0 || strcmp(
cache,
"term") == 0)
249 if (strcmp(
cache,
"type") == 0)
251 if (strcmp(
cache,
"left") == 0)
253 if (strcmp(
cache,
"right") == 0)
255 if (strcmp(
cache,
"nonassoc") == 0 || strcmp(
cache,
"binary") == 0)
257 if (strcmp(
cache,
"start") == 0)
259 if (strcmp(
cache,
"union") == 0)
261 if (strcmp(
cache,
"ident") == 0)
269 if (c ==
'%' || c ==
'\\')
295 fprintf(f,
"#ident \"");
321 int need_newline = 0;
323 char *t_line = dup_line();
324 char *t_cptr = t_line + (
cptr -
line - 2);
350 char *s_line = dup_line();
351 char *s_cptr = s_line + (
cptr -
line - 1);
388 while ((c = *++
cptr) !=
'\n')
390 if (c ==
'*' &&
cptr[1] ==
'/')
401 char *c_line = dup_line();
402 char *c_cptr = c_line + (
cptr -
line - 1);
410 if (c ==
'*' && *
cptr ==
'/')
432 if (need_newline) putc(
'\n', f);
454 char *u_line = dup_line();
455 char *u_cptr = u_line + (
cptr -
line - 6);
496 char *s_line = dup_line();
497 char *s_cptr = s_line + (
cptr -
line - 1);
533 while ((c = *++
cptr) !=
'\n')
535 if (c ==
'*' &&
cptr[1] ==
'/')
553 char *c_line = dup_line();
554 char *c_cptr = c_line + (
cptr -
line - 1);
564 if (c ==
'*' && *
cptr ==
'/')
591 if (c >=
'0' && c <=
'9')
593 if (c >=
'A' && c <=
'F')
594 return (c -
'A' + 10);
595 if (c >=
'a' && c <=
'f')
596 return (c -
'a' + 10);
610 char *s_line = dup_line();
611 char *s_cptr = s_line + (
cptr -
line);
618 if (c == quote)
break;
622 char *c_cptr =
cptr - 1;
632 case '0':
case '1':
case '2':
case '3':
633 case '4':
case '5':
case '6':
case '7':
638 n = (n << 3) + (c -
'0');
642 n = (n << 3) + (c -
'0');
653 if (n < 0 || n >= 16)
659 if (i < 0 || i >= 16)
break;
667 case 'a': c = 7;
break;
668 case 'b': c =
'\b';
break;
669 case 'f': c =
'\f';
break;
670 case 'n': c =
'\n';
break;
671 case 'r': c =
'\r';
break;
672 case 't': c =
'\t';
break;
673 case 'v': c =
'\v';
break;
684 for (i = 0; i < n; ++
i)
693 for (i = 0; i < n; ++
i)
695 c = ((
unsigned char *)s)[
i];
696 if (c ==
'\\' || c ==
cache[0])
708 case 7: cachec(
'a');
break;
709 case '\b': cachec(
'b');
break;
710 case '\f': cachec(
'f');
break;
711 case '\n': cachec(
'n');
break;
712 case '\r': cachec(
'r');
break;
713 case '\t': cachec(
't');
break;
714 case '\v': cachec(
'v');
break;
716 cachec(((c >> 6) & 7) +
'0');
717 cachec(((c >> 3) & 7) +
'0');
718 cachec((c & 7) +
'0');
733 bp->
value = *(
unsigned char *)s;
741 is_reserved(
char *name)
745 if (strcmp(name,
".") == 0 ||
746 strcmp(name,
"$accept") == 0 ||
747 strcmp(name,
"$end") == 0)
750 if (name[0] ==
'$' && name[1] ==
'$' && isdigit((
int) name[2]))
753 while (isdigit((
int) *s)) ++s;
754 if (*s ==
NUL)
return (1);
784 for (c = *
cptr; isdigit(c); c = *++
cptr)
785 n = 10*n + (c -
'0');
798 char *t_line = dup_line();
799 char *t_cptr = t_line + (
cptr -
line);
804 if (!isalpha(c) && c !=
'_' && c !=
'$')
817 for (i = 0; i <
ntags; ++
i)
843 declare_tokens(
int assoc)
863 if (isalpha(c) || c ==
'_' || c ==
'.' || c ==
'$')
865 else if (c ==
'\'' || c ==
'"')
875 if (bp->
tag && tag != bp->
tag)
893 value = get_number();
919 if (isalpha(c) || c ==
'_' || c ==
'.' || c ==
'$')
921 else if (c ==
'\'' || c ==
'"')
926 if (bp->
tag && tag != bp->
tag)
941 if (!isalpha(c) && c !=
'_' && c !=
'.' && c !=
'$')
946 if (goal && goal != bp)
953 read_declarations(
void)
966 switch (k = keyword())
1003 initialize_grammar(
void)
1057 advance_to_start(
void)
1067 if (c !=
'%')
break;
1088 if (!isalpha(c) && c !=
'_' && c !=
'.' && c !=
'_')
1102 start_rule(bp, s_lineno);
1108 start_rule(
bucket *bp,
int s_lineno)
1128 for (i =
nitems - 1; pitem[
i]; --
i)
continue;
1129 if (pitem[i+1] == 0 || pitem[i+1]->tag != plhs[
nrules]->tag)
1142 insert_empty_rule(
void)
1156 bpp = pitem +
nitems - 1;
1158 while ((bpp[0] = bpp[-1])) --bpp;
1179 if (c ==
'\'' || c ==
'"')
1188 start_rule(bp, s_lineno);
1194 insert_empty_rule();
1199 pitem[nitems-1] = bp;
1213 char *a_line = dup_line();
1214 char *a_cptr = a_line + (cptr -
line);
1217 insert_empty_rule();
1220 fprintf(f,
"case %d:\n",
nrules - 2);
1223 if (*cptr ==
'=') ++
cptr;
1226 for (i = nitems - 1; pitem[
i]; --
i) ++n;
1236 char *d_line = dup_line();
1237 char *d_cptr = d_line + (cptr -
line);
1244 fprintf(f,
"yyval.%s", tag);
1249 else if (isdigit(c))
1253 fprintf(f,
"yyvsp[%d].%s", i - n, tag);
1257 else if (c ==
'-' && isdigit((
int) cptr[1]))
1260 i = -get_number() - n;
1261 fprintf(f,
"yyvsp[%d].%s", i, tag);
1268 else if (cptr[1] ==
'$')
1274 fprintf(f,
"yyval.%s", tag);
1277 fprintf(f,
"yyval");
1281 else if (isdigit((
int) cptr[1]))
1287 if (i <= 0 || i > n)
1289 tag = pitem[nitems + i - n - 1]->
tag;
1290 if (tag == 0)
untyped_rhs(i, pitem[nitems + i - n - 1]->name);
1291 fprintf(f,
"yyvsp[%d].%s", i - n, tag);
1297 fprintf(f,
"yyvsp[%d]", i - n);
1301 else if (cptr[1] ==
'-')
1307 fprintf(f,
"yyvsp[%d]", -i - n);
1311 if (isalpha(c) || c ==
'_' || c ==
'$')
1317 }
while (isalnum(c) || c ==
'_' || c ==
'$');
1327 if (
line)
goto loop;
1331 if (depth > 0)
goto loop;
1332 fprintf(f,
"\nbreak;\n");
1341 if (--depth > 0)
goto loop;
1342 fprintf(f,
"\nbreak;\n");
1350 char *s_line = dup_line();
1351 char *s_cptr = s_line + (cptr -
line - 1);
1384 while ((c = *++cptr) !=
'\n')
1386 if (c ==
'*' && cptr[1] ==
'/')
1397 char *c_line = dup_line();
1398 char *c_cptr = c_line + (cptr -
line - 1);
1406 if (c ==
'*' && *cptr ==
'/')
1436 if (c ==
'%' || c ==
'\\')
1444 else if ((c ==
'p' || c ==
'P') &&
1445 ((c = cptr[2]) ==
'r' || c ==
'R') &&
1446 ((c = cptr[3]) ==
'e' || c ==
'E') &&
1447 ((c = cptr[4]) ==
'c' || c ==
'C') &&
1454 if (isalpha(c) || c ==
'_' || c ==
'.' || c ==
'$')
1456 else if (c ==
'\'' || c ==
'"')
1478 initialize_grammar();
1484 if (c == EOF)
break;
1485 if (isalpha(c) || c ==
'_' || c ==
'.' || c ==
'$' || c ==
'\'' ||
1488 else if (c ==
'{' || c ==
'=')
1493 start_rule(plhs[nrules-1], 0);
1498 if (mark_symbol())
break;
1514 for (i = 0; i <
ntags; ++
i)
1542 while ((*t++ = *s++))
continue;
1680 for (++i; i <
nsyms; ++
i)
1701 rlhs = (
short *)
MALLOC(nrules*
sizeof(
short));
1703 rrhs = (
short *)
MALLOC((nrules+1)*
sizeof(short));
1731 if (pitem[j]->
class ==
TERM)
1733 prec = pitem[j]->
prec;
1734 assoc = pitem[j]->
assoc;
1767 if (i != 2) fprintf(f,
"\n");
1773 fprintf(f,
"%4d ", i - 2);
1775 while (--j >= 0) putc(
' ', f);
1779 while (
ritem[k] >= 0)
1795 read_declarations();
void retyped_warning(char *s)
void unexpected_EOF(void) NORETURN
void illegal_tag(int t_lineno, char *t_line, char *t_cptr) NORETURN
#define assert(exp)
Declare that a condition should be true.
void used_reserved(char *s) NORETURN
void unknown_rhs(int i) NORETURN
void over_unionized(char *u_cptr) NORETURN
void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) NORETURN
bucket * make_bucket(char *name)
void no_grammar(void) NORETURN
void unterminated_action(int a_lineno, char *a_line, char *a_cptr) NORETURN
void restarted_warning(void)
void tokenized_start(char *s) NORETURN
bucket * lookup(char *name)
void undefined_goal(char *s) NORETURN
void illegal_character(char *c_cptr) NORETURN
void untyped_lhs(void) NORETURN
void write_section(char *section[])
void revalued_warning(char *s)
void prec_redeclared(void)
void terminal_lhs(int s_lineno) NORETURN
void dollar_error(int a_lineno, char *a_line, char *a_cptr) NORETURN
void default_action_warning(void)
void untyped_rhs(int i, char *s) NORETURN
void create_symbol_table(void)
void dollar_warning(int a_lineno, int i)
void reprec_warning(char *s)
void unterminated_string(int s_lineno, char *s_line, char *s_cptr) NORETURN
void free_symbol_table(void)
void no_space(void) NORETURN
void unterminated_union(int u_lineno, char *u_line, char *u_cptr) NORETURN
void terminal_start(char *s)
void undefined_symbol_warning(char *s)
void syntax_error(int st_lineno, char *st_line, char *st_cptr) NORETURN
Internal: Hash table structure.
void unterminated_text(int t_lineno, char *t_line, char *t_cptr) NORETURN