From efab18a07350335ff365d4505534e16c2fc1109d Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Tue, 29 Jul 2014 14:59:08 +0300 Subject: [PATCH] Disallow to use yacc/byacc instead of bison to build parser. Currently parser fails to build with yacc/byacc. A slightly modified parser, build by byacc, causes 3 tests to fail. --- re2c/Makefile.am | 19 +++--- re2c/bootstrap/parser.cc | 125 ++------------------------------------- re2c/bootstrap/y.tab.h | 4 -- re2c/configure.ac | 2 +- re2c/parser.tab.h | 23 ------- re2c/parser.y | 1 - 6 files changed, 16 insertions(+), 158 deletions(-) delete mode 100644 re2c/parser.tab.h diff --git a/re2c/Makefile.am b/re2c/Makefile.am index 26ea27de..a7b4ae36 100755 --- a/re2c/Makefile.am +++ b/re2c/Makefile.am @@ -15,7 +15,7 @@ BUILT_SOURCES = parser.cc scanner.cc #CXXFLAGS = -ggdb -fno-inline -O2 -Wall -Wextra -pedantic -Wconversion -Wpointer-arith -Wwrite-strings -Wredundant-decls -Werror -Wunused-function -DPEDANTIC #CXXFLAGS += -O2 CXXFLAGS += -W -Wall -Wextra -pedantic -Wredundant-decls -DPEDANTIC -YFLAGS = -d +YFLAGS = -y -d --no-lines RE2C = re2c$(EXEEXT) RE2CFLAGS = -bi @@ -70,15 +70,14 @@ zip: $(bin_PROGRAMS) $(EXTRA_ZIP) release: dist zip src-rpm parser.cc: $(top_srcdir)/parser.y - $(YACC) $(YFLAGS) $(top_srcdir)/parser.y || exit - cat y.tab.c | sed -e 's/"y\.tab\.c"/"parser.cc"/g' -e 's/"\.\/parser\.y"/"parser.y"/g' > $(top_srcdir)/parser.cc - rm -f y.tab.c - mv -f y.tab.h y.tab.c - cat y.tab.c | sed -e 's/"\.\/parser\.y"/"parser.y"/g' > y.tab.h - rm -f y.tab.c - if cmp -s $(top_srcdir)/parser.cc $(top_srcdir)/bootstrap/parser.cc; then :; else cp -f $(top_srcdir)/parser.cc $(top_srcdir)/bootstrap/parser.cc; fi - if cmp -s y.tab.h $(top_srcdir)/y.tab.h; then :; else mv -f y.tab.h $(top_srcdir)/y.tab.h; fi - if cmp -s $(top_srcdir)/y.tab.h $(top_srcdir)/bootstrap/y.tab.h; then :; else cp -f $(top_srcdir)/y.tab.h $(top_srcdir)/bootstrap/y.tab.h; fi + @if test $(BISON) = "yes"; then \ + bison $(YFLAGS) --output=$(top_srcdir)/parser.cc --defines=$(top_srcdir)/y.tab.h $(top_srcdir)/parser.y && \ + cp -f $(top_srcdir)/parser.cc $(top_srcdir)/bootstrap/parser.cc; \ + cp -f $(top_srcdir)/y.tab.h $(top_srcdir)/bootstrap/y.tab.h; \ + else \ + cp -f $(top_srcdir)/bootstrap/parser.cc $(top_srcdir)/parser.cc; \ + cp -f $(top_srcdir)/bootstrap/y.tab.h $(top_srcdir)/y.tab.h; \ + fi scanner.cc: $(top_srcdir)/scanner.re @if test -x ./re2c$(EXEEXT); then \ diff --git a/re2c/bootstrap/parser.cc b/re2c/bootstrap/parser.cc index f2f2a8b1..051e3ae8 100644 --- a/re2c/bootstrap/parser.cc +++ b/re2c/bootstrap/parser.cc @@ -66,8 +66,6 @@ /* Copy the first part of user declarations. */ -/* Line 189 of yacc.c */ -#line 1 "parser.y" /* $Id$ */ @@ -96,7 +94,6 @@ using namespace re2c; extern "C" { int yylex(); -int yyparse(); void yyerror(const char*); } @@ -223,8 +220,6 @@ void default_rule(CondList *clist, Token *code) -/* Line 189 of yacc.c */ -#line 228 "parser.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -288,8 +283,6 @@ void default_rule(CondList *clist, Token *code) typedef union YYSTYPE { -/* Line 214 of yacc.c */ -#line 158 "parser.y" re2c::Symbol *symbol; re2c::RegExp *regexp; @@ -302,8 +295,6 @@ typedef union YYSTYPE -/* Line 214 of yacc.c */ -#line 307 "parser.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -314,8 +305,6 @@ typedef union YYSTYPE /* Copy the second part of user declarations. */ -/* Line 264 of yacc.c */ -#line 319 "parser.cc" #ifdef short # undef short @@ -622,12 +611,12 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 187, 187, 189, 193, 197, 206, 215, 219, 223, - 229, 237, 246, 255, 259, 264, 269, 275, 279, 287, - 295, 300, 306, 312, 324, 336, 342, 350, 353, 360, - 365, 374, 377, 385, 388, 395, 399, 406, 410, 421, - 425, 432, 436, 451, 458, 462, 466, 470, 477, 485, - 489, 493 + 0, 186, 186, 188, 192, 196, 205, 214, 218, 222, + 228, 236, 245, 254, 258, 263, 268, 274, 278, 286, + 294, 299, 305, 311, 323, 335, 341, 349, 352, 359, + 364, 373, 376, 384, 387, 394, 398, 405, 409, 420, + 424, 431, 435, 450, 457, 461, 465, 469, 476, 484, + 488, 492 }; #endif @@ -1595,16 +1584,12 @@ yyreduce: { case 2: -/* Line 1464 of yacc.c */ -#line 187 "parser.y" { } break; case 3: -/* Line 1464 of yacc.c */ -#line 190 "parser.y" { foundRules = true; } @@ -1612,8 +1597,6 @@ yyreduce: case 5: -/* Line 1464 of yacc.c */ -#line 198 "parser.y" { if ((yyvsp[(1) - (4)].symbol)->re) { @@ -1626,8 +1609,6 @@ yyreduce: case 6: -/* Line 1464 of yacc.c */ -#line 207 "parser.y" { if ((yyvsp[(1) - (2)].symbol)->re) { @@ -1640,8 +1621,6 @@ yyreduce: case 7: -/* Line 1464 of yacc.c */ -#line 216 "parser.y" { in->fatal("trailing contexts are not allowed in named definitions"); } @@ -1649,8 +1628,6 @@ yyreduce: case 8: -/* Line 1464 of yacc.c */ -#line 220 "parser.y" { in->fatal("trailing contexts are not allowed in named definitions"); } @@ -1658,8 +1635,6 @@ yyreduce: case 9: -/* Line 1464 of yacc.c */ -#line 224 "parser.y" { in->config(*(yyvsp[(1) - (4)].str), *(yyvsp[(3) - (4)].str)); delete (yyvsp[(1) - (4)].str); @@ -1669,8 +1644,6 @@ yyreduce: case 10: -/* Line 1464 of yacc.c */ -#line 230 "parser.y" { in->config(*(yyvsp[(1) - (4)].str), (yyvsp[(3) - (4)].number)); delete (yyvsp[(1) - (4)].str); @@ -1679,8 +1652,6 @@ yyreduce: case 11: -/* Line 1464 of yacc.c */ -#line 238 "parser.y" { if (cFlag) { @@ -1693,8 +1664,6 @@ yyreduce: case 12: -/* Line 1464 of yacc.c */ -#line 247 "parser.y" { if (cFlag) in->fatal("condition or '<*>' required when using -c switch"); @@ -1707,8 +1676,6 @@ yyreduce: case 13: -/* Line 1464 of yacc.c */ -#line 256 "parser.y" { context_rule((yyvsp[(2) - (7)].clist), (yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), (yyvsp[(6) - (7)].str), (yyvsp[(7) - (7)].token)); } @@ -1716,8 +1683,6 @@ yyreduce: case 14: -/* Line 1464 of yacc.c */ -#line 260 "parser.y" { assert((yyvsp[(7) - (7)].str)); context_rule((yyvsp[(2) - (7)].clist), (yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), (yyvsp[(7) - (7)].str), NULL); @@ -1726,8 +1691,6 @@ yyreduce: case 15: -/* Line 1464 of yacc.c */ -#line 265 "parser.y" { context_none((yyvsp[(2) - (6)].clist)); delete (yyvsp[(5) - (6)].str); @@ -1736,8 +1699,6 @@ yyreduce: case 16: -/* Line 1464 of yacc.c */ -#line 270 "parser.y" { assert((yyvsp[(6) - (6)].str)); context_none((yyvsp[(2) - (6)].clist)); @@ -1747,8 +1708,6 @@ yyreduce: case 17: -/* Line 1464 of yacc.c */ -#line 276 "parser.y" { default_rule((yyvsp[(2) - (5)].clist), (yyvsp[(5) - (5)].token)); } @@ -1756,8 +1715,6 @@ yyreduce: case 18: -/* Line 1464 of yacc.c */ -#line 280 "parser.y" { context_check(NULL); Token *token = new Token((yyvsp[(7) - (7)].token), (yyvsp[(7) - (7)].token)->source, (yyvsp[(7) - (7)].token)->line, (yyvsp[(6) - (7)].str)); @@ -1769,8 +1726,6 @@ yyreduce: case 19: -/* Line 1464 of yacc.c */ -#line 288 "parser.y" { assert((yyvsp[(7) - (7)].str)); context_check(NULL); @@ -1782,8 +1737,6 @@ yyreduce: case 20: -/* Line 1464 of yacc.c */ -#line 296 "parser.y" { context_none(NULL); delete (yyvsp[(5) - (6)].str); @@ -1792,8 +1745,6 @@ yyreduce: case 21: -/* Line 1464 of yacc.c */ -#line 301 "parser.y" { assert((yyvsp[(6) - (6)].str)); context_none(NULL); @@ -1803,8 +1754,6 @@ yyreduce: case 22: -/* Line 1464 of yacc.c */ -#line 307 "parser.y" { CondList *clist = new CondList(); clist->insert("*"); @@ -1814,8 +1763,6 @@ yyreduce: case 23: -/* Line 1464 of yacc.c */ -#line 313 "parser.y" { context_check(NULL); if (specNone) @@ -1831,8 +1778,6 @@ yyreduce: case 24: -/* Line 1464 of yacc.c */ -#line 325 "parser.y" { assert((yyvsp[(3) - (3)].str)); context_check(NULL); @@ -1848,8 +1793,6 @@ yyreduce: case 25: -/* Line 1464 of yacc.c */ -#line 337 "parser.y" { CondList *clist = new CondList(); clist->insert("*"); @@ -1859,8 +1802,6 @@ yyreduce: case 26: -/* Line 1464 of yacc.c */ -#line 343 "parser.y" { setup_rule((yyvsp[(2) - (4)].clist), (yyvsp[(4) - (4)].token)); } @@ -1868,8 +1809,6 @@ yyreduce: case 27: -/* Line 1464 of yacc.c */ -#line 350 "parser.y" { in->fatal("unnamed condition not supported"); } @@ -1877,8 +1816,6 @@ yyreduce: case 28: -/* Line 1464 of yacc.c */ -#line 354 "parser.y" { (yyval.clist) = (yyvsp[(1) - (1)].clist); } @@ -1886,8 +1823,6 @@ yyreduce: case 29: -/* Line 1464 of yacc.c */ -#line 361 "parser.y" { (yyval.clist) = new CondList(); (yyval.clist)->insert((yyvsp[(1) - (1)].symbol)->GetName().to_string()); @@ -1896,8 +1831,6 @@ yyreduce: case 30: -/* Line 1464 of yacc.c */ -#line 366 "parser.y" { (yyvsp[(1) - (3)].clist)->insert((yyvsp[(3) - (3)].symbol)->GetName().to_string()); (yyval.clist) = (yyvsp[(1) - (3)].clist); @@ -1906,8 +1839,6 @@ yyreduce: case 31: -/* Line 1464 of yacc.c */ -#line 374 "parser.y" { (yyval.str) = NULL; } @@ -1915,8 +1846,6 @@ yyreduce: case 32: -/* Line 1464 of yacc.c */ -#line 378 "parser.y" { (yyval.str) = new Str((yyvsp[(3) - (3)].symbol)->GetName().to_string().c_str()); } @@ -1924,8 +1853,6 @@ yyreduce: case 33: -/* Line 1464 of yacc.c */ -#line 385 "parser.y" { (yyval.regexp) = new NullOp; } @@ -1933,8 +1860,6 @@ yyreduce: case 34: -/* Line 1464 of yacc.c */ -#line 389 "parser.y" { (yyval.regexp) = (yyvsp[(2) - (2)].regexp); } @@ -1942,8 +1867,6 @@ yyreduce: case 35: -/* Line 1464 of yacc.c */ -#line 396 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } @@ -1951,8 +1874,6 @@ yyreduce: case 36: -/* Line 1464 of yacc.c */ -#line 400 "parser.y" { (yyval.regexp) = mkAlt((yyvsp[(1) - (3)].regexp), (yyvsp[(3) - (3)].regexp)); } @@ -1960,8 +1881,6 @@ yyreduce: case 37: -/* Line 1464 of yacc.c */ -#line 407 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } @@ -1969,8 +1888,6 @@ yyreduce: case 38: -/* Line 1464 of yacc.c */ -#line 411 "parser.y" { (yyval.regexp) = mkDiff((yyvsp[(1) - (3)].regexp), (yyvsp[(3) - (3)].regexp)); if(!(yyval.regexp)) @@ -1982,8 +1899,6 @@ yyreduce: case 39: -/* Line 1464 of yacc.c */ -#line 422 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } @@ -1991,8 +1906,6 @@ yyreduce: case 40: -/* Line 1464 of yacc.c */ -#line 426 "parser.y" { (yyval.regexp) = new CatOp((yyvsp[(1) - (2)].regexp), (yyvsp[(2) - (2)].regexp)); } @@ -2000,8 +1913,6 @@ yyreduce: case 41: -/* Line 1464 of yacc.c */ -#line 433 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } @@ -2009,8 +1920,6 @@ yyreduce: case 42: -/* Line 1464 of yacc.c */ -#line 437 "parser.y" { switch((yyvsp[(2) - (2)].op)) { @@ -2029,8 +1938,6 @@ yyreduce: case 43: -/* Line 1464 of yacc.c */ -#line 452 "parser.y" { (yyval.regexp) = new CloseVOp((yyvsp[(1) - (2)].regexp), (yyvsp[(2) - (2)].extop).minsize, (yyvsp[(2) - (2)].extop).maxsize); } @@ -2038,8 +1945,6 @@ yyreduce: case 44: -/* Line 1464 of yacc.c */ -#line 459 "parser.y" { (yyval.op) = (yyvsp[(1) - (1)].op); } @@ -2047,8 +1952,6 @@ yyreduce: case 45: -/* Line 1464 of yacc.c */ -#line 463 "parser.y" { (yyval.op) = (yyvsp[(1) - (1)].op); } @@ -2056,8 +1959,6 @@ yyreduce: case 46: -/* Line 1464 of yacc.c */ -#line 467 "parser.y" { (yyval.op) = ((yyvsp[(1) - (2)].op) == (yyvsp[(2) - (2)].op)) ? (yyvsp[(1) - (2)].op) : '*'; } @@ -2065,8 +1966,6 @@ yyreduce: case 47: -/* Line 1464 of yacc.c */ -#line 471 "parser.y" { (yyval.op) = ((yyvsp[(1) - (2)].op) == (yyvsp[(2) - (2)].op)) ? (yyvsp[(1) - (2)].op) : '*'; } @@ -2074,8 +1973,6 @@ yyreduce: case 48: -/* Line 1464 of yacc.c */ -#line 478 "parser.y" { if(!(yyvsp[(1) - (1)].symbol)->re) { @@ -2087,8 +1984,6 @@ yyreduce: case 49: -/* Line 1464 of yacc.c */ -#line 486 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } @@ -2096,8 +1991,6 @@ yyreduce: case 50: -/* Line 1464 of yacc.c */ -#line 490 "parser.y" { (yyval.regexp) = (yyvsp[(1) - (1)].regexp); } @@ -2105,8 +1998,6 @@ yyreduce: case 51: -/* Line 1464 of yacc.c */ -#line 494 "parser.y" { (yyval.regexp) = (yyvsp[(2) - (3)].regexp); } @@ -2114,8 +2005,6 @@ yyreduce: -/* Line 1464 of yacc.c */ -#line 2119 "parser.cc" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -2326,8 +2215,6 @@ yyreturn: -/* Line 1684 of yacc.c */ -#line 499 "parser.y" extern "C" { diff --git a/re2c/bootstrap/y.tab.h b/re2c/bootstrap/y.tab.h index 7ba6d578..840ecfb9 100644 --- a/re2c/bootstrap/y.tab.h +++ b/re2c/bootstrap/y.tab.h @@ -75,8 +75,6 @@ typedef union YYSTYPE { -/* Line 1685 of yacc.c */ -#line 158 "parser.y" re2c::Symbol *symbol; re2c::RegExp *regexp; @@ -89,8 +87,6 @@ typedef union YYSTYPE -/* Line 1685 of yacc.c */ -#line 94 "y.tab.h" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ diff --git a/re2c/configure.ac b/re2c/configure.ac index fbee4c35..9cac446c 100644 --- a/re2c/configure.ac +++ b/re2c/configure.ac @@ -12,7 +12,7 @@ AC_SUBST(PACKAGE_RELEASE, ${PACKAGE_RELEASE:-1}) AC_SUBST(WINBUILDDIR, Release-2005) # Checks for programs. -AC_PROG_YACC +AC_CHECK_PROG(BISON, bison, yes, no) AC_PROG_CXX AC_PROG_CC AC_PROG_INSTALL diff --git a/re2c/parser.tab.h b/re2c/parser.tab.h deleted file mode 100644 index 1932bb74..00000000 --- a/re2c/parser.tab.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef BISON_PARSER_TAB_H -# define BISON_PARSER_TAB_H - -#ifndef YYSTYPE -typedef union { - re2c::Symbol *symbol; - re2c::RegExp *regexp; - re2c::Token *token; - char op; -} yystype; -# define YYSTYPE yystype -# define YYSTYPE_IS_TRIVIAL 1 -#endif -# define CLOSE 257 -# define ID 258 -# define CODE 259 -# define RANGE 260 -# define STRING 261 - - -extern YYSTYPE yylval; - -#endif /* not BISON_PARSER_TAB_H */ diff --git a/re2c/parser.y b/re2c/parser.y index 2c3d14a9..f0e7375e 100644 --- a/re2c/parser.y +++ b/re2c/parser.y @@ -26,7 +26,6 @@ using namespace re2c; extern "C" { int yylex(); -int yyparse(); void yyerror(const char*); } -- 2.40.0