From: Akim Demaille Date: Tue, 5 Feb 2002 10:08:59 +0000 (+0000) Subject: Give a try to M4 as a back end. X-Git-Tag: BISON-1_49a~172 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/be2a1a68efe93f7046f77b81346e4c740c14fb40?ds=sidebyside Give a try to M4 as a back end. * lib/readpipe.c: New, from wdiff. * src/Makefile.am (DEFS): Define PKGDATADIR, not BISON_SIMPLE and BISON_HAIRY. * src/system.h (BISON_HAIRY, BISON_SIMPLE): Remove the DOS and VMS specific values. Now it is m4 that performs the lookup. * src/parse-skel.y: Remove. * src/muscle_tab.c, src/muscle_tab.h (muscles_m4_output): New. * src/output.c (actions_output, guards_output) (token_definitions_output): No longer keeps track of the output line number, hence remove the second argument. (guards_output): Check against the guard member of a rule, not the action member. Adjust callers. (output_skeleton): Don't look for the skeleton location, let m4 do that. Create `/tmp/muscles.m4'. This is temporary, a proper temporary file will be used. Invoke `m4' on m4sugar.m4, muscles.m4, and the skeleton. (prepare): Given that for the time being changesyntax is not usable in M4, rename the muscles using `-' to `_'. Define `defines_flag', `output_parser_name' and `output_header_name'. * src/output.h (actions_output, guards_output) (token_definitions_output): Adjust prototypes. * src/scan-skel.l: Instead of scanning the skeletons, it now processes the output of m4: `__oline__' and `#output'. * data/bison.simple: Adjust to be used by M4(sugar). * tests/Makefile.am: Use check_SCRIPTS to make sure `bison' is up to date. * tests/bison.in: Use the secrete envvar `BISON_PKGDATADIR' instead of the dead `BISON_SIMPLE' and `BISON_HAIRY'. * data/m4sugar/m4sugar.m4, data/m4sugar/version.m4: New, shamelessly stolen from CVS Autoconf. --- diff --git a/ChangeLog b/ChangeLog index b7bebd13..943f43b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,41 @@ +2002-02-05 Akim Demaille + + Give a try to M4 as a back end. + + * lib/readpipe.c: New, from wdiff. + * src/Makefile.am (DEFS): Define PKGDATADIR, not BISON_SIMPLE and + BISON_HAIRY. + * src/system.h (BISON_HAIRY, BISON_SIMPLE): Remove the DOS and VMS + specific values. Now it is m4 that performs the lookup. + * src/parse-skel.y: Remove. + * src/muscle_tab.c, src/muscle_tab.h (muscles_m4_output): New. + * src/output.c (actions_output, guards_output) + (token_definitions_output): No longer keeps track of the output + line number, hence remove the second argument. + (guards_output): Check against the guard member of a rule, not the + action member. + Adjust callers. + (output_skeleton): Don't look for the skeleton location, let m4 do + that. + Create `/tmp/muscles.m4'. This is temporary, a proper temporary + file will be used. + Invoke `m4' on m4sugar.m4, muscles.m4, and the skeleton. + (prepare): Given that for the time being changesyntax is not + usable in M4, rename the muscles using `-' to `_'. + Define `defines_flag', `output_parser_name' and `output_header_name'. + * src/output.h (actions_output, guards_output) + (token_definitions_output): Adjust prototypes. + * src/scan-skel.l: Instead of scanning the skeletons, it now + processes the output of m4: `__oline__' and `#output'. + * data/bison.simple: Adjust to be used by M4(sugar). + * tests/Makefile.am: Use check_SCRIPTS to make sure `bison' is up + to date. + * tests/bison.in: Use the secrete envvar `BISON_PKGDATADIR' + instead of the dead `BISON_SIMPLE' and `BISON_HAIRY'. + * data/m4sugar/m4sugar.m4, data/m4sugar/version.m4: New, + shamelessly stolen from CVS Autoconf. + + 2002-02-05 Akim Demaille * lib/hash.c, lib/hash.h: Replace with Fileutils 4.1's version. diff --git a/data/Makefile.am b/data/Makefile.am index bbc86b4c..641bba38 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -16,3 +16,6 @@ ## 02111-1307 USA dist_pkgdata_DATA = bison.simple bison.hairy bison.c++ + +m4sugardir = $(pkgdatadir)/m4sugar +dist_m4sugar_DATA = m4sugar/m4sugar.m4 m4sugar/version.m4 diff --git a/data/bison.simple b/data/bison.simple index f4af302c..80cf81ae 100644 --- a/data/bison.simple +++ b/data/bison.simple @@ -1,11 +1,36 @@ -%%{section} %%{output-prefix} %%{output-infix} %%".c" -/* -*- C -*- */ +m4_divert(-1) -/* A Bison parser, made from %%{filename} - by GNU bison %%{version}. */ +# m4_define_default(MACRO, VALUE) +# ------------------------------- +# Define MACRO to VALUE, unless already defined. +m4_define([m4_define_default], +[m4_ifdef([$1], [], [m4_define($@)])]) -/* Skeleton output parser for bison, +m4_define_default([b4_input_suffix], [.y]) +m4_define_default([b4_output_parser_suffix], +[m4_translit(b4_input_suffix, [yY], [cC])]) + +m4_define_default([b4_output_parser_name], +[b4_output_prefix[]b4_output_infix[]b4_output_parser_suffix[]]) + + +m4_define_default([b4_output_header_suffix], +[m4_translit(b4_input_suffix, [yY], [hH])]) + +m4_define_default([b4_output_header_name], +[b4_output_prefix[]b4_output_infix[]b4_output_header_suffix[]]) + +m4_define_default([b4_header_guard], + [m4_bpatsubst(m4_toupper([BISON_]b4_output_header_name), + [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])]) + +m4_divert(0)dnl +#output "b4_output_parser_name" +/* A Bison parser, made from b4_filename + by GNU bison b4_version. */ + +/* Skeleton output parser for Bison, Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. @@ -38,31 +63,32 @@ #define YYBISON 1 /* Pure parsers. */ -#define YYPURE %%{pure} +#define YYPURE b4_pure /* Using locations. */ -#define YYLSP_NEEDED %%{locations-flag} +#define YYLSP_NEEDED b4_locations_flag -/* If NAME_PREFIX is specified substitute the variables and functions +m4_if(b4_prefix[], [yy], [], +[/* If NAME_PREFIX is specified substitute the variables and functions names. */ -#define yyparse %%{prefix}parse -#define yylex %%{prefix}lex -#define yyerror %%{prefix}error -#define yylval %%{prefix}lval -#define yychar %%{prefix}char -#define yydebug %%{prefix}debug -#define yynerrs %%{prefix}nerrs +#define yyparse b4_prefix[]parse +#define yylex b4_prefix[]lex +#define yyerror b4_prefix[]error +#define yylval b4_prefix[]lval +#define yychar b4_prefix[]char +#define yydebug b4_prefix[]debug +#define yynerrs b4_prefix[]nerrs #if YYLSP_NEEDED -# define yylloc %%{prefix}lloc +# define yylloc b4_prefix[]lloc #endif - +]) /* Copy the user declarations. */ -%%{prologue} +b4_prologue /* Enabling traces. */ #ifndef YYDEBUG -# define YYDEBUG %%{debug} +# define YYDEBUG b4_debug #endif /* Enabling verbose error messages. */ @@ -70,11 +96,11 @@ # undef YYERROR_VERBOSE # define YYERROR_VERBOSE 1 #else -# define YYERROR_VERBOSE %%{error-verbose} +# define YYERROR_VERBOSE b4_error_verbose #endif #ifndef YYSTYPE -typedef %%{stype} yystype; +typedef b4_stype yystype; # define YYSTYPE yystype #endif @@ -86,11 +112,11 @@ typedef struct yyltype int last_line; int last_column; } yyltype; -# define YYLTYPE %%{ltype} +# define YYLTYPE b4_ltype #endif -/* Line %%{skeleton-line} of %%{skeleton}. */ -#line %%{line} "%%{parser-file-name}" +/* Line __line__ of __file__. */ +#line __oline__ "b4_output_parser_name" /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local @@ -185,118 +211,118 @@ union yyalloc #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ /* Tokens. */ -%%{tokendef} +b4_tokendef /* YYFINAL -- State number of the termination state. */ -#define YYFINAL %%{final} -#define YYFLAG %%{flag} -#define YYLAST %%{last} +#define YYFINAL b4_final +#define YYFLAG b4_flag +#define YYLAST b4_last /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS %%{ntokens} +#define YYNTOKENS b4_ntokens /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS %%{nnts} +#define YYNNTS b4_nnts /* YYNRULES -- Number of rules. */ -#define YYNRULES %%{nrules} +#define YYNRULES b4_nrules /* YYNRULES -- Number of states. */ -#define YYNSTATES %%{nstates} -#define YYMAXUTOK %%{maxtok} +#define YYNSTATES b4_nstates +#define YYMAXUTOK b4_maxtok /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ -#define YYTRANSLATE(x) ((unsigned)(x) <= %%{maxtok} ? yytranslate[x] : %%{nsym}) +#define YYTRANSLATE(x) ((unsigned)(x) <= b4_maxtok ? yytranslate[[x]] : b4_nsym) -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ -static const char yytranslate[] = +/* YYTRANSLATE[[YYLEX]] -- Bison symbol number corresponding to YYLEX. */ +static const char yytranslate[[]] = { - %%{translate} + b4_translate }; #if YYDEBUG -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in +/* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in YYRHS. */ -static const short yyprhs[] = +static const short yyprhs[[]] = { - %%{prhs} + b4_prhs }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const short yyrhs[] = +static const short yyrhs[[]] = { - %%{rhs} + b4_rhs }; -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ -static const short yyrline[] = +/* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */ +static const short yyrline[[]] = { - %%{rline} + b4_rline }; #endif #if (YYDEBUG) || YYERROR_VERBOSE -/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. +/* YYTNME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = +static const char *const yytname[[]] = { - %%{tname} + b4_tname }; #endif -/* YYTOKNUM[YYN] -- Index in YYTNAME corresponding to YYLEX. */ -static const short yytoknum[] = +/* YYTOKNUM[[YYN]] -- Index in YYTNAME corresponding to YYLEX. */ +static const short yytoknum[[]] = { - %%{toknum} + b4_toknum }; -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const short yyr1[] = +/* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */ +static const short yyr1[[]] = { - %%{r1} + b4_r1 }; -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const short yyr2[] = +/* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */ +static const short yyr2[[]] = { - %%{r2} + b4_r2 }; -/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE +/* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ -static const short yydefact[] = +static const short yydefact[[]] = { - %%{defact} + b4_defact }; -/* YYPGOTO[NTERM-NUM]. */ -static const short yydefgoto[] = +/* YYPGOTO[[NTERM-NUM]]. */ +static const short yydefgoto[[]] = { - %%{defgoto} + b4_defgoto }; -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing +/* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing STATE-NUM. */ -static const short yypact[] = +static const short yypact[[]] = { - %%{pact} + b4_pact }; -/* YYPGOTO[NTERM-NUM]. */ -static const short yypgoto[] = +/* YYPGOTO[[NTERM-NUM]]. */ +static const short yypgoto[[]] = { - %%{pgoto} + b4_pgoto }; -/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If +/* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which number is the opposite. If zero, do what YYDEFACT says. */ -static const short yytable[] = +static const short yytable[[]] = { - %%{table} + b4_table }; -static const short yycheck[] = +static const short yycheck[[]] = { - %%{check} + b4_check }; @@ -367,8 +393,8 @@ while (0) #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.last_line = Rhs[N].last_line; \ - Current.last_column = Rhs[N].last_column; + Current.last_line = Rhs[[N]].last_line; \ + Current.last_column = Rhs[[N]].last_column; #endif /* YYLEX -- calling `yylex' with the right arguments. */ @@ -408,10 +434,8 @@ do { \ if (yydebug) \ YYFPRINTF Args; \ } while (0) -/* Nonzero means print parse trace. [The following comment makes no - sense to me. Could someone clarify it? --akim] Since this is - uninitialized, it does not stop multiple parsers from coexisting. - */ +/* Nonzero means print parse trace. Since this is uninitialized, it + does not stop multiple parsers from coexisting. */ int yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) @@ -419,7 +443,7 @@ int yydebug; /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH -# define YYINITDEPTH %%{initdepth} +# define YYINITDEPTH b4_initdepth #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only @@ -434,7 +458,7 @@ int yydebug; #endif #ifndef YYMAXDEPTH -# define YYMAXDEPTH %%{maxdepth} +# define YYMAXDEPTH b4_maxdepth #endif @@ -582,7 +606,7 @@ YY_DECL_VARIABLES int yyparse (YYPARSE_PARAM_ARG) YYPARSE_PARAM_DECL -{ +{[ /* If reentrant, generate the variables here. */ #if YYPURE YY_DECL_VARIABLES @@ -902,14 +926,14 @@ yyreduce: } #endif switch (yyn) - { - %%{actions} + ]{ + b4_actions } -/* Line %%{skeleton-line} of %%{skeleton}. */ -#line %%{line} "%%{parser-file-name}" +/* Line __line__ of __file__. */ +#line __oline__ "b4_output_parser_name" - yyvsp -= yylen; +[ yyvsp -= yylen; yyssp -= yylen; #if YYLSP_NEEDED yylsp -= yylen; @@ -1136,6 +1160,39 @@ yyreturn: YYSTACK_FREE (yyss); #endif return yyresult; -} +]} + +b4_epilogue +m4_if(b4_defines_flag, 0, [], +[#output "b4_output_header_name" +#ifndef b4_header_guard +# define b4_header_guard + +b4_tokendef + +#ifndef YYSTYPE +typedef b4_stype +yystype; +# define YYSTYPE yystype +#endif + +m4_if(b4_pure, [0], +[extern YYSTYPE b4_prefix[]lval;]) + +m4_if(b4_locations_flag, [0], [], +[#ifndef YYLTYPE +typedef struct yyltype +{ + int first_line; + int first_column; + int last_line; + int last_column; +} yyltype; +# define YYLTYPE yyltype +#endif -%%{epilogue} +m4_if(b4_pure, [0], +[extern YYLTYPE b4_prefix[]lloc;]) +]) +#endif /* not b4_header_guard */ +]) diff --git a/lib/Makefile.am b/lib/Makefile.am index 321094b4..be318511 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,4 @@ -## Copyright 2001, 2002 Free Software Foundation, Inc. +## Copyright (C) 2001, 2002 Free Software Foundation, Inc. ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -39,7 +39,8 @@ libbison_a_SOURCES = \ getopt.h getopt.c getopt1.c \ hash.h hash.c \ quote.h quote.c quotearg.h quotearg.c \ - xalloc.h xmalloc.c xstrdup.c xstrndup.c + xalloc.h xmalloc.c xstrdup.c xstrndup.c \ + readpipe.c libbison_a_LIBADD = @LIBOBJS@ @ALLOCA@ libbison_a_DEPENDENCIES = $(libbison_a_LIBADD) diff --git a/src/Makefile.am b/src/Makefile.am index b258e543..03b3b53b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## Copyright 2001 Free Software Foundation, Inc. +## Copyright (C) 2001, 2002 Free Software Foundation, Inc. ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -18,8 +18,7 @@ AUTOMAKE_OPTIONS = ../lib/ansi2knr DEFS = @DEFS@ \ - -DBISON_SIMPLE=\"$(pkgdatadir)/bison.simple\" \ - -DBISON_HAIRY=\"$(pkgdatadir)/bison.hairy\" \ + -DPKGDATADIR=\"$(pkgdatadir)\" \ -DLOCALEDIR=\"$(datadir)/locale\" CFLAGS = @CFLAGS@ $(WARNING_CFLAGS) $(WERROR_CFLAGS) @@ -45,9 +44,9 @@ bison_SOURCES = LR0.c closure.c complain.c conflicts.c \ muscle_tab.h muscle_tab.c \ options.h options.c \ print.c reader.c reduce.c symtab.c warshall.c vcg.c \ - skeleton.h parse-skel.h parse-skel.y scan-skel.l + scan-skel.l -BUILT_SOURCES = parse-skel.c scan-skel.c +BUILT_SOURCES = scan-skel.c EXTRA_bison_SOURCES = vmsgetargs.c diff --git a/src/muscle_tab.c b/src/muscle_tab.c index 380a0471..30eb442c 100644 --- a/src/muscle_tab.c +++ b/src/muscle_tab.c @@ -92,3 +92,26 @@ muscle_find (const char *key) muscle_entry_t *result = hash_lookup (muscle_table, &pair); return result ? result->value : NULL; } + + +/* Output the definition of all the current muscles into a list of + m4_defines. */ + +static void +muscle_m4_output (muscle_entry_t *entry, FILE *out) +{ + fprintf (out, "m4_define([b4_%s],\n", entry->key); + fprintf (out, " [[%s]])\n\n\n", entry->value); +} + + +/* Output the definition of all the current muscles into a list of + m4_defines. */ + +void +muscles_m4_output (FILE *out) +{ + hash_do_for_each (muscle_table, + (Hash_processor) muscle_m4_output, + out); +} diff --git a/src/muscle_tab.h b/src/muscle_tab.h index da35bbd6..80f09f19 100644 --- a/src/muscle_tab.h +++ b/src/muscle_tab.h @@ -1,5 +1,5 @@ /* Definitions for macrotab.c and callers, part of bison, - Copyright 2001 Free Software Foundation, Inc. + Copyright (C) 2001, 2002 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -55,4 +55,7 @@ const char *muscle_find PARAMS ((const char *key)); muscle_insert (Key, obstack_finish (&muscle_obstack)); \ } + +void muscles_m4_output PARAMS ((FILE *out)); + #endif /* not MUSCLE_TAB_H_ */ diff --git a/src/output.c b/src/output.c index 4cb42e1b..702f0cb1 100644 --- a/src/output.c +++ b/src/output.c @@ -90,6 +90,7 @@ #include "system.h" #include "quotearg.h" +#include "error.h" #include "getargs.h" #include "files.h" #include "gram.h" @@ -101,7 +102,13 @@ #include "symtab.h" #include "conflicts.h" #include "muscle_tab.h" -#include "skeleton.h" + +/* From lib/readpipe.h. */ +FILE *readpipe PARAMS ((const char *, ...)); + +/* From src/scan-skel.l. */ +int skel_lex PARAMS ((void)); +extern FILE *skel_in; static int nvectors; static int nentries; @@ -504,7 +511,7 @@ token_actions (void) `-----------------------------*/ void -actions_output (FILE *out, size_t *line) +actions_output (FILE *out) { int rule; for (rule = 1; rule < nrules + 1; ++rule) @@ -523,14 +530,6 @@ actions_output (FILE *out, size_t *line) fprintf (out, "{ %s%s }\n break;\n\n", rules[rule].action, yacc_flag ? ";" : ""); - - /* We always output 4 '\n' per action. */ - *line += 4; - /* Plus one if !no_lines_flag. */ - if (!no_lines_flag) - ++*line; - /* Get the number of lines written by the user. */ - *line += get_lines_number (rules[rule].action); } } @@ -540,11 +539,11 @@ actions_output (FILE *out, size_t *line) `----------------------------*/ void -guards_output (FILE *out, size_t *line) +guards_output (FILE *out) { int rule; for (rule = 1; rule < nrules + 1; ++rule) - if (rules[rule].action) + if (rules[rule].guard) { fprintf (out, " case %d:\n", rule); @@ -555,14 +554,6 @@ guards_output (FILE *out, size_t *line) muscle_find ("filename"))); fprintf (out, "{ %s; }\n break;\n\n", rules[rule].guard); - - /* We always output 4 '\n' per action. */ - *line += 4; - /* Plus one if !no_lines_flag. */ - if (!no_lines_flag) - ++*line; - /* Get the number of lines written by the user. */ - *line += get_lines_number (rules[rule].guard); } } @@ -572,7 +563,7 @@ guards_output (FILE *out, size_t *line) `---------------------------------------*/ void -token_definitions_output (FILE *out, size_t *line) +token_definitions_output (FILE *out) { int i; for (i = 0; i < ntokens; ++i) @@ -603,14 +594,10 @@ token_definitions_output (FILE *out, size_t *line) fprintf (out, "# define %s\t%d\n", symbol->tag, number); - ++*line; if (semantic_parser) - { - /* FIXME: This is probably wrong, and should be just as - above. --akim. */ - fprintf (out, "# define T%s\t%d\n", symbol->tag, symbol->value); - ++*line; - } + /* FIXME: This is probably wrong, and should be just as + above. --akim. */ + fprintf (out, "# define T%s\t%d\n", symbol->tag, symbol->value); } } @@ -972,14 +959,57 @@ output_skeleton (void) if (!skeleton) { if (semantic_parser) - skeleton = skeleton_find ("BISON_HAIRY", BISON_HAIRY); + skeleton = "bison.hairy"; else - skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE); + skeleton = "bison.simple"; } /* Parse the skeleton file and output the needed parsers. */ muscle_insert ("skeleton", skeleton); - process_skeleton (skeleton); + + /* Store the definition of all the muscles. */ + { + FILE *muscles_m4 = xfopen ("/tmp/muscles.m4", "w"); + /* There are no comments, especially not `#': we do want M4 expansion + after `#': think of CPP macros! */ + fprintf (muscles_m4, "m4_changecom()\n"); + fprintf (muscles_m4, "m4_init()\n"); + + fprintf (muscles_m4, "m4_define([b4_actions], \n[["); + actions_output (muscles_m4); + fprintf (muscles_m4, "]])\n\n"); + + fprintf (muscles_m4, "m4_define([b4_guards], \n[["); + guards_output (muscles_m4); + fprintf (muscles_m4, "]])\n\n"); + + fprintf (muscles_m4, "m4_define([b4_tokendef], \n[["); + token_definitions_output (muscles_m4); + fprintf (muscles_m4, "]])\n\n"); + + muscles_m4_output (muscles_m4); + + fprintf (muscles_m4, "m4_wrap([m4_divert_pop(0)])\n"); + fprintf (muscles_m4, "m4_divert_push(0)dnl\n"); + xfclose (muscles_m4); + } + + /* Invoke m4 on the definition of the muscles, and the skeleton. */ + { + const char *bison_pkgdatadir = getenv ("BISON_PKGDATADIR"); + if (!bison_pkgdatadir) + bison_pkgdatadir = PKGDATADIR; + skel_in = readpipe ("m4", + "-I", + bison_pkgdatadir, + "m4sugar/m4sugar.m4", + "/tmp/muscles.m4", + skeleton, + NULL); + if (!skel_in) + error (EXIT_FAILURE, errno, "cannot run m4"); + skel_lex (); + } } static void @@ -992,20 +1022,23 @@ prepare (void) MUSCLE_INSERT_INT ("debug", debug_flag); MUSCLE_INSERT_INT ("final", final_state); MUSCLE_INSERT_INT ("maxtok", max_user_token_number); - MUSCLE_INSERT_INT ("error-verbose", error_verbose); + MUSCLE_INSERT_INT ("error_verbose", error_verbose); MUSCLE_INSERT_STRING ("prefix", spec_name_prefix ? spec_name_prefix : "yy"); /* FIXME: This is wrong: the muscles should decide whether they hold a copy or not, but the situation is too obscure currently. */ - MUSCLE_INSERT_STRING ("output-infix", output_infix ? output_infix : ""); - MUSCLE_INSERT_STRING ("output-prefix", short_base_name); + MUSCLE_INSERT_STRING ("output_infix", output_infix ? output_infix : ""); + MUSCLE_INSERT_STRING ("output_prefix", short_base_name); + MUSCLE_INSERT_STRING ("output_parser_name", parser_file_name); + MUSCLE_INSERT_STRING ("output_header_name", spec_defines_file); MUSCLE_INSERT_INT ("nnts", nvars); MUSCLE_INSERT_INT ("nrules", nrules); MUSCLE_INSERT_INT ("nstates", nstates); MUSCLE_INSERT_INT ("ntokens", ntokens); - MUSCLE_INSERT_INT ("locations-flag", locations_flag); + MUSCLE_INSERT_INT ("locations_flag", locations_flag); + MUSCLE_INSERT_INT ("defines_flag", defines_flag); } /*-------------------------. @@ -1015,14 +1048,13 @@ prepare (void) static void header_output (void) { - size_t dummy_line; FILE *out = xfopen (spec_defines_file, "w"); char *macro_name = compute_header_macro (); fprintf (out, "#ifndef %s\n", macro_name); fprintf (out, "# define %s\n\n", macro_name); - token_definitions_output (out, &dummy_line); + token_definitions_output (out); fprintf (out, "\ #ifndef YYSTYPE\n\ typedef %s @@ -1097,7 +1129,8 @@ output (void) output_skeleton (); /* Output the header if needed. */ - if (defines_flag) + + if (0) header_output (); free (rules + 1); diff --git a/src/output.h b/src/output.h index 4e3799c6..306a63e4 100644 --- a/src/output.h +++ b/src/output.h @@ -28,9 +28,9 @@ void output PARAMS ((void)); size_t get_lines_number PARAMS ((const char *s)); -void actions_output PARAMS ((FILE *out, size_t *line)); -void guards_output PARAMS ((FILE *out, size_t *line)); -void token_definitions_output PARAMS ((FILE *out, size_t *line)); +void actions_output PARAMS ((FILE *out)); +void guards_output PARAMS ((FILE *out)); +void token_definitions_output PARAMS ((FILE *out)); extern struct obstack muscle_obstack; diff --git a/src/scan-skel.l b/src/scan-skel.l index 924f4ab9..82f9ed1a 100644 --- a/src/scan-skel.l +++ b/src/scan-skel.l @@ -1,6 +1,5 @@ - /* -*- C -*- */ -/* Scan Bison Skeletons. - Copyright (C) 2001 Free Software Foundation, Inc. +/* Scan Bison Skeletons. -*- C -*- + Copyright (C) 2001, 2002 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -19,77 +18,26 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -%option debug nodefault noyywrap nounput +%option nodefault noyywrap nounput %option prefix="skel_" outfile="lex.yy.c" -/* If we enable - - %option yylineno - - Then we have warning: `yy_flex_realloc' defined but not used. - Seems like a Flex bug to me: Why the heck yylineno would trigger - the REJECT exception??? */ - %{ #include "system.h" -#include "skeleton.h" -#include "parse-skel.h" -%} - -%{ -/* Each time we match a string, move the end cursor to its end. */ -#define YY_USER_ACTION yylloc->last_column += yyleng; +#include "files.h" +int skel_lex PARAMS ((void)); +static int yylineno = 1; %} %% -%{ - /* At each yylex invocation, mark the current position as the - start of the next token. */ - LOCATION_STEP (*yylloc); -%} - -"%%{line}" { return LINE; } -"%%{skeleton-line}" { return SLINE; } - -"%%{section}" { return SECTION; } - -"%%{guards}" { return GUARDS; } -"%%{actions}" { return ACTIONS; } -"%%{tokendef}" { return TOKENS; } - - /* Muscle. */ -"%%{"[a-zA-Z][0-9a-zA-Z_-]+"}" { - yylval->string = xstrndup (yytext + 3, yyleng - 4); - return MUSCLE; -} - - /* String. */ -"%%\"".*"\"" { - yylval->string = xstrndup (yytext + 3, yyleng - 4); - return STRING; -} - - /* End of line. */ -"\n" { - LOCATION_LINES (*yylloc, yyleng); - return '\n'; -} - - /* White spaces. */ -[\t ]+ { - yylval->string = yytext; - return BLANKS; -} - - /* Plain Characters. */ -[^%\n]+ { - yylval->string = yytext; - return RAW; -} - - /* Plain Character. */ -. { - yylval->character = *yytext; - return CHARACTER; -} + /* This is an approximation, but we don't need more. */ +^"#output \""[^\"]+\"\n { + yytext[yyleng - 2] = '\0'; + skel_out = xfopen (yytext + strlen ("#output \""), "w"); + yylineno = 1; + } + +"__oline__" fprintf (yyout, "%d", yylineno); +[^_\n]+ ECHO; +\n+ yylineno += yyleng; ECHO; +. ECHO; %% diff --git a/src/system.h b/src/system.h index b66f70aa..392f4eec 100644 --- a/src/system.h +++ b/src/system.h @@ -273,25 +273,6 @@ do { \ # endif /* ! MSDOS */ #endif /* ! VMS */ -#if defined (VMS) & !defined (__VMS_POSIX) -# ifndef BISON_SIMPLE -# define BISON_SIMPLE "GNU_BISON:[000000]BISON.SIMPLE" -# endif -# ifndef BISON_HAIRY -# define BISON_HARIRY "GNU_BISON:[000000]BISON.HAIRY" -# endif -#endif - -#if defined (_MSC_VER) -# ifndef BISON_SIMPLE -# define BISON_SIMPLE "c:/usr/local/lib/bison.simple" -# endif -# ifndef BISON_HAIRY -# define BISON_HAIRY "c:/usr/local/lib/bison.hairy" -# endif -#endif - - /* As memcpy, but for shorts. */ #define shortcpy(Dest, Src, Num) \ memcpy (Dest, Src, Num * sizeof (short)) diff --git a/tests/Makefile.am b/tests/Makefile.am index 77866a6d..4d0584b1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -20,7 +20,7 @@ EXTRA_DIST = $(TESTSUITE_AT) testsuite -DISTCLEANFILES = atconfig bison +DISTCLEANFILES = atconfig $(check_SCRIPTS) MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE) ## ------------ ## @@ -66,6 +66,8 @@ clean-local: check-local: atconfig atlocal $(TESTSUITE) $(SHELL) $(TESTSUITE) +check_SCRIPTS = bison + # Run the test suite on the *installed* tree. installcheck-local: $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin diff --git a/tests/bison.in b/tests/bison.in index 6bce1d73..6a582f77 100644 --- a/tests/bison.in +++ b/tests/bison.in @@ -1,11 +1,8 @@ -#! /bin/sh +#! @SHELL@ # @configure_input@ # Wrapper around a non installed bison to make it work as an installed one. # We want to use the files shipped with Bison. -BISON_SIMPLE='@abs_top_srcdir@/data/bison.simple' -export BISON_SIMPLE -BISON_HAIRY='@abs_top_srcdir@/data/bison.hairy' -export BISON_HAIRY - +BISON_PKGDATADIR='@abs_top_srcdir@/data' +export BISON_PKGDATADIR exec '@abs_top_builddir@/src/bison' ${1+"$@"}