pid_t pid;
/* Compute the names of the package data dir and skeleton files. */
- char const m4sugar[] = "m4sugar/m4sugar.m4";
- char const m4bison[] = "bison.m4";
- char *full_m4sugar;
- char *full_m4bison;
- char *full_skeleton;
- char const *p;
- char const *m4 = (p = getenv ("M4")) ? p : M4;
- char const *pkgdatadir = compute_pkgdatadir ();
- size_t skeleton_size = strlen (skeleton) + 1;
- size_t pkgdatadirlen = strlen (pkgdatadir);
- while (pkgdatadirlen && pkgdatadir[pkgdatadirlen - 1] == '/')
- pkgdatadirlen--;
- full_skeleton = xmalloc (pkgdatadirlen + 1
- + (skeleton_size < sizeof m4sugar
- ? sizeof m4sugar : skeleton_size));
- memcpy (full_skeleton, pkgdatadir, pkgdatadirlen);
- full_skeleton[pkgdatadirlen] = '/';
- strcpy (full_skeleton + pkgdatadirlen + 1, m4sugar);
- full_m4sugar = xstrdup (full_skeleton);
- strcpy (full_skeleton + pkgdatadirlen + 1, m4bison);
- full_m4bison = xstrdup (full_skeleton);
- if (mbschr (skeleton, '/'))
- strcpy (full_skeleton, skeleton);
- else
- strcpy (full_skeleton + pkgdatadirlen + 1, skeleton);
+ char const *m4 = (m4 = getenv ("M4")) ? m4 : M4;
+ char const *datadir = pkgdatadir ();
+ char *m4sugar = xconcatenated_filename (datadir, "m4sugar/m4sugar.m4", NULL);
+ char *m4bison = xconcatenated_filename (datadir, "bison.m4", NULL);
+ char *skel = (IS_PATH_WITH_DIR (skeleton)
- ? xstrdup (skeleton)
- : xconcatenated_filename (datadir, skeleton, NULL));
++ ? xstrdup (skeleton)
++ : xconcatenated_filename (datadir, skeleton, NULL));
/* Test whether m4sugar.m4 is readable, to check for proper
installation. A faulty installation can cause deadlock, so a
[m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])])
m4_pushdef([AT_NAME_PREFIX],
[m4_bmatch([$3], [%name-prefix ".*"],
- [m4_bregexp([$3], [name-prefix "\([^""]*\)"], [\1])],
+ [m4_bregexp([$3], [%name-prefix "\([^""]*\)"], [\1])],
[yy])])
m4_pushdef([AT_API_PREFIX],
- [m4_bmatch([$3], [%define api\.prefix ".*"],
- [m4_bregexp([$3], [%define api\.prefix "\([^""]*\)"], [\1])],
+ [m4_bmatch([$3], [\(%define api\.prefix\|%name-prefix\) ".*"],
+ [m4_bregexp([$3], [\(%define api\.prefix\|%name-prefix\) "\([^""]*\)"], [\2])],
[yy])])
+m4_pushdef([AT_TOKEN_PREFIX],
+[m4_bmatch([$3], [%define api.tokens.prefix ".*"],
+ [m4_bregexp([$3], [%define api.tokens.prefix "\(.*\)"], [\1])])])
# yyerror receives the location if %location & %pure & (%glr or %parse-param).
m4_pushdef([AT_YYERROR_ARG_LOC_IF],
[AT_GLR_OR_PARAM_IF([AT_PURE_AND_LOC_IF([$1], [$2])],
AT_PURE_LEX_IF(
[m4_pushdef([AT_LOC], [(*llocp)])
m4_pushdef([AT_VAL], [(*lvalp)])
- m4_pushdef([AT_LEX_FORMALS],
+ m4_pushdef([AT_YYLEX_FORMALS],
- [YYSTYPE *lvalp[]AT_LOCATION_IF([, YYLTYPE *llocp])])
+ [YYSTYPE *lvalp[]AT_LOCATION_IF([, YYLTYPE *llocp])])
- m4_pushdef([AT_LEX_ARGS],
+ m4_pushdef([AT_YYLEX_ARGS],
- [lvalp[]AT_LOCATION_IF([, llocp])])
+ [lvalp[]AT_LOCATION_IF([, llocp])])
m4_pushdef([AT_USE_LEX_ARGS],
- [(void) lvalp;AT_LOCATION_IF([(void) llocp])])
+ [(void) lvalp;AT_LOCATION_IF([(void) llocp])])
- m4_pushdef([AT_LEX_PRE_FORMALS],
- [AT_LEX_FORMALS, ])
- m4_pushdef([AT_LEX_PRE_ARGS],
- [AT_LEX_ARGS, ])
+ m4_pushdef([AT_YYLEX_PRE_FORMALS],
+ [AT_YYLEX_FORMALS, ])
+ m4_pushdef([AT_YYLEX_PRE_ARGS],
+ [AT_YYLEX_ARGS, ])
],
[m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]])
m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]])
])
m4_define([AT_YYERROR_DEFINE],
- [AT_SKEL_JAVA_IF([[public void yyerror (String msg)
- {
- System.err.println (msg);
- }]], [AT_SKEL_CC_IF([[void
- yy::parser::error (]AT_LOCATION_IF([[const yy::location &, ]])[std::string const &msg)
- {
- std::cerr << msg << std::endl;
- }]], [[#include <stdio.h>
- static void
- ]AT_API_PREFIX[error (char const *msg)
+ [m4_case(AT_LANG,
+ [c], [[#include <stdio.h>
+ /* A C error reporting function. */
+ static
+ ]AT_YYERROR_PROTOTYPE[
{
+ ]AT_YYERROR_SEES_LOC_IF([[
+ fprintf (stderr, "%d.%d",
+ ]AT_LOC_FIRST_LINE[, ]AT_LOC_FIRST_COLUMN[);
+ if (]AT_LOC_FIRST_LINE[ != ]AT_LOC_LAST_LINE[)
+ fprintf (stderr, "-%d.%d",
+ ]AT_LOC_LAST_LINE[, ]AT_LOC_LAST_COLUMN[ - 1);
+ else if (]AT_LOC_FIRST_COLUMN[ != ]AT_LOC_LAST_COLUMN[ - 1)
+ fprintf (stderr, "-%d",
+ ]AT_LOC_LAST_COLUMN[ - 1);
+ fprintf (stderr, ": ");]])[
fprintf (stderr, "%s\n", msg);
-]AT_NAME_PREFIX[::parser::error (const location_type& l, const std::string& m)
-{
- (void) l;
- std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << std::endl;
+ }]],
+ [c++], [[/* A C++ error reporting function. */
+ void
- {
++]AT_NAME_PREFIX[::parser::error (]AT_LOCATION_IF([[const location_type& l, ]])[const std::string& m)
++{ std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << std::endl;
+ }]],
+ [java], [AT_LOCATION_IF([[public void yyerror (Calc.Location l, String s)
- }]])])dnl
++{
+ if (l == null)
+ System.err.println (s);
+ else
+ System.err.println (l + ": " + s);
+ }
+ ]], [[
+ public void yyerror (String s)
+ {
+ System.err.println (s);
+}]])])dnl
])
+
## --------------- ##
## Running Bison. ##
## --------------- ##
# OUTPUT-OTHER.c, OUTPUT-OTHER.cc, or OUTPUT-OTHER.java to OUTPUT or
# OUTPUT.java along with it. Relies on AT_SKEL_CC_IF and
# AT_SKEL_JAVA_IF.
- m4_define([AT_FULL_COMPILE], [
- AT_SKEL_JAVA_IF([
- AT_BISON_CHECK([-o $1.java $1.y])
- AT_JAVA_COMPILE([$1.java],
+ m4_define([AT_FULL_COMPILE],
+ [m4_case(AT_LANG,
+ [java],
+ [AT_BISON_CHECK([-o $1.java $1.y])
+ AT_LANG_COMPILE([$1],
- m4_join([ ],
- [$1.java],
- m4_ifval($2, [[$1-$2.java]]),
+ m4_join([ ],
+ [$1.java],
+ m4_ifval($2, [[$1-$2.java]]),
- m4_ifval($3, [[$1-$3.java]])))
- ], [
- AT_SKEL_CC_IF([
- AT_BISON_CHECK([-o $1.cc $1.y])
- AT_COMPILE_CXX([$1],
+ m4_ifval($3, [[$1-$3.java]])))],
+ [c++],
+ [AT_BISON_CHECK([-o $1.cc $1.y])
+ AT_LANG_COMPILE([$1],
- m4_join([ ],
- [$1.cc],
- m4_ifval($2, [[$1-$2.cc]]),
+ m4_join([ ],
+ [$1.cc],
+ m4_ifval($2, [[$1-$2.cc]]),
- m4_ifval($3, [[$1-$3.cc]])))
- ], [
- AT_BISON_CHECK([-o $1.c $1.y])
- AT_COMPILE([$1],
+ m4_ifval($3, [[$1-$3.cc]])))],
+ [c],
+ [AT_BISON_CHECK([-o $1.c $1.y])
+ AT_LANG_COMPILE([$1],
- m4_join([ ],
- [$1.c],
- m4_ifval($2, [[$1-$2.c]]),
+ m4_join([ ],
+ [$1.c],
+ m4_ifval($2, [[$1-$2.c]]),
- m4_ifval($3, [[$1-$3.c]])))
- ])
- ])
+ m4_ifval($3, [[$1-$3.c]])))])
])