diff --git a/Makefile b/Makefile index 9eb97de..9d24f87 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -devel = 0 +devel = 1 BISON = bison FLEX = flex diff --git a/kk.cpp b/kk.cpp index 0d45025..484b547 100644 --- a/kk.cpp +++ b/kk.cpp @@ -539,6 +539,39 @@ compute_sq2 () sage_show_khsq (outfp, H, sq1, sq2); } + + +unsigned +kh_rk (knot_diagram kd) +{ + cube c (kd); + mod_map d = c.compute_d (1, 0, 0, 0, 0); + + chain_complex_simplifier s (c.khC, d, maybe (1), maybe (0)); + assert (s.new_d == 0); + return s.new_C->free_rank(); +} + +void +run_demo () +{ + printf ("Link \t\t L1 \t L2 \t L \n"); + for (unsigned i = 10; i <= 11; i ++) + { + for (unsigned j = 90; j <= fmin(mt_links (i, 0), 230); j ++) + { + + knot_diagram kd (mt_link (i, 0, j)); + if (kd.num_components () != 2) + continue; + knot_diagram L1 (SUBLINK, smallbitset (2, 1), kd); + knot_diagram L2 (SUBLINK, smallbitset (2, 2), kd); + + printf ("%s \t %d \t %d \t %d \n", kd.name.c_str(), kh_rk(L1), kh_rk(L2), kh_rk(kd)); + } + } +} + int main (int argc, char **argv) { @@ -557,6 +590,11 @@ main (int argc, char **argv) usage (); exit (EXIT_SUCCESS); } + else if (strcmp (argv[i], "-demo") == 0) + { + run_demo(); + exit (EXIT_SUCCESS); + } else if (!strcmp (argv[i], "-v")) verbose = 1; else if (!strcmp (argv[i], "-f")) @@ -626,6 +664,23 @@ main (int argc, char **argv) kd = parse_knot (knot); kd.marked_edge = 1; + if (!strcmp (invariant, "gauss")) + { + basedvector, 1> gc = kd.as_gauss_code (); + for (unsigned i = 1; i <= gc.size (); i ++) + { + if (i > 1) + printf (":"); + for (unsigned j = 1; j <= gc[i].size (); j ++) + { + if (j > 1) + printf (","); + printf ("%d", gc[i][j]); + } + } + newline (); + } + if (!strcmp (invariant, "sq2")) { if (strcmp (field, "Z2")) diff --git a/knot_diagram.cpp b/knot_diagram.cpp index ea6c1b2..b0bdcd9 100644 --- a/knot_diagram.cpp +++ b/knot_diagram.cpp @@ -1040,6 +1040,59 @@ knot_diagram::planar_diagram_crossings () const return r; } +basedvector, 1> +knot_diagram::as_gauss_code () const +{ + set visited; + unsigned m = num_components (); + + basedvector, 1> gc (m); + + unsigned k = 0; // index component + for (unsigned i = 1; i <= num_edges (); i ++) + { + if (visited % i) + continue; + + basedvector comp_gc; + + unsigned p = edge_to_ept (i); + for (unsigned j = i;;) + { + visited.push (j); + + unsigned c = ept_crossing[p]; + + int t = (is_over_ept (p) + ? -c + : c); + comp_gc.append (t); + + p = crossings[c][add_base1_mod4 (ept_index[p], 2)]; + p = edge_other_ept (p); + assert (is_to_ept (p)); + + j = ept_edge (p); + + if (j == i) + break; + } + + ++ k; + gc[k] = comp_gc; + } + assert (visited.card () == num_edges ()); + +#ifndef NDEBUG + unsigned n = 0; + for (unsigned i = 1; i <= m; i ++) + n += gc[i].size (); + assert (n == 2*n_crossings); +#endif + + return gc; +} + hash_t knot_diagram::hash_self () const { diff --git a/knot_diagram.h b/knot_diagram.h index e721233..8cd3808 100644 --- a/knot_diagram.h +++ b/knot_diagram.h @@ -175,6 +175,8 @@ class knot_diagram basedvector, 1> planar_diagram_crossings () const; + basedvector, 1> as_gauss_code () const; + hash_t hash_self () const; void show_ept (unsigned p) const; diff --git a/knot_parser/knot_parser.cc b/knot_parser/knot_parser.cc index 9f0a338..7d383d2 100644 --- a/knot_parser/knot_parser.cc +++ b/knot_parser/knot_parser.cc @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.5. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Skeleton implementation for Bison LALR(1) parsers in C++ @@ -33,7 +33,7 @@ /* First part of user declarations. */ -/* Line 278 of lalr1.cc */ +/* Line 279 of lalr1.cc */ #line 38 "knot_parser/knot_parser.cc" @@ -41,23 +41,23 @@ /* User implementation prologue. */ -/* Line 284 of lalr1.cc */ +/* Line 285 of lalr1.cc */ #line 46 "knot_parser/knot_parser.cc" /* Unqualified %code blocks. */ -/* Line 285 of lalr1.cc */ +/* Line 286 of lalr1.cc */ #line 15 "knot_parser/knot_parser.yy" #define YY_DECL \ yy::knot_parser::token_type knot_yylex (yy::knot_parser::semantic_type *yylval) YY_DECL; -/* Line 285 of lalr1.cc */ +/* Line 286 of lalr1.cc */ #line 30 "knot_parser/knot_parser.yy" #define yylex knot_yylex -/* Line 285 of lalr1.cc */ +/* Line 286 of lalr1.cc */ #line 62 "knot_parser/knot_parser.cc" @@ -136,9 +136,9 @@ do { \ #else /* !YYDEBUG */ # define YYCDEBUG if (false) std::cerr -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_REDUCE_PRINT(Rule) -# define YY_STACK_PRINT() +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) YYUSE(Type) +# define YY_REDUCE_PRINT(Rule) static_cast(0) +# define YY_STACK_PRINT() static_cast(0) #endif /* !YYDEBUG */ @@ -152,7 +152,7 @@ do { \ namespace yy { -/* Line 352 of lalr1.cc */ +/* Line 353 of lalr1.cc */ #line 157 "knot_parser/knot_parser.cc" /// Build a parser object. @@ -212,7 +212,8 @@ namespace yy { YYUSE (yymsg); YYUSE (yyvaluep); - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + if (yymsg) + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); switch (yytype) { @@ -300,6 +301,10 @@ namespace yy { int yyresult; + // FIXME: This shoud be completely indented. It is not yet to + // avoid gratuitous conflicts when merging into the master branch. + try + { YYCDEBUG << "Starting parse" << std::endl; @@ -335,8 +340,8 @@ namespace yy { /* Read a lookahead token. */ if (yychar == yyempty_) { - YYCDEBUG << "Reading a token: "; - yychar = yylex (&yylval); + YYCDEBUG << "Reading a token: "; + yychar = yylex (&yylval); } /* Convert token to internal form. */ @@ -409,15 +414,18 @@ namespace yy { else yyval = yysemantic_stack_[0]; + // Compute the default @$. { slice slice (yylocation_stack_, yylen); YYLLOC_DEFAULT (yyloc, slice, yylen); } + + // Perform the reduction. YY_REDUCE_PRINT (yyn); switch (yyn) { - case 2: -/* Line 661 of lalr1.cc */ + case 2: +/* Line 670 of lalr1.cc */ #line 60 "knot_parser/knot_parser.yy" { parsed_knot = *(yysemantic_stack_[(1) - (1)].kd); @@ -426,7 +434,7 @@ namespace yy { break; case 4: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 69 "knot_parser/knot_parser.yy" { (yyval.kd) = new knot_diagram (DISJOINT_UNION, *(yysemantic_stack_[(2) - (1)].kd), *(yysemantic_stack_[(2) - (2)].kd)); @@ -436,7 +444,7 @@ namespace yy { break; case 13: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 89 "knot_parser/knot_parser.yy" { unsigned n = (yysemantic_stack_[(3) - (1)].integer), @@ -455,7 +463,7 @@ namespace yy { break; case 14: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 107 "knot_parser/knot_parser.yy" { unsigned n = (yysemantic_stack_[(3) - (1)].integer), @@ -475,7 +483,7 @@ namespace yy { break; case 15: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 126 "knot_parser/knot_parser.yy" { unsigned n = (yysemantic_stack_[(4) - (2)].integer), @@ -495,19 +503,19 @@ namespace yy { break; case 16: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 145 "knot_parser/knot_parser.yy" { (yyval.kd) = new knot_diagram (planar_diagram ("", *(yysemantic_stack_[(4) - (3)].int_vec2))); } break; case 17: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 147 "knot_parser/knot_parser.yy" { (yyval.kd) = new knot_diagram (planar_diagram ("", *(yysemantic_stack_[(4) - (3)].int_vec2))); } break; case 18: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 152 "knot_parser/knot_parser.yy" { basedvector, 1> even_labels (1); @@ -517,31 +525,31 @@ namespace yy { break; case 19: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 158 "knot_parser/knot_parser.yy" { (yyval.kd) = new knot_diagram (dt_code ("", *(yysemantic_stack_[(4) - (3)].int_vec2))); } break; case 20: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 160 "knot_parser/knot_parser.yy" { (yyval.kd) = new knot_diagram (dt_code ("", (yysemantic_stack_[(4) - (3)].string))); } break; case 21: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 165 "knot_parser/knot_parser.yy" { (yyval.kd) = new knot_diagram (torus_knot ((yysemantic_stack_[(6) - (3)].integer), (yysemantic_stack_[(6) - (5)].integer))); } break; case 22: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 170 "knot_parser/knot_parser.yy" { (yyval.kd) = new knot_diagram (braid ((yysemantic_stack_[(6) - (3)].integer), *(yysemantic_stack_[(6) - (5)].int_vec))); } break; case 23: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 175 "knot_parser/knot_parser.yy" { unsigned unknot_ar[1][4] = { @@ -552,7 +560,7 @@ namespace yy { break; case 26: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 190 "knot_parser/knot_parser.yy" { basedvector, 1> *v @@ -563,7 +571,7 @@ namespace yy { break; case 27: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 197 "knot_parser/knot_parser.yy" { basedvector, 1> *v = (yysemantic_stack_[(3) - (1)].int_vec2); @@ -573,19 +581,19 @@ namespace yy { break; case 28: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 206 "knot_parser/knot_parser.yy" { (yyval.int_vec) = (yysemantic_stack_[(3) - (2)].int_vec); } break; case 29: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 208 "knot_parser/knot_parser.yy" { (yyval.int_vec) = (yysemantic_stack_[(3) - (2)].int_vec); } break; case 30: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 213 "knot_parser/knot_parser.yy" { basedvector *v = @@ -596,7 +604,7 @@ namespace yy { break; case 31: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 220 "knot_parser/knot_parser.yy" { basedvector *v = (yysemantic_stack_[(3) - (1)].int_vec); @@ -606,7 +614,7 @@ namespace yy { break; case 32: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 229 "knot_parser/knot_parser.yy" { basedvector, 1> *v @@ -617,7 +625,7 @@ namespace yy { break; case 33: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 236 "knot_parser/knot_parser.yy" { basedvector, 1> *v = (yysemantic_stack_[(3) - (1)].int_vec2); @@ -627,7 +635,7 @@ namespace yy { break; case 34: -/* Line 661 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 245 "knot_parser/knot_parser.yy" { basedvector *v @@ -641,11 +649,12 @@ namespace yy { break; -/* Line 661 of lalr1.cc */ -#line 646 "knot_parser/knot_parser.cc" - default: - break; +/* Line 670 of lalr1.cc */ +#line 654 "knot_parser/knot_parser.cc" + default: + break; } + /* User semantic actions sometimes alter yychar, and that requires that yytoken be updated with the new translation. We take the approach of translating immediately before every use of yytoken. @@ -696,20 +705,19 @@ namespace yy { yyerror_range[1] = yylloc; if (yyerrstatus_ == 3) { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= yyeof_) - { - /* Return failure if at end of input. */ - if (yychar == yyeof_) - YYABORT; - } - else - { - yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc); - yychar = yyempty_; - } + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + if (yychar <= yyeof_) + { + /* Return failure if at end of input. */ + if (yychar == yyeof_) + YYABORT; + } + else + { + yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc); + yychar = yyempty_; + } } /* Else will try to reuse lookahead token after shifting the error @@ -758,7 +766,7 @@ namespace yy { /* Pop the current state because it cannot handle the error token. */ if (yystate_stack_.height () == 1) - YYABORT; + YYABORT; yyerror_range[1] = yylocation_stack_[0]; yydestruct_ ("Error: popping", @@ -806,16 +814,42 @@ namespace yy { /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ yypop_ (yylen); - while (yystate_stack_.height () != 1) + while (1 < yystate_stack_.height ()) { - yydestruct_ ("Cleanup: popping", - yystos_[yystate_stack_[0]], - &yysemantic_stack_[0], - &yylocation_stack_[0]); - yypop_ (); + yydestruct_ ("Cleanup: popping", + yystos_[yystate_stack_[0]], + &yysemantic_stack_[0], + &yylocation_stack_[0]); + yypop_ (); } return yyresult; + } + catch (...) + { + YYCDEBUG << "Exception caught: cleaning lookahead and stack" + << std::endl; + // Do not try to display the values of the reclaimed symbols, + // as their printer might throw an exception. + if (yychar != yyempty_) + { + /* Make sure we have latest lookahead translation. See + comments at user semantic actions for why this is + necessary. */ + yytoken = yytranslate_ (yychar); + yydestruct_ (YY_NULL, yytoken, &yylval, &yylloc); + } + + while (1 < yystate_stack_.height ()) + { + yydestruct_ (YY_NULL, + yystos_[yystate_stack_[0]], + &yysemantic_stack_[0], + &yylocation_stack_[0]); + yypop_ (); + } + throw; + } } // Generate an error message. @@ -1094,9 +1128,9 @@ namespace yy { } // yy -/* Line 1106 of lalr1.cc */ -#line 1099 "knot_parser/knot_parser.cc" -/* Line 1107 of lalr1.cc */ +/* Line 1141 of lalr1.cc */ +#line 1133 "knot_parser/knot_parser.cc" +/* Line 1142 of lalr1.cc */ #line 255 "knot_parser/knot_parser.yy" diff --git a/knot_parser/knot_parser.hh b/knot_parser/knot_parser.hh index 7f07eb3..1a9109b 100644 --- a/knot_parser/knot_parser.hh +++ b/knot_parser/knot_parser.hh @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.5. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Skeleton interface for Bison LALR(1) parsers in C++ @@ -41,13 +41,13 @@ # define YY_YY_KNOT_PARSER_KNOT_PARSER_HH_INCLUDED /* "%code requires" blocks. */ -/* Line 36 of lalr1.cc */ +/* Line 33 of lalr1.cc */ #line 11 "knot_parser/knot_parser.yy" #include -/* Line 36 of lalr1.cc */ +/* Line 33 of lalr1.cc */ #line 52 "knot_parser/knot_parser.hh" @@ -63,7 +63,7 @@ namespace yy { -/* Line 36 of lalr1.cc */ +/* Line 33 of lalr1.cc */ #line 68 "knot_parser/knot_parser.hh" /// A Bison parser. @@ -74,7 +74,7 @@ namespace yy { #ifndef YYSTYPE union semantic_type { -/* Line 36 of lalr1.cc */ +/* Line 33 of lalr1.cc */ #line 21 "knot_parser/knot_parser.yy" int integer; @@ -85,7 +85,7 @@ namespace yy { knot_diagram *kd; -/* Line 36 of lalr1.cc */ +/* Line 33 of lalr1.cc */ #line 90 "knot_parser/knot_parser.hh" }; #else @@ -254,6 +254,7 @@ namespace yy { /// \brief Reclaim the memory associated to a symbol. /// \param yymsg Why this token is reclaimed. + /// If null, do not display the symbol, just free it. /// \param yytype The symbol type. /// \param yyvaluep Its semantic value. /// \param yylocationp Its location. @@ -283,8 +284,8 @@ namespace yy { }; } // yy -/* Line 36 of lalr1.cc */ -#line 288 "knot_parser/knot_parser.hh" +/* Line 33 of lalr1.cc */ +#line 289 "knot_parser/knot_parser.hh" diff --git a/knot_parser/knot_scanner.cc b/knot_parser/knot_scanner.cc index a34f5dd..7123155 100644 --- a/knot_parser/knot_scanner.cc +++ b/knot_parser/knot_scanner.cc @@ -66,6 +66,7 @@ typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; +typedef uint64_t flex_uint64_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; @@ -172,7 +173,12 @@ typedef unsigned int flex_uint32_t; typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif -extern int knot_yyleng; +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern yy_size_t knot_yyleng; extern FILE *knot_yyin, *knot_yyout; @@ -198,11 +204,6 @@ extern FILE *knot_yyin, *knot_yyout; #define unput(c) yyunput( c, (yytext_ptr) ) -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state @@ -220,7 +221,7 @@ struct yy_buffer_state /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - int yy_n_chars; + yy_size_t yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to @@ -290,8 +291,8 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* yy_hold_char holds the character lost when knot_yytext is formed. */ static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int knot_yyleng; +static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ +yy_size_t knot_yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; @@ -319,7 +320,7 @@ static void knot_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); YY_BUFFER_STATE knot_yy_scan_buffer (char *base,yy_size_t size ); YY_BUFFER_STATE knot_yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE knot_yy_scan_bytes (yyconst char *bytes,int len ); +YY_BUFFER_STATE knot_yy_scan_bytes (yyconst char *bytes,yy_size_t len ); void *knot_yyalloc (yy_size_t ); void *knot_yyrealloc (void *,yy_size_t ); @@ -377,7 +378,7 @@ static void yy_fatal_error (yyconst char msg[] ); */ #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ - knot_yyleng = (size_t) (yy_cp - yy_bp); \ + knot_yyleng = (yy_size_t) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; @@ -483,7 +484,7 @@ char *knot_yytext; typedef yy::knot_parser::token token; typedef yy::knot_parser::token_type token_type; -#line 487 "knot_parser/knot_scanner.cc" +#line 488 "knot_parser/knot_scanner.cc" #define INITIAL 0 @@ -522,7 +523,7 @@ FILE *knot_yyget_out (void ); void knot_yyset_out (FILE * out_str ); -int knot_yyget_leng (void ); +yy_size_t knot_yyget_leng (void ); char *knot_yyget_text (void ); @@ -581,7 +582,7 @@ static int input (void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - int n; \ + yy_size_t n; \ for ( n = 0; n < max_size && \ (c = getc( knot_yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -666,7 +667,7 @@ YY_DECL #line 16 "knot_parser/knot_scanner.ll" -#line 670 "knot_parser/knot_scanner.cc" +#line 671 "knot_parser/knot_scanner.cc" if ( !(yy_init) ) { @@ -808,7 +809,7 @@ YY_RULE_SETUP #line 63 "knot_parser/knot_scanner.ll" ECHO; YY_BREAK -#line 812 "knot_parser/knot_scanner.cc" +#line 813 "knot_parser/knot_scanner.cc" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -995,7 +996,7 @@ static int yy_get_next_buffer (void) else { - int num_to_read = + yy_size_t num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) @@ -1009,7 +1010,7 @@ static int yy_get_next_buffer (void) if ( b->yy_is_our_buffer ) { - int new_size = b->yy_buf_size * 2; + yy_size_t new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; @@ -1040,7 +1041,7 @@ static int yy_get_next_buffer (void) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), (size_t) num_to_read ); + (yy_n_chars), num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } @@ -1162,7 +1163,7 @@ static int yy_get_next_buffer (void) else { /* need more input */ - int offset = (yy_c_buf_p) - (yytext_ptr); + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) @@ -1186,7 +1187,7 @@ static int yy_get_next_buffer (void) case EOB_ACT_END_OF_FILE: { if ( knot_yywrap( ) ) - return EOF; + return 0; if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; @@ -1438,7 +1439,7 @@ void knot_yypop_buffer_state (void) */ static void knot_yyensure_buffer_stack (void) { - int num_to_alloc; + yy_size_t num_to_alloc; if (!(yy_buffer_stack)) { @@ -1535,12 +1536,11 @@ YY_BUFFER_STATE knot_yy_scan_string (yyconst char * yystr ) * * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE knot_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) +YY_BUFFER_STATE knot_yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) { YY_BUFFER_STATE b; char *buf; - yy_size_t n; - int i; + yy_size_t n, i; /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; @@ -1622,7 +1622,7 @@ FILE *knot_yyget_out (void) /** Get the length of the current token. * */ -int knot_yyget_leng (void) +yy_size_t knot_yyget_leng (void) { return knot_yyleng; } diff --git a/knot_parser/location.hh b/knot_parser/location.hh index 7faaf2b..81e6604 100644 --- a/knot_parser/location.hh +++ b/knot_parser/location.hh @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.5. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Locations for Bison parsers in C++ @@ -42,7 +42,7 @@ namespace yy { -/* Line 164 of location.cc */ +/* Line 166 of location.cc */ #line 47 "knot_parser/location.hh" /// Abstract a location. @@ -156,7 +156,9 @@ namespace yy { ** ** Avoid duplicate information. */ - inline std::ostream& operator<< (std::ostream& ostr, const location& loc) + template + inline std::basic_ostream& + operator<< (std::basic_ostream& ostr, const location& loc) { position last = loc.end - 1; ostr << loc.begin; @@ -173,7 +175,7 @@ namespace yy { } // yy -/* Line 292 of location.cc */ -#line 178 "knot_parser/location.hh" +/* Line 296 of location.cc */ +#line 180 "knot_parser/location.hh" #endif /* !YY_YY_KNOT_PARSER_LOCATION_HH_INCLUDED */ diff --git a/knot_parser/position.hh b/knot_parser/position.hh index dbbea36..c590bd1 100644 --- a/knot_parser/position.hh +++ b/knot_parser/position.hh @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.5. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Positions for Bison parsers in C++ @@ -52,7 +52,7 @@ namespace yy { -/* Line 38 of location.cc */ +/* Line 36 of location.cc */ #line 57 "knot_parser/position.hh" /// Abstract a position. class position @@ -156,8 +156,9 @@ namespace yy { ** \param ostr the destination output stream ** \param pos a reference to the position to redirect */ - inline std::ostream& - operator<< (std::ostream& ostr, const position& pos) + template + inline std::basic_ostream& + operator<< (std::basic_ostream& ostr, const position& pos) { if (pos.filename) ostr << *pos.filename << ':'; @@ -166,6 +167,6 @@ namespace yy { } // yy -/* Line 149 of location.cc */ -#line 171 "knot_parser/position.hh" +/* Line 148 of location.cc */ +#line 172 "knot_parser/position.hh" #endif /* !YY_YY_KNOT_PARSER_POSITION_HH_INCLUDED */ diff --git a/knot_parser/stack.hh b/knot_parser/stack.hh index e005e60..d47647a 100644 --- a/knot_parser/stack.hh +++ b/knot_parser/stack.hh @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.5. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Stack handling for Bison parsers in C++ @@ -42,7 +42,7 @@ namespace yy { -/* Line 37 of stack.hh */ +/* Line 34 of stack.hh */ #line 47 "knot_parser/stack.hh" template > class stack @@ -127,7 +127,7 @@ namespace yy { }; } // yy -/* Line 119 of stack.hh */ +/* Line 116 of stack.hh */ #line 132 "knot_parser/stack.hh" #endif /* !YY_YY_KNOT_PARSER_STACK_HH_INCLUDED */ diff --git a/rd_parser/location.hh b/rd_parser/location.hh index de209d7..7b7d3f1 100644 --- a/rd_parser/location.hh +++ b/rd_parser/location.hh @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Locations for Bison parsers in C++ - Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software - Foundation, Inc. + Copyright (C) 2002-2007, 2009-2012 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 @@ -32,39 +31,55 @@ version 2.2 of Bison. */ /** - ** \file location.hh + ** \file rd_parser/location.hh ** Define the yy::location class. */ -#ifndef BISON_LOCATION_HH -# define BISON_LOCATION_HH +#ifndef YY_YY_RD_PARSER_LOCATION_HH_INCLUDED +# define YY_YY_RD_PARSER_LOCATION_HH_INCLUDED -# include -# include # include "position.hh" namespace yy { - -/* Line 163 of location.cc */ -#line 51 "rd_parser/location.hh" +/* Line 166 of location.cc */ +#line 47 "rd_parser/location.hh" /// Abstract a location. class location { public: - /// Construct a location. - location () - : begin (), end () + /// Construct a location from \a b to \a e. + location (const position& b, const position& e) + : begin (b) + , end (e) + { + } + + /// Construct a 0-width location in \a p. + explicit location (const position& p = position ()) + : begin (p) + , end (p) + { + } + + /// Construct a 0-width location in \a f, \a l, \a c. + explicit location (std::string* f, + unsigned int l = 1u, + unsigned int c = 1u) + : begin (f, l, c) + , end (f, l, c) { } /// Initialization. - inline void initialize (std::string* fn) + void initialize (std::string* f = YY_NULL, + unsigned int l = 1u, + unsigned int c = 1u) { - begin.initialize (fn); + begin.initialize (f, l, c); end = begin; } @@ -72,19 +87,19 @@ namespace yy { ** \{ */ public: /// Reset initial location to final location. - inline void step () + void step () { begin = end; } /// Extend the current location to the COUNT next columns. - inline void columns (unsigned int count = 1) + void columns (unsigned int count = 1) { end += count; } /// Extend the current location to the COUNT next lines. - inline void lines (unsigned int count = 1) + void lines (unsigned int count = 1) { end.lines (count); } @@ -141,7 +156,9 @@ namespace yy { ** ** Avoid duplicate information. */ - inline std::ostream& operator<< (std::ostream& ostr, const location& loc) + template + inline std::basic_ostream& + operator<< (std::basic_ostream& ostr, const location& loc) { position last = loc.end - 1; ostr << loc.begin; @@ -158,8 +175,7 @@ namespace yy { } // yy +/* Line 296 of location.cc */ +#line 180 "rd_parser/location.hh" -/* Line 272 of location.cc */ -#line 164 "rd_parser/location.hh" - -#endif // not BISON_LOCATION_HH +#endif /* !YY_YY_RD_PARSER_LOCATION_HH_INCLUDED */ diff --git a/rd_parser/position.hh b/rd_parser/position.hh index 1cd2639..4f3af7d 100644 --- a/rd_parser/position.hh +++ b/rd_parser/position.hh @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Positions for Bison parsers in C++ - Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software - Foundation, Inc. + Copyright (C) 2002-2007, 2009-2012 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 @@ -32,60 +31,71 @@ version 2.2 of Bison. */ /** - ** \file position.hh + ** \file rd_parser/position.hh ** Define the yy::position class. */ -#ifndef BISON_POSITION_HH -# define BISON_POSITION_HH +#ifndef YY_YY_RD_PARSER_POSITION_HH_INCLUDED +# define YY_YY_RD_PARSER_POSITION_HH_INCLUDED +# include // std::max # include # include -# include + +# ifndef YY_NULL +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULL nullptr +# else +# define YY_NULL 0 +# endif +# endif namespace yy { - -/* Line 38 of location.cc */ -#line 51 "rd_parser/position.hh" +/* Line 36 of location.cc */ +#line 57 "rd_parser/position.hh" /// Abstract a position. class position { public: /// Construct a position. - position () - : filename (0), line (1), column (1) + explicit position (std::string* f = YY_NULL, + unsigned int l = 1u, + unsigned int c = 1u) + : filename (f) + , line (l) + , column (c) { } /// Initialization. - inline void initialize (std::string* fn) + void initialize (std::string* fn = YY_NULL, + unsigned int l = 1u, + unsigned int c = 1u) { filename = fn; - line = 1; - column = 1; + line = l; + column = c; } /** \name Line and Column related manipulators ** \{ */ - public: /// (line related) Advance to the COUNT next lines. - inline void lines (int count = 1) + void lines (int count = 1) { - column = 1; + column = 1u; line += count; } /// (column related) Advance to the COUNT next columns. - inline void columns (int count = 1) + void columns (int count = 1) { column = std::max (1u, column + count); } /** \} */ - public: /// File name to which this position refers. std::string* filename; /// Current line number. @@ -95,7 +105,7 @@ namespace yy { }; /// Add and assign a position. - inline const position& + inline position& operator+= (position& res, const int width) { res.columns (width); @@ -111,7 +121,7 @@ namespace yy { } /// Add and assign a position. - inline const position& + inline position& operator-= (position& res, const int width) { return res += -width; @@ -146,8 +156,9 @@ namespace yy { ** \param ostr the destination output stream ** \param pos a reference to the position to redirect */ - inline std::ostream& - operator<< (std::ostream& ostr, const position& pos) + template + inline std::basic_ostream& + operator<< (std::basic_ostream& ostr, const position& pos) { if (pos.filename) ostr << *pos.filename << ':'; @@ -156,7 +167,6 @@ namespace yy { } // yy - -/* Line 145 of location.cc */ -#line 162 "rd_parser/position.hh" -#endif // not BISON_POSITION_HH +/* Line 148 of location.cc */ +#line 172 "rd_parser/position.hh" +#endif /* !YY_YY_RD_PARSER_POSITION_HH_INCLUDED */ diff --git a/rd_parser/rd_parser.cc b/rd_parser/rd_parser.cc index 085aa1a..2f6229b 100644 --- a/rd_parser/rd_parser.cc +++ b/rd_parser/rd_parser.cc @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Skeleton implementation for Bison LALR(1) parsers in C++ - Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free - Software Foundation, Inc. + Copyright (C) 2002-2012 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 @@ -34,21 +33,18 @@ /* First part of user declarations. */ - -/* Line 311 of lalr1.cc */ -#line 40 "rd_parser/rd_parser.cc" +/* Line 279 of lalr1.cc */ +#line 38 "rd_parser/rd_parser.cc" #include "rd_parser.hh" /* User implementation prologue. */ - -/* Line 317 of lalr1.cc */ -#line 49 "rd_parser/rd_parser.cc" +/* Line 285 of lalr1.cc */ +#line 46 "rd_parser/rd_parser.cc" /* Unqualified %code blocks. */ - -/* Line 318 of lalr1.cc */ +/* Line 286 of lalr1.cc */ #line 15 "rd_parser/rd_parser.yy" #define YY_DECL \ @@ -59,16 +55,23 @@ YY_DECL; #define CPT_MARKED 0x10000 #define CPT_MARKED2 0x20000 - -/* Line 318 of lalr1.cc */ +/* Line 286 of lalr1.cc */ #line 32 "rd_parser/rd_parser.yy" #define yylex rd_yylex +/* Line 286 of lalr1.cc */ +#line 66 "rd_parser/rd_parser.cc" -/* Line 318 of lalr1.cc */ -#line 72 "rd_parser/rd_parser.cc" + +# ifndef YY_NULL +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULL nullptr +# else +# define YY_NULL 0 +# endif +# endif #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS @@ -82,6 +85,27 @@ YY_DECL; # endif #endif +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +# ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).begin = YYRHSLOC (Rhs, 1).begin; \ + (Current).end = YYRHSLOC (Rhs, N).end; \ + } \ + else \ + { \ + (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \ + } \ + while (/*CONSTCOND*/ false) +# endif + + /* Suppress unused-variable warnings by "using" E. */ #define YYUSE(e) ((void) (e)) @@ -116,9 +140,9 @@ do { \ #else /* !YYDEBUG */ # define YYCDEBUG if (false) std::cerr -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_REDUCE_PRINT(Rule) -# define YY_STACK_PRINT() +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) YYUSE(Type) +# define YY_REDUCE_PRINT(Rule) static_cast(0) +# define YY_STACK_PRINT() static_cast(0) #endif /* !YYDEBUG */ @@ -132,49 +156,8 @@ do { \ namespace yy { - -/* Line 380 of lalr1.cc */ -#line 138 "rd_parser/rd_parser.cc" -#if YYERROR_VERBOSE - - /* Return YYSTR after stripping away unnecessary quotes and - backslashes, so that it's suitable for yyerror. The heuristic is - that double-quoting is unnecessary unless the string contains an - apostrophe, a comma, or backslash (other than backslash-backslash). - YYSTR is taken from yytname. */ - std::string - rd_parser::yytnamerr_ (const char *yystr) - { - if (*yystr == '"') - { - std::string yyr = ""; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - yyr += *yyp; - break; - - case '"': - return yyr; - } - do_not_strip_quotes: ; - } - - return yystr; - } - -#endif +/* Line 353 of lalr1.cc */ +#line 161 "rd_parser/rd_parser.cc" /// Build a parser object. rd_parser::rd_parser (resolution_diagram &parsed_rd_yyarg) @@ -202,6 +185,9 @@ namespace yy { { YYUSE (yylocationp); YYUSE (yyvaluep); + std::ostream& yyo = debug_stream (); + std::ostream& yyoutput = yyo; + YYUSE (yyoutput); switch (yytype) { default: @@ -230,7 +216,8 @@ namespace yy { YYUSE (yymsg); YYUSE (yyvaluep); - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + if (yymsg) + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); switch (yytype) { @@ -275,6 +262,18 @@ namespace yy { } #endif + inline bool + rd_parser::yy_pact_value_is_default_ (int yyvalue) + { + return yyvalue == yypact_ninf_; + } + + inline bool + rd_parser::yy_table_value_is_error_ (int yyvalue) + { + return yyvalue == yytable_ninf_; + } + int rd_parser::parse () { @@ -282,17 +281,18 @@ namespace yy { int yychar = yyempty_; int yytoken = 0; - /* State. */ + // State. int yyn; int yylen = 0; int yystate = 0; - /* Error handling. */ + // Error handling. int yynerrs_ = 0; int yyerrstatus_ = 0; /// Semantic value of the lookahead. - semantic_type yylval; + static semantic_type yyval_default; + semantic_type yylval = yyval_default; /// Location of the lookahead. location_type yylloc; /// The locations where the error started and ended. @@ -305,6 +305,10 @@ namespace yy { int yyresult; + // FIXME: This shoud be completely indented. It is not yet to + // avoid gratuitous conflicts when merging into the master branch. + try + { YYCDEBUG << "Starting parse" << std::endl; @@ -334,17 +338,16 @@ namespace yy { /* Try to take a decision without lookahead. */ yyn = yypact_[yystate]; - if (yyn == yypact_ninf_) + if (yy_pact_value_is_default_ (yyn)) goto yydefault; /* Read a lookahead token. */ if (yychar == yyempty_) { - YYCDEBUG << "Reading a token: "; - yychar = yylex (&yylval); + YYCDEBUG << "Reading a token: "; + yychar = yylex (&yylval); } - /* Convert token to internal form. */ if (yychar <= yyeof_) { @@ -367,8 +370,8 @@ namespace yy { yyn = yytable_[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == yytable_ninf_) - goto yyerrlab; + if (yy_table_value_is_error_ (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } @@ -415,16 +418,18 @@ namespace yy { else yyval = yysemantic_stack_[0]; + // Compute the default @$. { slice slice (yylocation_stack_, yylen); YYLLOC_DEFAULT (yyloc, slice, yylen); } + + // Perform the reduction. YY_REDUCE_PRINT (yyn); switch (yyn) { - case 2: - -/* Line 678 of lalr1.cc */ + case 2: +/* Line 670 of lalr1.cc */ #line 54 "rd_parser/rd_parser.yy" { unsigned n_crossings = (yysemantic_stack_[(1) - (1)].integer); @@ -453,8 +458,7 @@ namespace yy { break; case 6: - -/* Line 678 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 88 "rd_parser/rd_parser.yy" { unsigned s = ++ parsed_rd.n_starting_circles; @@ -480,8 +484,7 @@ namespace yy { break; case 12: - -/* Line 678 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 126 "rd_parser/rd_parser.yy" { basedvector *v = @@ -492,8 +495,7 @@ namespace yy { break; case 13: - -/* Line 678 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 133 "rd_parser/rd_parser.yy" { basedvector *v = (yysemantic_stack_[(3) - (1)].cpt_vec); @@ -503,36 +505,31 @@ namespace yy { break; case 15: - -/* Line 678 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 143 "rd_parser/rd_parser.yy" { (yyval.cpt) = (yysemantic_stack_[(2) - (1)].cpt) | CPT_MARKED; } break; case 16: - -/* Line 678 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 145 "rd_parser/rd_parser.yy" { (yyval.cpt) = (yysemantic_stack_[(2) - (1)].cpt) | CPT_MARKED2; } break; case 17: - -/* Line 678 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 147 "rd_parser/rd_parser.yy" { (yyval.cpt) = (yysemantic_stack_[(3) - (1)].cpt) | CPT_MARKED | CPT_MARKED2; } break; case 18: - -/* Line 678 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 149 "rd_parser/rd_parser.yy" { (yyval.cpt) = (yysemantic_stack_[(3) - (1)].cpt) | CPT_MARKED | CPT_MARKED2; } break; case 19: - -/* Line 678 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 154 "rd_parser/rd_parser.yy" { if ((yysemantic_stack_[(2) - (2)].inside)) @@ -542,26 +539,35 @@ namespace yy { break; case 20: - -/* Line 678 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 163 "rd_parser/rd_parser.yy" { (yyval.cpt) = parsed_rd.crossing_to_cpt ((yysemantic_stack_[(2) - (2)].integer)); } break; case 21: - -/* Line 678 of lalr1.cc */ +/* Line 670 of lalr1.cc */ #line 165 "rd_parser/rd_parser.yy" { (yyval.cpt) = parsed_rd.crossing_from_cpt ((yysemantic_stack_[(2) - (2)].integer)); } break; - -/* Line 678 of lalr1.cc */ -#line 562 "rd_parser/rd_parser.cc" - default: - break; +/* Line 670 of lalr1.cc */ +#line 556 "rd_parser/rd_parser.cc" + default: + break; } + + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action + invokes YYABORT, YYACCEPT, or YYERROR immediately after altering + yychar. In the case of YYABORT or YYACCEPT, an incorrect + destructor might then be invoked immediately. In the case of + YYERROR, subsequent parser actions might lead to an incorrect + destructor call or verbose syntax error message before the + lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc); yypop_ (yylen); @@ -585,30 +591,35 @@ namespace yy { | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yytranslate_ (yychar); + /* If not already recovering from an error, report this error. */ if (!yyerrstatus_) { ++yynerrs_; - error (yylloc, yysyntax_error_ (yystate)); + if (yychar == yyempty_) + yytoken = yyempty_; + error (yylloc, yysyntax_error_ (yystate, yytoken)); } yyerror_range[1] = yylloc; if (yyerrstatus_ == 3) { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= yyeof_) - { - /* Return failure if at end of input. */ - if (yychar == yyeof_) - YYABORT; - } - else - { - yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc); - yychar = yyempty_; - } + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + if (yychar <= yyeof_) + { + /* Return failure if at end of input. */ + if (yychar == yyeof_) + YYABORT; + } + else + { + yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc); + yychar = yyempty_; + } } /* Else will try to reuse lookahead token after shifting the error @@ -644,7 +655,7 @@ namespace yy { for (;;) { yyn = yypact_[yystate]; - if (yyn != yypact_ninf_) + if (!yy_pact_value_is_default_ (yyn)) { yyn += yyterror_; if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) @@ -657,7 +668,7 @@ namespace yy { /* Pop the current state because it cannot handle the error token. */ if (yystate_stack_.height () == 1) - YYABORT; + YYABORT; yyerror_range[1] = yylocation_stack_[0]; yydestruct_ ("Error: popping", @@ -694,70 +705,60 @@ namespace yy { yyreturn: if (yychar != yyempty_) - yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc); + { + /* Make sure we have latest lookahead translation. See comments + at user semantic actions for why this is necessary. */ + yytoken = yytranslate_ (yychar); + yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, + &yylloc); + } /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ yypop_ (yylen); - while (yystate_stack_.height () != 1) + while (1 < yystate_stack_.height ()) { - yydestruct_ ("Cleanup: popping", - yystos_[yystate_stack_[0]], - &yysemantic_stack_[0], - &yylocation_stack_[0]); - yypop_ (); + yydestruct_ ("Cleanup: popping", + yystos_[yystate_stack_[0]], + &yysemantic_stack_[0], + &yylocation_stack_[0]); + yypop_ (); } return yyresult; + } + catch (...) + { + YYCDEBUG << "Exception caught: cleaning lookahead and stack" + << std::endl; + // Do not try to display the values of the reclaimed symbols, + // as their printer might throw an exception. + if (yychar != yyempty_) + { + /* Make sure we have latest lookahead translation. See + comments at user semantic actions for why this is + necessary. */ + yytoken = yytranslate_ (yychar); + yydestruct_ (YY_NULL, yytoken, &yylval, &yylloc); + } + + while (1 < yystate_stack_.height ()) + { + yydestruct_ (YY_NULL, + yystos_[yystate_stack_[0]], + &yysemantic_stack_[0], + &yylocation_stack_[0]); + yypop_ (); + } + throw; + } } // Generate an error message. std::string - rd_parser::yysyntax_error_ (int yystate) + rd_parser::yysyntax_error_ (int, int) { - std::string res; - YYUSE (yystate); -#if YYERROR_VERBOSE - int yyn = yypact_[yystate]; - if (yypact_ninf_ < yyn && yyn <= yylast_) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = yylast_ - yyn + 1; - int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; - int count = 0; - for (int x = yyxbegin; x < yyxend; ++x) - if (yycheck_[x + yyn] == x && x != yyterror_) - ++count; - - // FIXME: This method of building the message is not compatible - // with internationalization. It should work like yacc.c does it. - // That is, first build a string that looks like this: - // "syntax error, unexpected %s or %s or %s" - // Then, invoke YY_ on this string. - // Finally, use the string as a format to output - // yytname_[tok], etc. - // Until this gets fixed, this message appears in English only. - res = "syntax error, unexpected "; - res += yytnamerr_ (yytname_[tok]); - if (count < 5) - { - count = 0; - for (int x = yyxbegin; x < yyxend; ++x) - if (yycheck_[x + yyn] == x && x != yyterror_) - { - res += (!count++) ? ", expecting " : " or "; - res += yytnamerr_ (yytname_[x]); - } - } - } - else -#endif - res = YY_("syntax error"); - return res; + return YY_("syntax error"); } @@ -773,9 +774,9 @@ namespace yy { -12, -12, -12, 18, 13, -12, -12 }; - /* 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. */ + /* YYDEFACT[S] -- default reduction number in state S. Performed when + YYTABLE doesn't specify something else to do. Zero means the + default is an error. */ const unsigned char rd_parser::yydefact_[] = { @@ -803,7 +804,7 @@ namespace yy { /* 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. */ + number is the opposite. If YYTABLE_NINF_, syntax error. */ const signed char rd_parser::yytable_ninf_ = -1; const unsigned char rd_parser::yytable_[] = @@ -864,7 +865,7 @@ namespace yy { 2, 2, 1, 1 }; -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +#if YYDEBUG /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at \a yyntokens_, nonterminals. */ const char* @@ -875,11 +876,10 @@ namespace yy { "resolution_diagram", "$@1", "starting_circles", "starting_circle", "dual_crossings_opt", "dual_crossings", "dual_crossing", "crossing_points", "crossing_point", "crossing_point_1", - "crossing_point_spec", "inout", 0 + "crossing_point_spec", "inout", YY_NULL }; -#endif -#if YYDEBUG + /* YYRHS -- A `-1'-separated list of the rules' RHS. */ const rd_parser::rhs_number_type rd_parser::yyrhs_[] = @@ -997,12 +997,9 @@ namespace yy { } // yy - -/* Line 1054 of lalr1.cc */ -#line 1003 "rd_parser/rd_parser.cc" - - -/* Line 1056 of lalr1.cc */ +/* Line 1141 of lalr1.cc */ +#line 1002 "rd_parser/rd_parser.cc" +/* Line 1142 of lalr1.cc */ #line 173 "rd_parser/rd_parser.yy" @@ -1027,4 +1024,3 @@ parse_resolution_diagram (const char *s) return rd; } - diff --git a/rd_parser/rd_parser.hh b/rd_parser/rd_parser.hh index d522587..3567455 100644 --- a/rd_parser/rd_parser.hh +++ b/rd_parser/rd_parser.hh @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Skeleton interface for Bison LALR(1) parsers in C++ - Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free - Software Foundation, Inc. + Copyright (C) 2002-2012 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 @@ -31,41 +30,30 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ +/** + ** \file rd_parser/rd_parser.hh + ** Define the yy::parser class. + */ + /* C++ LALR(1) parser skeleton written by Akim Demaille. */ -#ifndef PARSER_HEADER_H -# define PARSER_HEADER_H +#ifndef YY_YY_RD_PARSER_RD_PARSER_HH_INCLUDED +# define YY_YY_RD_PARSER_RD_PARSER_HH_INCLUDED /* "%code requires" blocks. */ - -/* Line 35 of lalr1.cc */ +/* Line 33 of lalr1.cc */ #line 11 "rd_parser/rd_parser.yy" #include - -/* Line 35 of lalr1.cc */ -#line 50 "rd_parser/rd_parser.hh" +/* Line 33 of lalr1.cc */ +#line 52 "rd_parser/rd_parser.hh" #include #include #include "stack.hh" - - -namespace yy { - -/* Line 35 of lalr1.cc */ -#line 61 "rd_parser/rd_parser.hh" - class position; - class location; - -} // yy - -/* Line 35 of lalr1.cc */ -#line 68 "rd_parser/rd_parser.hh" - #include "location.hh" /* Enabling traces. */ @@ -73,43 +61,10 @@ namespace yy { # define YYDEBUG 0 #endif -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 -#endif - -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ -do { \ - if (N) \ - { \ - (Current).begin = (Rhs)[1].begin; \ - (Current).end = (Rhs)[N].end; \ - } \ - else \ - { \ - (Current).begin = (Current).end = (Rhs)[0].end; \ - } \ -} while (false) -#endif - namespace yy { - -/* Line 35 of lalr1.cc */ -#line 113 "rd_parser/rd_parser.hh" +/* Line 33 of lalr1.cc */ +#line 68 "rd_parser/rd_parser.hh" /// A Bison parser. class rd_parser @@ -119,8 +74,7 @@ namespace yy { #ifndef YYSTYPE union semantic_type { - -/* Line 35 of lalr1.cc */ +/* Line 33 of lalr1.cc */ #line 25 "rd_parser/rd_parser.yy" int integer; @@ -129,9 +83,8 @@ namespace yy { basedvector *cpt_vec; - -/* Line 35 of lalr1.cc */ -#line 135 "rd_parser/rd_parser.hh" +/* Line 33 of lalr1.cc */ +#line 88 "rd_parser/rd_parser.hh" }; #else typedef YYSTYPE semantic_type; @@ -186,7 +139,7 @@ namespace yy { /// Generate an error message. /// \param state the state where the error occurred. /// \param tok the lookahead token. - virtual std::string yysyntax_error_ (int yystate); + virtual std::string yysyntax_error_ (int yystate, int tok); #if YYDEBUG /// \brief Report a symbol value on the debug stream. @@ -222,6 +175,14 @@ namespace yy { /// The location stack. location_stack_type yylocation_stack_; + /// Whether the given \c yypact_ value indicates a defaulted state. + /// \param yyvalue the value to check + static bool yy_pact_value_is_default_ (int yyvalue); + + /// Whether the given \c yytable_ value indicates a syntax error. + /// \param yyvalue the value to check + static bool yy_table_value_is_error_ (int yyvalue); + /// Internal symbol numbers. typedef unsigned char token_number_type; /* Tables. */ @@ -229,7 +190,7 @@ namespace yy { static const signed char yypact_[]; static const signed char yypact_ninf_; - /// For a state, default rule to reduce. + /// For a state, default reduction number. /// Unless\a yytable_ specifies something else to do. /// Zero means the default is an error. static const unsigned char yydefact_[]; @@ -253,19 +214,12 @@ namespace yy { /// For a rule, its LHS. static const unsigned char yyr1_[]; /// For a rule, its RHS length. - static const unsigned char yyr2_[]; - -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE - /// For a symbol, its name in clear. - static const char* const yytname_[]; -#endif - -#if YYERROR_VERBOSE - /// Convert the symbol name \a n to a form suitable for a diagnostic. - virtual std::string yytnamerr_ (const char *n); -#endif + static const unsigned char yyr2_[]; #if YYDEBUG + /// For a symbol, its name in clear. + static const char* const yytname_[]; + /// A type to store symbol numbers and -1. typedef signed char rhs_number_type; /// A `-1'-separated list of the rules' RHS. @@ -291,6 +245,7 @@ namespace yy { /// \brief Reclaim the memory associated to a symbol. /// \param yymsg Why this token is reclaimed. + /// If null, do not display the symbol, just free it. /// \param yytype The symbol type. /// \param yyvaluep Its semantic value. /// \param yylocationp Its location. @@ -320,10 +275,9 @@ namespace yy { }; } // yy - -/* Line 35 of lalr1.cc */ -#line 326 "rd_parser/rd_parser.hh" +/* Line 33 of lalr1.cc */ +#line 280 "rd_parser/rd_parser.hh" -#endif /* ! defined PARSER_HEADER_H */ +#endif /* !YY_YY_RD_PARSER_RD_PARSER_HH_INCLUDED */ diff --git a/rd_parser/stack.hh b/rd_parser/stack.hh index c356e5c..3dd5ca0 100644 --- a/rd_parser/stack.hh +++ b/rd_parser/stack.hh @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Stack handling for Bison parsers in C++ - Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free - Software Foundation, Inc. + Copyright (C) 2002-2012 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 @@ -31,21 +30,24 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -#ifndef BISON_STACK_HH -# define BISON_STACK_HH +/** + ** \file rd_parser/stack.hh + ** Define the yy::stack class. + */ -#include +#ifndef YY_YY_RD_PARSER_STACK_HH_INCLUDED +# define YY_YY_RD_PARSER_STACK_HH_INCLUDED + +# include namespace yy { - -/* Line 1067 of lalr1.cc */ -#line 44 "rd_parser/stack.hh" +/* Line 34 of stack.hh */ +#line 47 "rd_parser/stack.hh" template > class stack { public: - // Hide our reversed order. typedef typename S::reverse_iterator iterator; typedef typename S::const_reverse_iterator const_iterator; @@ -84,7 +86,7 @@ namespace yy { pop (unsigned int n = 1) { for (; n; --n) - seq_.pop_front (); + seq_.pop_front (); } inline @@ -98,7 +100,6 @@ namespace yy { inline const_iterator end () const { return seq_.rend (); } private: - S seq_; }; @@ -107,10 +108,9 @@ namespace yy { class slice { public: - - slice (const S& stack, - unsigned int range) : stack_ (stack), - range_ (range) + slice (const S& stack, unsigned int range) + : stack_ (stack) + , range_ (range) { } @@ -122,15 +122,12 @@ namespace yy { } private: - const S& stack_; unsigned int range_; }; } // yy +/* Line 116 of stack.hh */ +#line 132 "rd_parser/stack.hh" -/* Line 1153 of lalr1.cc */ -#line 134 "rd_parser/stack.hh" - -#endif // not BISON_STACK_HH[]dnl - +#endif /* !YY_YY_RD_PARSER_STACK_HH_INCLUDED */