version 1.22, 2010/07/14 13:13:42 |
version 1.23, 2012/04/15 12:44:38 |
|
|
{ |
{ |
cache_size += 256; |
cache_size += 256; |
cache = REALLOC(cache, cache_size); |
cache = REALLOC(cache, cache_size); |
if (cache == 0) no_space(); |
if (cache == NULL) no_space(); |
} |
} |
cache[cinc] = c; |
cache[cinc] = c; |
++cinc; |
++cinc; |
|
|
return; |
return; |
} |
} |
|
|
if (line == 0 || linesize != (LINESIZE + 1)) |
if (line == NULL || linesize != (LINESIZE + 1)) |
{ |
{ |
if (line) FREE(line); |
if (line) FREE(line); |
linesize = LINESIZE + 1; |
linesize = LINESIZE + 1; |
line = MALLOC(linesize); |
line = MALLOC(linesize); |
if (line == 0) no_space(); |
if (line == NULL) no_space(); |
} |
} |
|
|
i = 0; |
i = 0; |
|
|
{ |
{ |
char *p, *s, *t; |
char *p, *s, *t; |
|
|
if (line == 0) return (0); |
if (line == NULL) return (0); |
s = line; |
s = line; |
while (*s != '\n') ++s; |
while (*s != '\n') ++s; |
p = MALLOC(s - line + 1); |
p = MALLOC(s - line + 1); |
if (p == 0) no_space(); |
if (p == NULL) no_space(); |
|
|
s = line; |
s = line; |
t = p; |
t = p; |
|
|
if (*s == '\n') |
if (*s == '\n') |
{ |
{ |
get_line(); |
get_line(); |
if (line == 0) |
if (line == NULL) |
unterminated_comment(st_lineno, st_line, st_cptr); |
unterminated_comment(st_lineno, st_line, st_cptr); |
s = cptr; |
s = cptr; |
} |
} |
|
|
{ |
{ |
char *s; |
char *s; |
|
|
if (line == 0) |
if (line == NULL) |
{ |
{ |
get_line(); |
get_line(); |
if (line == 0) |
if (line == NULL) |
return (EOF); |
return (EOF); |
} |
} |
|
|
|
|
{ |
{ |
case '\n': |
case '\n': |
get_line(); |
get_line(); |
if (line == 0) return (EOF); |
if (line == NULL) return (EOF); |
s = cptr; |
s = cptr; |
break; |
break; |
|
|
|
|
else if (s[1] == '/') |
else if (s[1] == '/') |
{ |
{ |
get_line(); |
get_line(); |
if (line == 0) return (EOF); |
if (line == NULL) return (EOF); |
s = cptr; |
s = cptr; |
break; |
break; |
} |
} |
|
|
if (*cptr == '\n') |
if (*cptr == '\n') |
{ |
{ |
get_line(); |
get_line(); |
if (line == 0) |
if (line == NULL) |
unterminated_text(t_lineno, t_line, t_cptr); |
unterminated_text(t_lineno, t_line, t_cptr); |
} |
} |
if (!lflag) fprintf(f, line_format, lineno, input_file_name); |
if (!lflag) fprintf(f, line_format, lineno, input_file_name); |
|
|
if (c == '\n') |
if (c == '\n') |
{ |
{ |
get_line(); |
get_line(); |
if (line == 0) |
if (line == NULL) |
unterminated_string(s_lineno, s_line, s_cptr); |
unterminated_string(s_lineno, s_line, s_cptr); |
} |
} |
} |
} |
|
|
if (c == '\n') |
if (c == '\n') |
{ |
{ |
get_line(); |
get_line(); |
if (line == 0) |
if (line == NULL) |
unterminated_comment(c_lineno, c_line, c_cptr); |
unterminated_comment(c_lineno, c_line, c_cptr); |
} |
} |
} |
} |
|
|
case '\n': |
case '\n': |
next_line: |
next_line: |
get_line(); |
get_line(); |
if (line == 0) unterminated_union(u_lineno, u_line, u_cptr); |
if (line == NULL) unterminated_union(u_lineno, u_line, u_cptr); |
goto loop; |
goto loop; |
|
|
case '{': |
case '{': |
|
|
if (c == '\n') |
if (c == '\n') |
{ |
{ |
get_line(); |
get_line(); |
if (line == 0) |
if (line == NULL) |
unterminated_string(s_lineno, s_line, s_cptr); |
unterminated_string(s_lineno, s_line, s_cptr); |
} |
} |
} |
} |
|
|
if (c == '\n') |
if (c == '\n') |
{ |
{ |
get_line(); |
get_line(); |
if (line == 0) |
if (line == NULL) |
unterminated_comment(c_lineno, c_line, c_cptr); |
unterminated_comment(c_lineno, c_line, c_cptr); |
} |
} |
} |
} |
|
|
{ |
{ |
case '\n': |
case '\n': |
get_line(); |
get_line(); |
if (line == 0) unterminated_string(s_lineno, s_line, s_cptr); |
if (line == NULL) unterminated_string(s_lineno, s_line, s_cptr); |
continue; |
continue; |
|
|
case '0': case '1': case '2': case '3': |
case '0': case '1': case '2': case '3': |
|
|
|
|
n = cinc; |
n = cinc; |
s = MALLOC(n); |
s = MALLOC(n); |
if (s == 0) no_space(); |
if (s == NULL) no_space(); |
|
|
for (i = 0; i < n; ++i) |
memcpy(s, cache, n); |
s[i] = cache[i]; |
|
|
|
cinc = 0; |
cinc = 0; |
if (n == 1) |
if (n == 1) |
|
|
tag_table = (char **) |
tag_table = (char **) |
(tag_table ? REALLOC(tag_table, tagmax*sizeof(char *)) |
(tag_table ? REALLOC(tag_table, tagmax*sizeof(char *)) |
: MALLOC(tagmax*sizeof(char *))); |
: MALLOC(tagmax*sizeof(char *))); |
if (tag_table == 0) no_space(); |
if (tag_table == NULL) no_space(); |
} |
} |
|
|
s = MALLOC(cinc); |
s = MALLOC(cinc); |
if (s == 0) no_space(); |
if (s == NULL) no_space(); |
strlcpy(s, cache, cinc); |
strlcpy(s, cache, cinc); |
tag_table[ntags] = s; |
tag_table[ntags] = s; |
++ntags; |
++ntags; |
|
|
c = *++cptr; |
c = *++cptr; |
if (c == EOF) unexpected_EOF(); |
if (c == EOF) unexpected_EOF(); |
|
|
for(;;) |
for (;;) |
{ |
{ |
if (isdigit(c)) |
if (isdigit(c)) |
{ |
{ |
|
|
|
|
cache_size = 256; |
cache_size = 256; |
cache = MALLOC(cache_size); |
cache = MALLOC(cache_size); |
if (cache == 0) no_space(); |
if (cache == NULL) no_space(); |
|
|
for (;;) |
for (;;) |
{ |
{ |
|
|
nitems = 4; |
nitems = 4; |
maxitems = 300; |
maxitems = 300; |
pitem = (bucket **) CALLOC(maxitems, sizeof(bucket *)); |
pitem = (bucket **) CALLOC(maxitems, sizeof(bucket *)); |
if (pitem == 0) no_space(); |
if (pitem == NULL) no_space(); |
|
|
nrules = 3; |
nrules = 3; |
maxrules = 100; |
maxrules = 100; |
plhs = (bucket **) MALLOC(maxrules*sizeof(bucket *)); |
plhs = (bucket **) MALLOC(maxrules*sizeof(bucket *)); |
if (plhs == 0) no_space(); |
if (plhs == NULL) no_space(); |
plhs[0] = 0; |
plhs[0] = 0; |
plhs[1] = 0; |
plhs[1] = 0; |
plhs[2] = 0; |
plhs[2] = 0; |
rprec = (short *) MALLOC(maxrules*sizeof(short)); |
rprec = (short *) MALLOC(maxrules*sizeof(short)); |
if (rprec == 0) no_space(); |
if (rprec == NULL) no_space(); |
rprec[0] = 0; |
rprec[0] = 0; |
rprec[1] = 0; |
rprec[1] = 0; |
rprec[2] = 0; |
rprec[2] = 0; |
rassoc = (char *) MALLOC(maxrules*sizeof(char)); |
rassoc = (char *) MALLOC(maxrules*sizeof(char)); |
if (rassoc == 0) no_space(); |
if (rassoc == NULL) no_space(); |
rassoc[0] = TOKEN; |
rassoc[0] = TOKEN; |
rassoc[1] = TOKEN; |
rassoc[1] = TOKEN; |
rassoc[2] = TOKEN; |
rassoc[2] = TOKEN; |
|
|
int olditems = maxitems; |
int olditems = maxitems; |
maxitems += 300; |
maxitems += 300; |
pitem = (bucket **) REALLOC(pitem, maxitems*sizeof(bucket *)); |
pitem = (bucket **) REALLOC(pitem, maxitems*sizeof(bucket *)); |
if (pitem == 0) no_space(); |
if (pitem == NULL) no_space(); |
memset(pitem + olditems, 0, (maxitems - olditems)*sizeof(bucket *)); |
memset(pitem + olditems, 0, (maxitems - olditems)*sizeof(bucket *)); |
} |
} |
|
|
|
|
{ |
{ |
maxrules += 100; |
maxrules += 100; |
plhs = (bucket **) REALLOC(plhs, maxrules*sizeof(bucket *)); |
plhs = (bucket **) REALLOC(plhs, maxrules*sizeof(bucket *)); |
if (plhs == 0) no_space(); |
if (plhs == NULL) no_space(); |
rprec = (short *) REALLOC(rprec, maxrules*sizeof(short)); |
rprec = (short *) REALLOC(rprec, maxrules*sizeof(short)); |
if (rprec == 0) no_space(); |
if (rprec == NULL) no_space(); |
rassoc = (char *) REALLOC(rassoc, maxrules*sizeof(char)); |
rassoc = (char *) REALLOC(rassoc, maxrules*sizeof(char)); |
if (rassoc == 0) no_space(); |
if (rassoc == NULL) no_space(); |
} |
} |
|
|
|
|
|
|
if (!isalpha(c) && c != '_' && c != '.' && c != '_') |
if (!isalpha(c) && c != '_' && c != '.' && c != '_') |
syntax_error(lineno, line, cptr); |
syntax_error(lineno, line, cptr); |
bp = get_name(); |
bp = get_name(); |
if (goal == 0) |
if (goal == NULL) |
{ |
{ |
if (bp->class == TERM) |
if (bp->class == TERM) |
terminal_start(bp->name); |
terminal_start(bp->name); |
|
|
if (ntags) |
if (ntags) |
{ |
{ |
tag = plhs[nrules]->tag; |
tag = plhs[nrules]->tag; |
if (tag == 0) untyped_lhs(); |
if (tag == NULL) untyped_lhs(); |
fprintf(f, "yyval.%s", tag); |
fprintf(f, "yyval.%s", tag); |
} |
} |
else |
else |
|
|
if (i <= 0 || i > n) |
if (i <= 0 || i > n) |
unknown_rhs(i); |
unknown_rhs(i); |
tag = pitem[nitems + i - n - 1]->tag; |
tag = pitem[nitems + i - n - 1]->tag; |
if (tag == 0) untyped_rhs(i, pitem[nitems + i - n - 1]->name); |
if (tag == NULL) untyped_rhs(i, pitem[nitems + i - n - 1]->name); |
fprintf(f, "yyvsp[%d].%s", i - n, tag); |
fprintf(f, "yyvsp[%d].%s", i - n, tag); |
} |
} |
else |
else |
|
|
if (c == '\n') |
if (c == '\n') |
{ |
{ |
get_line(); |
get_line(); |
if (line == 0) |
if (line == NULL) |
unterminated_string(s_lineno, s_line, s_cptr); |
unterminated_string(s_lineno, s_line, s_cptr); |
} |
} |
} |
} |
|
|
if (c == '\n') |
if (c == '\n') |
{ |
{ |
get_line(); |
get_line(); |
if (line == 0) |
if (line == NULL) |
unterminated_comment(c_lineno, c_line, c_cptr); |
unterminated_comment(c_lineno, c_line, c_cptr); |
} |
} |
} |
} |
|
|
{ |
{ |
int i; |
int i; |
|
|
if (tag_table == 0) return; |
if (tag_table == NULL) return; |
|
|
for (i = 0; i < ntags; ++i) |
for (i = 0; i < ntags; ++i) |
{ |
{ |
|
|
for (bp = first_symbol; bp; bp = bp->next) |
for (bp = first_symbol; bp; bp = bp->next) |
name_pool_size += strlen(bp->name) + 1; |
name_pool_size += strlen(bp->name) + 1; |
name_pool = MALLOC(name_pool_size); |
name_pool = MALLOC(name_pool_size); |
if (name_pool == 0) no_space(); |
if (name_pool == NULL) no_space(); |
|
|
strlcpy(name_pool, "$accept", name_pool_size); |
strlcpy(name_pool, "$accept", name_pool_size); |
strlcpy(name_pool+8, "$end", name_pool_size - 8); |
strlcpy(name_pool+8, "$end", name_pool_size - 8); |
|
|
nvars = nsyms - ntokens; |
nvars = nsyms - ntokens; |
|
|
symbol_name = (char **) MALLOC(nsyms*sizeof(char *)); |
symbol_name = (char **) MALLOC(nsyms*sizeof(char *)); |
if (symbol_name == 0) no_space(); |
if (symbol_name == NULL) no_space(); |
symbol_value = (short *) MALLOC(nsyms*sizeof(short)); |
symbol_value = (short *) MALLOC(nsyms*sizeof(short)); |
if (symbol_value == 0) no_space(); |
if (symbol_value == NULL) no_space(); |
symbol_prec = (short *) MALLOC(nsyms*sizeof(short)); |
symbol_prec = (short *) MALLOC(nsyms*sizeof(short)); |
if (symbol_prec == 0) no_space(); |
if (symbol_prec == NULL) no_space(); |
symbol_assoc = MALLOC(nsyms); |
symbol_assoc = MALLOC(nsyms); |
if (symbol_assoc == 0) no_space(); |
if (symbol_assoc == NULL) no_space(); |
|
|
v = (bucket **) MALLOC(nsyms*sizeof(bucket *)); |
v = (bucket **) MALLOC(nsyms*sizeof(bucket *)); |
if (v == 0) no_space(); |
if (v == NULL) no_space(); |
|
|
v[0] = 0; |
v[0] = 0; |
v[start_symbol] = 0; |
v[start_symbol] = 0; |
|
|
int assoc, prec; |
int assoc, prec; |
|
|
ritem = (short *) MALLOC(nitems*sizeof(short)); |
ritem = (short *) MALLOC(nitems*sizeof(short)); |
if (ritem == 0) no_space(); |
if (ritem == NULL) no_space(); |
rlhs = (short *) MALLOC(nrules*sizeof(short)); |
rlhs = (short *) MALLOC(nrules*sizeof(short)); |
if (rlhs == 0) no_space(); |
if (rlhs == NULL) no_space(); |
rrhs = (short *) MALLOC((nrules+1)*sizeof(short)); |
rrhs = (short *) MALLOC((nrules+1)*sizeof(short)); |
if (rrhs == 0) no_space(); |
if (rrhs == NULL) no_space(); |
rprec = (short *) REALLOC(rprec, nrules*sizeof(short)); |
rprec = (short *) REALLOC(rprec, nrules*sizeof(short)); |
if (rprec == 0) no_space(); |
if (rprec == NULL) no_space(); |
rassoc = REALLOC(rassoc, nrules); |
rassoc = REALLOC(rassoc, nrules); |
if (rassoc == 0) no_space(); |
if (rassoc == NULL) no_space(); |
|
|
ritem[0] = -1; |
ritem[0] = -1; |
ritem[1] = goal->index; |
ritem[1] = goal->index; |