26 |
#include "quote.h" |
#include "quote.h" |
27 |
#include "getargs.h" |
#include "getargs.h" |
28 |
#include "files.h" |
#include "files.h" |
|
#include "xalloc.h" |
|
29 |
#include "symtab.h" |
#include "symtab.h" |
30 |
#include "options.h" |
#include "options.h" |
31 |
#include "lex.h" |
#include "lex.h" |
430 |
if (!no_lines_flag) |
if (!no_lines_flag) |
431 |
{ |
{ |
432 |
obstack_fgrow2 (&attrs_obstack, muscle_find ("linef"), |
obstack_fgrow2 (&attrs_obstack, muscle_find ("linef"), |
433 |
lineno, quotearg_style (c_quoting_style, |
lineno, quotearg_style (c_quoting_style, |
434 |
muscle_find("filename"))); |
muscle_find("filename"))); |
435 |
} |
} |
436 |
#endif |
#endif |
490 |
static void |
static void |
491 |
parse_token_decl (symbol_class what_is, symbol_class what_is_not) |
parse_token_decl (symbol_class what_is, symbol_class what_is_not) |
492 |
{ |
{ |
493 |
token_t token = 0; |
token_t token = tok_undef; |
494 |
char *typename = 0; |
char *typename = NULL; |
495 |
|
|
496 |
/* The symbol being defined. */ |
/* The symbol being defined. */ |
497 |
struct bucket *symbol = NULL; |
struct bucket *symbol = NULL; |
540 |
/* symbol and symval combined are only one symbol */ |
/* symbol and symval combined are only one symbol */ |
541 |
nsyms--; |
nsyms--; |
542 |
} |
} |
|
translations = 1; |
|
543 |
symbol = NULL; |
symbol = NULL; |
544 |
} |
} |
545 |
else if (token == tok_identifier) |
else if (token == tok_identifier) |
564 |
else if (symbol && token == tok_number) |
else if (symbol && token == tok_number) |
565 |
{ |
{ |
566 |
symbol->user_token_number = numval; |
symbol->user_token_number = numval; |
|
translations = 1; |
|
567 |
} |
} |
568 |
else |
else |
569 |
{ |
{ |
705 |
if (prev == tok_identifier) |
if (prev == tok_identifier) |
706 |
{ |
{ |
707 |
symval->user_token_number = numval; |
symval->user_token_number = numval; |
|
translations = 1; |
|
708 |
} |
} |
709 |
else |
else |
710 |
{ |
{ |
750 |
|
|
751 |
if (no_lines_flag) |
if (no_lines_flag) |
752 |
obstack_1grow (&attrs_obstack, '\n'); |
obstack_1grow (&attrs_obstack, '\n'); |
753 |
|
|
754 |
obstack_init (&union_obstack); |
obstack_init (&union_obstack); |
755 |
obstack_sgrow (&union_obstack, "union"); |
obstack_sgrow (&union_obstack, "union"); |
756 |
if (defines_flag) |
if (defines_flag) |
760 |
|
|
761 |
while (c != EOF) |
while (c != EOF) |
762 |
{ |
{ |
763 |
obstack_1grow (&union_obstack, c); |
/* If C contains '/', it is output by copy_comment (). */ |
764 |
if (defines_flag) |
if (c != '/') |
765 |
obstack_1grow (&defines_obstack, c); |
{ |
766 |
|
obstack_1grow (&attrs_obstack, c); |
767 |
|
if (defines_flag) |
768 |
|
obstack_1grow (&defines_obstack, c); |
769 |
|
} |
770 |
|
|
771 |
switch (c) |
switch (c) |
772 |
{ |
{ |
852 |
char *typename = 0; |
char *typename = 0; |
853 |
int usrtoknum; |
int usrtoknum; |
854 |
|
|
|
translations = 1; |
|
855 |
token = lex (); /* fetch typename or first token */ |
token = lex (); /* fetch typename or first token */ |
856 |
if (token == tok_typename) |
if (token == tok_typename) |
857 |
{ |
{ |
903 |
nsyms--; |
nsyms--; |
904 |
} |
} |
905 |
|
|
|
/* FIXME. */ |
|
|
|
|
906 |
static void |
static void |
907 |
parse_muscle_decl (void) |
parse_muscle_decl (void) |
908 |
{ |
{ |
920 |
copy_identifier (finput, &muscle_obstack); |
copy_identifier (finput, &muscle_obstack); |
921 |
obstack_1grow (&muscle_obstack, 0); |
obstack_1grow (&muscle_obstack, 0); |
922 |
muscle_key = obstack_finish (&muscle_obstack); |
muscle_key = obstack_finish (&muscle_obstack); |
923 |
|
|
924 |
/* Read value. */ |
/* Read value. */ |
925 |
ch = skip_white_space (); |
ch = skip_white_space (); |
926 |
if (ch != '"') |
if (ch != '"') |
954 |
/* Complete with parse_dquoted_param () on the CVS branch 1.29. */ |
/* Complete with parse_dquoted_param () on the CVS branch 1.29. */ |
955 |
} |
} |
956 |
|
|
|
/*------------------------------------------. |
|
|
| Parse what comes after %header_extension. | |
|
|
`------------------------------------------*/ |
|
|
|
|
|
static void |
|
|
parse_header_extension_decl (void) |
|
|
{ |
|
|
char buff[32]; |
|
|
|
|
|
if (header_extension) |
|
|
complain (_("multiple %%header_extension declarations")); |
|
|
fscanf (finput, "%s", buff); |
|
|
header_extension = xstrdup (buff); |
|
|
} |
|
|
|
|
|
/*------------------------------------------. |
|
|
| Parse what comes after %source_extension. | |
|
|
`------------------------------------------*/ |
|
|
|
|
|
static void |
|
|
parse_source_extension_decl (void) |
|
|
{ |
|
|
char buff[32]; |
|
|
|
|
|
if (src_extension) |
|
|
complain (_("multiple %%source_extension declarations")); |
|
|
fscanf (finput, "%s", buff); |
|
|
src_extension = xstrdup (buff); |
|
|
} |
|
|
|
|
957 |
/*----------------------------------------------------------------. |
/*----------------------------------------------------------------. |
958 |
| Read from finput until `%%' is seen. Discard the `%%'. Handle | |
| Read from finput until `%%' is seen. Discard the `%%'. Handle | |
959 |
| any `%' declarations, and copy the contents of any `%{ ... %}' | |
| any `%' declarations, and copy the contents of any `%{ ... %}' | |
1023 |
parse_assoc_decl (non_assoc); |
parse_assoc_decl (non_assoc); |
1024 |
break; |
break; |
1025 |
|
|
|
case tok_hdrext: |
|
|
parse_header_extension_decl (); |
|
|
break; |
|
|
|
|
|
case tok_srcext: |
|
|
parse_source_extension_decl (); |
|
|
break; |
|
|
|
|
1026 |
case tok_define: |
case tok_define: |
1027 |
parse_muscle_decl (); |
parse_muscle_decl (); |
1028 |
break; |
break; |
1029 |
|
|
1030 |
case tok_skel: |
case tok_skel: |
1031 |
parse_skel_decl (); |
parse_skel_decl (); |
1032 |
break; |
break; |
1074 |
if (!no_lines_flag) |
if (!no_lines_flag) |
1075 |
{ |
{ |
1076 |
obstack_fgrow2 (&action_obstack, muscle_find ("linef"), |
obstack_fgrow2 (&action_obstack, muscle_find ("linef"), |
1077 |
lineno, quotearg_style (c_quoting_style, |
lineno, quotearg_style (c_quoting_style, |
1078 |
muscle_find ("filename"))); |
muscle_find ("filename"))); |
1079 |
} |
} |
1080 |
obstack_1grow (&action_obstack, '{'); |
obstack_1grow (&action_obstack, '{'); |
1637 |
{ |
{ |
1638 |
char c; |
char c; |
1639 |
struct obstack el_obstack; |
struct obstack el_obstack; |
1640 |
|
|
1641 |
obstack_init (&el_obstack); |
obstack_init (&el_obstack); |
1642 |
|
|
1643 |
while ((c = getc (finput)) != EOF) |
while ((c = getc (finput)) != EOF) |
1644 |
obstack_1grow (&el_obstack, c); |
obstack_1grow (&el_obstack, c); |
1645 |
|
|
1646 |
obstack_1grow (&el_obstack, 0); |
obstack_1grow (&el_obstack, 0); |
1647 |
muscle_insert ("epilogue", obstack_finish (&el_obstack)); |
muscle_insert ("epilogue", obstack_finish (&el_obstack)); |
1648 |
} |
} |
1688 |
continue; |
continue; |
1689 |
|
|
1690 |
obstack_fgrow2 (oout, "# define\t%s\t%d\n", |
obstack_fgrow2 (oout, "# define\t%s\t%d\n", |
1691 |
symbol, |
symbol, bp->user_token_number); |
|
(translations ? bp->user_token_number : bp->value)); |
|
1692 |
if (semantic_parser) |
if (semantic_parser) |
1693 |
|
/* FIXME: This is certainly dead wrong, and should be just as |
1694 |
|
above. --akim. */ |
1695 |
obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value); |
obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value); |
1696 |
} |
} |
1697 |
} |
} |
1706 |
static void |
static void |
1707 |
packsymbols (void) |
packsymbols (void) |
1708 |
{ |
{ |
1709 |
bucket *bp; |
bucket *bp = NULL; |
1710 |
int tokno = 1; |
int tokno = 1; |
1711 |
int i; |
int i, j; |
1712 |
int last_user_token_number; |
int last_user_token_number; |
1713 |
static char DOLLAR[] = "$"; |
static char DOLLAR[] = "$"; |
1714 |
|
|
1772 |
|
|
1773 |
if (bp->class == token_sym) |
if (bp->class == token_sym) |
1774 |
{ |
{ |
1775 |
if (translations && !(bp->user_token_number)) |
if (!bp->user_token_number) |
1776 |
bp->user_token_number = ++last_user_token_number; |
bp->user_token_number = ++last_user_token_number; |
1777 |
if (bp->user_token_number > max_user_token_number) |
if (bp->user_token_number > max_user_token_number) |
1778 |
max_user_token_number = bp->user_token_number; |
max_user_token_number = bp->user_token_number; |
1782 |
user_toknums[bp->value] = bp->user_token_number; |
user_toknums[bp->value] = bp->user_token_number; |
1783 |
sprec[bp->value] = bp->prec; |
sprec[bp->value] = bp->prec; |
1784 |
sassoc[bp->value] = bp->assoc; |
sassoc[bp->value] = bp->assoc; |
|
|
|
1785 |
} |
} |
1786 |
|
|
1787 |
if (translations) |
token_translations = XCALLOC (short, max_user_token_number + 1); |
|
{ |
|
|
int j; |
|
1788 |
|
|
1789 |
token_translations = XCALLOC (short, max_user_token_number + 1); |
/* initialize all entries for literal tokens to 2, the internal |
1790 |
|
token number for $undefined., which represents all invalid |
1791 |
|
inputs. */ |
1792 |
|
for (j = 0; j <= max_user_token_number; j++) |
1793 |
|
token_translations[j] = 2; |
1794 |
|
|
1795 |
/* initialize all entries for literal tokens to 2, the internal |
for (bp = firstsymbol; bp; bp = bp->next) |
1796 |
token number for $undefined., which represents all invalid |
{ |
1797 |
inputs. */ |
if (bp->value >= ntokens) |
1798 |
for (j = 0; j <= max_user_token_number; j++) |
continue; /* non-terminal */ |
1799 |
token_translations[j] = 2; |
if (bp->user_token_number == SALIAS) |
1800 |
|
continue; |
1801 |
for (bp = firstsymbol; bp; bp = bp->next) |
if (token_translations[bp->user_token_number] != 2) |
1802 |
{ |
complain (_("tokens %s and %s both assigned number %d"), |
1803 |
if (bp->value >= ntokens) |
tags[token_translations[bp->user_token_number]], |
1804 |
continue; /* non-terminal */ |
bp->tag, bp->user_token_number); |
1805 |
if (bp->user_token_number == SALIAS) |
token_translations[bp->user_token_number] = bp->value; |
|
continue; |
|
|
if (token_translations[bp->user_token_number] != 2) |
|
|
complain (_("tokens %s and %s both assigned number %d"), |
|
|
tags[token_translations[bp->user_token_number]], |
|
|
bp->tag, bp->user_token_number); |
|
|
token_translations[bp->user_token_number] = bp->value; |
|
|
} |
|
1806 |
} |
} |
1807 |
|
|
1808 |
error_token_number = errtoken->value; |
error_token_number = errtoken->value; |
1809 |
|
|
1810 |
output_token_defines (&output_obstack); |
{ |
1811 |
obstack_1grow (&output_obstack, 0); |
struct obstack tokendefs; |
1812 |
muscle_insert ("tokendef", obstack_finish (&output_obstack)); |
obstack_init (&tokendefs); |
1813 |
|
output_token_defines (&tokendefs); |
1814 |
|
obstack_1grow (&tokendefs, 0); |
1815 |
|
muscle_insert ("tokendef", xstrdup (obstack_finish (&tokendefs))); |
1816 |
|
obstack_free (&tokendefs, NULL); |
1817 |
|
} |
1818 |
|
|
1819 |
#if 0 |
#if 0 |
1820 |
if (!no_parser_flag) |
if (!no_parser_flag) |
1939 |
start_flag = 0; |
start_flag = 0; |
1940 |
startval = NULL; /* start symbol not specified yet. */ |
startval = NULL; /* start symbol not specified yet. */ |
1941 |
|
|
|
#if 0 |
|
|
/* initially assume token number translation not needed. */ |
|
|
translations = 0; |
|
|
#endif |
|
|
/* Nowadays translations is always set to 1, since we give `error' a |
|
|
user-token-number to satisfy the Posix demand for YYERRCODE==256. |
|
|
*/ |
|
|
translations = 1; |
|
|
|
|
1942 |
nsyms = 1; |
nsyms = 1; |
1943 |
nvars = 0; |
nvars = 0; |
1944 |
nrules = 0; |
nrules = 0; |
1954 |
|
|
1955 |
grammar = NULL; |
grammar = NULL; |
1956 |
|
|
1957 |
init_lex (); |
lex_init (); |
1958 |
lineno = 1; |
lineno = 1; |
1959 |
|
|
1960 |
/* Initialize the muscle obstack. */ |
/* Initialize the muscle obstack. */ |
1993 |
packsymbols (); |
packsymbols (); |
1994 |
/* Convert the grammar into the format described in gram.h. */ |
/* Convert the grammar into the format described in gram.h. */ |
1995 |
packgram (); |
packgram (); |
|
/* Free the symbol table data structure since symbols are now all |
|
|
referred to by symbol number. */ |
|
|
free_symtab (); |
|
1996 |
} |
} |