Use push parser for selection parsing.
authorTeemu Murtola <teemu.murtola@gmail.com>
Thu, 14 Jun 2012 04:27:29 +0000 (07:27 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Wed, 20 Jun 2012 17:52:54 +0000 (20:52 +0300)
The push parser is new in Bison 2.4 (current parser.cpp files generated
with 2.5), and has two benefits in our case:
- Clearer control flow, since the interactive prompt loop is now outside
  the parser, so it doesn't need to behave like a state machine.
- Allows better exception handling: since it is possible to directly
  return from Flex actions, we should also be able to throw exceptions.
  But without this change, they would go through the generated part of
  the Bison parser, causing memory leaks since the code is generated for
  C.  With this change, the Flex scanner is called directly from C++
  code, eliminating this problem.

Since the Bison and Flex parsers are now decoupled, it should also be
possible to clarify the code further, by having a separate data
structure for parser-specific data instead of using yyscan_t.  For now,
kept the changes to a minimum.

Related to #880.

Change-Id: I43ea11561d3dd0577dd95eae3794ca621953d038

13 files changed:
src/gromacs/selection/parser.cpp
src/gromacs/selection/parser.h
src/gromacs/selection/parser.y
src/gromacs/selection/scanner.cpp
src/gromacs/selection/scanner.h
src/gromacs/selection/scanner.l
src/gromacs/selection/scanner_flex.h
src/gromacs/selection/scanner_internal.cpp
src/gromacs/selection/scanner_internal.h
src/gromacs/selection/selectioncollection-impl.h
src/gromacs/selection/selectioncollection.cpp
src/gromacs/utility/file.cpp
src/gromacs/utility/file.h

index 0385ca1a1b4f5433fd670ea87d368989fed52b57..e64669f4c575b5fdbe574bedb763ac4567a436a6 100644 (file)
@@ -1,24 +1,21 @@
-/* A Bison parser, made by GNU Bison 2.3.  */
+/* A Bison parser, made by GNU Bison 2.5.  */
 
-/* Skeleton implementation for Bison's Yacc-like parsers in C
-
-   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
-   Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
+/* Bison implementation for Yacc-like parsers in C
+   
+      Copyright (C) 1984, 1989-1990, 2000-2011 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
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+   
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-
+   
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* As a special exception, you may create a larger work that contains
    part or all of the Bison parser skeleton and distribute that work
@@ -29,7 +26,7 @@
    special exception, which will cause the skeleton and the resulting
    Bison output files to be licensed under the GNU General Public
    License without this special exception.
-
+   
    This special exception was added by the Free Software Foundation in
    version 2.2 of Bison.  */
 
@@ -47,7 +44,7 @@
 #define YYBISON 1
 
 /* Bison version.  */
-#define YYBISON_VERSION "2.3"
+#define YYBISON_VERSION "2.5"
 
 /* Skeleton name.  */
 #define YYSKELETON_NAME "yacc.c"
 /* Pure parsers.  */
 #define YYPURE 1
 
+/* Push parsers.  */
+#define YYPUSH 1
+
+/* Pull parsers.  */
+#define YYPULL 0
+
 /* Using locations.  */
 #define YYLSP_NEEDED 0
 
 /* Substitute the variable and function names.  */
-#define yyparse _gmx_sel_yybparse
-#define yylex   _gmx_sel_yyblex
-#define yyerror _gmx_sel_yyberror
-#define yylval  _gmx_sel_yyblval
-#define yychar  _gmx_sel_yybchar
-#define yydebug _gmx_sel_yybdebug
-#define yynerrs _gmx_sel_yybnerrs
-
-
-/* Tokens.  */
-#ifndef YYTOKENTYPE
-# define YYTOKENTYPE
-   /* Put the tokens into the symbol table, so that GDB and other debuggers
-      know about them.  */
-   enum yytokentype {
-     INVALID = 258,
-     HELP = 259,
-     HELP_TOPIC = 260,
-     TOK_INT = 261,
-     TOK_REAL = 262,
-     STR = 263,
-     IDENTIFIER = 264,
-     CMD_SEP = 265,
-     GROUP = 266,
-     TO = 267,
-     VARIABLE_NUMERIC = 268,
-     VARIABLE_GROUP = 269,
-     VARIABLE_POS = 270,
-     KEYWORD_NUMERIC = 271,
-     KEYWORD_STR = 272,
-     KEYWORD_POS = 273,
-     KEYWORD_GROUP = 274,
-     METHOD_NUMERIC = 275,
-     METHOD_GROUP = 276,
-     METHOD_POS = 277,
-     MODIFIER = 278,
-     EMPTY_POSMOD = 279,
-     PARAM = 280,
-     END_OF_METHOD = 281,
-     OF = 282,
-     CMP_OP = 283,
-     PARAM_REDUCT = 284,
-     XOR = 285,
-     OR = 286,
-     AND = 287,
-     NOT = 288,
-     UNARY_NEG = 289,
-     NUM_REDUCT = 290
-   };
-#endif
-/* Tokens.  */
-#define INVALID 258
-#define HELP 259
-#define HELP_TOPIC 260
-#define TOK_INT 261
-#define TOK_REAL 262
-#define STR 263
-#define IDENTIFIER 264
-#define CMD_SEP 265
-#define GROUP 266
-#define TO 267
-#define VARIABLE_NUMERIC 268
-#define VARIABLE_GROUP 269
-#define VARIABLE_POS 270
-#define KEYWORD_NUMERIC 271
-#define KEYWORD_STR 272
-#define KEYWORD_POS 273
-#define KEYWORD_GROUP 274
-#define METHOD_NUMERIC 275
-#define METHOD_GROUP 276
-#define METHOD_POS 277
-#define MODIFIER 278
-#define EMPTY_POSMOD 279
-#define PARAM 280
-#define END_OF_METHOD 281
-#define OF 282
-#define CMP_OP 283
-#define PARAM_REDUCT 284
-#define XOR 285
-#define OR 286
-#define AND 287
-#define NOT 288
-#define UNARY_NEG 289
-#define NUM_REDUCT 290
-
-
+#define yypush_parse    _gmx_sel_yypush_parse
+#define yypstate_new    _gmx_sel_yypstate_new
+#define yypstate_delete _gmx_sel_yypstate_delete
+#define yypstate        _gmx_sel_yypstate
+#define yylex           _gmx_sel_yylex
+#define yyerror         _gmx_sel_yyerror
+#define yylval          _gmx_sel_yylval
+#define yychar          _gmx_sel_yychar
+#define yydebug         _gmx_sel_yydebug
+#define yynerrs         _gmx_sel_yynerrs
 
 
 /* Copy the first part of user declarations.  */
+
+/* Line 268 of yacc.c  */
 #line 37 "parser.y"
 
 /*! \internal \file parser.cpp
@@ -184,6 +113,9 @@ yyerror(yyscan_t, char const *s);
 #endif
 
 
+/* Line 268 of yacc.c  */
+#line 118 "parser.cpp"
+
 /* Enabling traces.  */
 #ifndef YYDEBUG
 # define YYDEBUG 1
@@ -202,10 +134,58 @@ yyerror(yyscan_t, char const *s);
 # define YYTOKEN_TABLE 0
 #endif
 
+
+/* Tokens.  */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+   /* Put the tokens into the symbol table, so that GDB and other debuggers
+      know about them.  */
+   enum yytokentype {
+     INVALID = 258,
+     HELP = 259,
+     HELP_TOPIC = 260,
+     TOK_INT = 261,
+     TOK_REAL = 262,
+     STR = 263,
+     IDENTIFIER = 264,
+     CMD_SEP = 265,
+     GROUP = 266,
+     TO = 267,
+     VARIABLE_NUMERIC = 268,
+     VARIABLE_GROUP = 269,
+     VARIABLE_POS = 270,
+     KEYWORD_NUMERIC = 271,
+     KEYWORD_STR = 272,
+     KEYWORD_POS = 273,
+     KEYWORD_GROUP = 274,
+     METHOD_NUMERIC = 275,
+     METHOD_GROUP = 276,
+     METHOD_POS = 277,
+     MODIFIER = 278,
+     EMPTY_POSMOD = 279,
+     PARAM = 280,
+     END_OF_METHOD = 281,
+     OF = 282,
+     CMP_OP = 283,
+     PARAM_REDUCT = 284,
+     XOR = 285,
+     OR = 286,
+     AND = 287,
+     NOT = 288,
+     UNARY_NEG = 289,
+     NUM_REDUCT = 290
+   };
+#endif
+
+
+
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
-#line 72 "parser.y"
 {
+
+/* Line 293 of yacc.c  */
+#line 72 "parser.y"
+
     int                         i;
     real                        r;
     char                       *str;
@@ -215,22 +195,47 @@ typedef union YYSTYPE
 
     struct t_selexpr_value     *val;
     struct t_selexpr_param     *param;
-}
-/* Line 193 of yacc.c.  */
-#line 221 "parser.cpp"
-       YYSTYPE;
+
+
+
+/* Line 293 of yacc.c  */
+#line 203 "parser.cpp"
+} YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
-# define YYSTYPE_IS_TRIVIAL 1
 #endif
 
+#ifndef YYPUSH_DECLS
+#  define YYPUSH_DECLS
+struct yypstate;
+typedef struct yypstate yypstate;
+enum { YYPUSH_MORE = 4 };
+
+#if defined __STDC__ || defined __cplusplus
+int yypush_parse (yypstate *yyps, int yypushed_char, YYSTYPE const *yypushed_val, void *scanner);
+#else
+int yypush_parse ();
+#endif
+
+#if defined __STDC__ || defined __cplusplus
+yypstate * yypstate_new (void);
+#else
+yypstate * yypstate_new ();
+#endif
+#if defined __STDC__ || defined __cplusplus
+void yypstate_delete (yypstate *yyps);
+#else
+void yypstate_delete ();
+#endif
+#endif
 
 
 /* Copy the second part of user declarations.  */
 
 
-/* Line 216 of yacc.c.  */
-#line 234 "parser.cpp"
+/* Line 343 of yacc.c  */
+#line 239 "parser.cpp"
 
 #ifdef short
 # undef short
@@ -305,14 +310,14 @@ typedef short int yytype_int16;
 #if (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
 static int
-YYID (int i)
+YYID (int yyi)
 #else
 static int
-YYID (i)
-    int i;
+YYID (yyi)
+    int yyi;
 #endif
 {
-  return i;
+  return yyi;
 }
 #endif
 
@@ -320,30 +325,6 @@ YYID (i)
 
 /* The parser invokes alloca or malloc; define the necessary symbols.  */
 
-# ifdef YYSTACK_USE_ALLOCA
-#  if YYSTACK_USE_ALLOCA
-#   ifdef __GNUC__
-#    define YYSTACK_ALLOC __builtin_alloca
-#   elif defined __BUILTIN_VA_ARG_INCR
-#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
-#   elif defined _AIX
-#    define YYSTACK_ALLOC __alloca
-#   elif defined _MSC_VER
-#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
-#    define alloca _alloca
-#   else
-#    define YYSTACK_ALLOC alloca
-#    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-#     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-#     ifndef _STDLIB_H
-#      define _STDLIB_H 1
-#     endif
-#    endif
-#   endif
-#  endif
-# endif
-
 # ifdef YYSTACK_ALLOC
    /* Pacify GCC's `empty if-body' warning.  */
 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
@@ -360,24 +341,24 @@ YYID (i)
 #  ifndef YYSTACK_ALLOC_MAXIMUM
 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
 #  endif
-#  if (defined __cplusplus && ! defined _STDLIB_H \
+#  if (defined __cplusplus && ! defined EXIT_SUCCESS \
        && ! ((defined YYMALLOC || defined malloc) \
             && (defined YYFREE || defined free)))
 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-#   ifndef _STDLIB_H
-#    define _STDLIB_H 1
+#   ifndef EXIT_SUCCESS
+#    define EXIT_SUCCESS 0
 #   endif
 #  endif
 #  ifndef YYMALLOC
 #   define YYMALLOC malloc
-#   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+#   if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
 #   endif
 #  endif
 #  ifndef YYFREE
 #   define YYFREE free
-#   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+#   if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
 void free (void *); /* INFRINGES ON USER NAME SPACE */
 #   endif
@@ -393,9 +374,9 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
 /* A type that is properly aligned for any stack member.  */
 union yyalloc
 {
-  yytype_int16 yyss;
-  YYSTYPE yyvs;
-  };
+  yytype_int16 yyss_alloc;
+  YYSTYPE yyvs_alloc;
+};
 
 /* The size of the maximum gap between one aligned stack and the next.  */
 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
@@ -406,6 +387,27 @@ union yyalloc
      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
       + YYSTACK_GAP_MAXIMUM)
 
+# define YYCOPY_NEEDED 1
+
+/* Relocate STACK from its old location to the new one.  The
+   local variables YYSIZE and YYSTACKSIZE give the old and new number of
+   elements in the stack, and YYPTR gives the new location of the
+   stack.  Advance YYPTR to a properly aligned location for the next
+   stack.  */
+# define YYSTACK_RELOCATE(Stack_alloc, Stack)                          \
+    do                                                                 \
+      {                                                                        \
+       YYSIZE_T yynewbytes;                                            \
+       YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
+       Stack = &yyptr->Stack_alloc;                                    \
+       yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+       yyptr += yynewbytes / sizeof (*yyptr);                          \
+      }                                                                        \
+    while (YYID (0))
+
+#endif
+
+#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
 /* Copy COUNT objects from FROM to TO.  The source and destination do
    not overlap.  */
 # ifndef YYCOPY
@@ -423,24 +425,7 @@ union yyalloc
       while (YYID (0))
 #  endif
 # endif
-
-/* Relocate STACK from its old location to the new one.  The
-   local variables YYSIZE and YYSTACKSIZE give the old and new number of
-   elements in the stack, and YYPTR gives the new location of the
-   stack.  Advance YYPTR to a properly aligned location for the next
-   stack.  */
-# define YYSTACK_RELOCATE(Stack)                                       \
-    do                                                                 \
-      {                                                                        \
-       YYSIZE_T yynewbytes;                                            \
-       YYCOPY (&yyptr->Stack, Stack, yysize);                          \
-       Stack = &yyptr->Stack;                                          \
-       yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
-       yyptr += yynewbytes / sizeof (*yyptr);                          \
-      }                                                                        \
-    while (YYID (0))
-
-#endif
+#endif /* !YYCOPY_NEEDED */
 
 /* YYFINAL -- State number of the termination state.  */
 #define YYFINAL  2
@@ -549,16 +534,16 @@ static const yytype_int8 yyrhs[] =
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const yytype_uint16 yyrline[] =
 {
-       0,   194,   194,   195,   204,   205,   225,   229,   230,   239,
-     249,   251,   253,   255,   257,   263,   267,   268,   276,   277,
-     282,   283,   295,   296,   300,   301,   304,   305,   308,   309,
-     317,   323,   329,   341,   345,   353,   359,   367,   368,   372,
-     377,   382,   390,   402,   409,   419,   424,   432,   434,   436,
-     438,   440,   442,   444,   451,   458,   470,   475,   479,   487,
-     498,   502,   506,   515,   517,   522,   523,   528,   535,   536,
-     537,   541,   542,   544,   549,   550,   554,   555,   557,   561,
-     563,   565,   567,   569,   573,   578,   583,   588,   592,   597,
-     602
+       0,   188,   188,   189,   198,   199,   219,   223,   224,   233,
+     243,   245,   247,   249,   251,   257,   261,   262,   270,   271,
+     276,   277,   289,   290,   294,   295,   298,   299,   302,   303,
+     311,   317,   323,   335,   339,   347,   353,   361,   362,   366,
+     371,   376,   384,   396,   403,   413,   418,   426,   428,   430,
+     432,   434,   436,   438,   445,   452,   464,   469,   473,   481,
+     492,   496,   500,   509,   511,   516,   517,   522,   529,   530,
+     531,   535,   536,   538,   543,   544,   548,   549,   551,   555,
+     557,   559,   561,   563,   567,   572,   577,   582,   586,   591,
+     596
 };
 #endif
 
@@ -627,8 +612,8 @@ static const yytype_uint8 yyr2[] =
        3
 };
 
-/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
-   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
+/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
+   Performed when YYTABLE doesn't specify something else to do.  Zero
    means the default is an error.  */
 static const yytype_uint8 yydefact[] =
 {
@@ -689,8 +674,7 @@ static const yytype_int8 yypgoto[] =
 
 /* 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.
-   If YYTABLE_NINF, syntax error.  */
+   number is the opposite.  If YYTABLE_NINF, syntax error.  */
 #define YYTABLE_NINF -26
 static const yytype_int16 yytable[] =
 {
@@ -738,6 +722,12 @@ static const yytype_int16 yytable[] =
       17,     0,     0,     0,     0,     0,     0,    42
 };
 
+#define yypact_value_is_default(yystate) \
+  ((yystate) == (-72))
+
+#define yytable_value_is_error(yytable_value) \
+  YYID (0)
+
 static const yytype_int16 yycheck[] =
 {
        1,    17,    18,    23,     6,     7,     8,     9,     9,    31,
@@ -817,9 +807,18 @@ static const yytype_uint8 yystos[] =
 
 /* Like YYERROR except do call yyerror.  This remains here temporarily
    to ease the transition to the new meaning of YYERROR, for GCC.
-   Once GCC version 2 has supplanted version 1, this can go.  */
+   Once GCC version 2 has supplanted version 1, this can go.  However,
+   YYFAIL appears to be in use.  Nevertheless, it is formally deprecated
+   in Bison 2.4.2's NEWS entry, where a plan to phase it out is
+   discussed.  */
 
 #define YYFAIL         goto yyerrlab
+#if defined YYFAIL
+  /* This is here to suppress warnings from the GCC cpp's
+     -Wunused-macros.  Normally we don't worry about that warning, but
+     some users do, and we want to make it easy for users to remove
+     YYFAIL uses, which will produce warnings from Bison 2.5.  */
+#endif
 
 #define YYRECOVERING()  (!!yyerrstatus)
 
@@ -829,7 +828,6 @@ do                                                          \
     {                                                          \
       yychar = (Token);                                                \
       yylval = (Value);                                                \
-      yytoken = YYTRANSLATE (yychar);                          \
       YYPOPSTACK (1);                                          \
       goto yybackup;                                           \
     }                                                          \
@@ -871,19 +869,10 @@ while (YYID (0))
 #endif
 
 
-/* YY_LOCATION_PRINT -- Print the location on the stream.
-   This macro was not mandated originally: define only if we know
-   we won't break user code: when these are the locations we know.  */
+/* This macro is provided for backward compatibility. */
 
 #ifndef YY_LOCATION_PRINT
-# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
-#  define YY_LOCATION_PRINT(File, Loc)                 \
-     fprintf (File, "%d.%d-%d.%d",                     \
-             (Loc).first_line, (Loc).first_column,     \
-             (Loc).last_line,  (Loc).last_column)
-# else
-#  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
-# endif
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
 #endif
 
 
@@ -892,7 +881,7 @@ while (YYID (0))
 #ifdef YYLEX_PARAM
 # define YYLEX yylex (&yylval, YYLEX_PARAM)
 #else
-# define YYLEX yylex (&yylval, scanner)
+# define YYLEX yylex (&yylval)
 #endif
 
 /* Enable debugging if requested.  */
@@ -929,14 +918,14 @@ do {                                                                        \
 #if (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
 static void
-yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, yyscan_t                 scanner)
+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *scanner)
 #else
 static void
 yy_symbol_value_print (yyoutput, yytype, yyvaluep, scanner)
     FILE *yyoutput;
     int yytype;
     YYSTYPE const * const yyvaluep;
-    yyscan_t                 scanner;
+    void *scanner;
 #endif
 {
   if (!yyvaluep)
@@ -963,14 +952,14 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, scanner)
 #if (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
 static void
-yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, yyscan_t                 scanner)
+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *scanner)
 #else
 static void
 yy_symbol_print (yyoutput, yytype, yyvaluep, scanner)
     FILE *yyoutput;
     int yytype;
     YYSTYPE const * const yyvaluep;
-    yyscan_t                 scanner;
+    void *scanner;
 #endif
 {
   if (yytype < YYNTOKENS)
@@ -990,17 +979,20 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, scanner)
 #if (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
 static void
-yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
+yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
 #else
 static void
-yy_stack_print (bottom, top)
-    yytype_int16 *bottom;
-    yytype_int16 *top;
+yy_stack_print (yybottom, yytop)
+    yytype_int16 *yybottom;
+    yytype_int16 *yytop;
 #endif
 {
   YYFPRINTF (stderr, "Stack now");
-  for (; bottom <= top; ++bottom)
-    YYFPRINTF (stderr, " %d", *bottom);
+  for (; yybottom <= yytop; yybottom++)
+    {
+      int yybot = *yybottom;
+      YYFPRINTF (stderr, " %d", yybot);
+    }
   YYFPRINTF (stderr, "\n");
 }
 
@@ -1018,13 +1010,13 @@ do {                                                            \
 #if (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
 static void
-yy_reduce_print (YYSTYPE *yyvsp, int yyrule, yyscan_t                 scanner)
+yy_reduce_print (YYSTYPE *yyvsp, int yyrule, void *scanner)
 #else
 static void
 yy_reduce_print (yyvsp, yyrule, scanner)
     YYSTYPE *yyvsp;
     int yyrule;
-    yyscan_t                 scanner;
+    void *scanner;
 #endif
 {
   int yynrhs = yyr2[yyrule];
@@ -1035,11 +1027,11 @@ yy_reduce_print (yyvsp, yyrule, scanner)
   /* The symbols being reduced.  */
   for (yyi = 0; yyi < yynrhs; yyi++)
     {
-      fprintf (stderr, "   $%d = ", yyi + 1);
+      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
                       &(yyvsp[(yyi + 1) - (yynrhs)])
                                       , scanner);
-      fprintf (stderr, "\n");
+      YYFPRINTF (stderr, "\n");
     }
 }
 
@@ -1076,7 +1068,6 @@ int yydebug;
 # define YYMAXDEPTH 10000
 #endif
 
-\f
 
 #if YYERROR_VERBOSE
 
@@ -1179,115 +1170,142 @@ yytnamerr (char *yyres, const char *yystr)
 }
 # endif
 
-/* Copy into YYRESULT an error message about the unexpected token
-   YYCHAR while in state YYSTATE.  Return the number of bytes copied,
-   including the terminating null byte.  If YYRESULT is null, do not
-   copy anything; just return the number of bytes that would be
-   copied.  As a special case, return 0 if an ordinary "syntax error"
-   message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
-   size calculation.  */
-static YYSIZE_T
-yysyntax_error (char *yyresult, int yystate, int yychar)
-{
-  int yyn = yypact[yystate];
+/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
+   about the unexpected token YYTOKEN for the state stack whose top is
+   YYSSP.
 
-  if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
-    return 0;
-  else
+   Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
+   not large enough to hold the message.  In that case, also set
+   *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
+   required number of bytes is too large to store.  */
+static int
+yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
+                yytype_int16 *yyssp, int yytoken)
+{
+  YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]);
+  YYSIZE_T yysize = yysize0;
+  YYSIZE_T yysize1;
+  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+  /* Internationalized format string. */
+  const char *yyformat = 0;
+  /* Arguments of yyformat. */
+  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+  /* Number of reported tokens (one for the "unexpected", one per
+     "expected"). */
+  int yycount = 0;
+
+  /* There are many possibilities here to consider:
+     - Assume YYFAIL is not used.  It's too flawed to consider.  See
+       <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
+       for details.  YYERROR is fine as it does not invoke this
+       function.
+     - If this state is a consistent state with a default action, then
+       the only way this function was invoked is if the default action
+       is an error action.  In that case, don't check for expected
+       tokens because there are none.
+     - The only way there can be no lookahead present (in yychar) is if
+       this state is a consistent state with a default action.  Thus,
+       detecting the absence of a lookahead is sufficient to determine
+       that there is no unexpected or expected token to report.  In that
+       case, just report a simple "syntax error".
+     - Don't assume there isn't a lookahead just because this state is a
+       consistent state with a default action.  There might have been a
+       previous inconsistent state, consistent state with a non-default
+       action, or user semantic action that manipulated yychar.
+     - Of course, the expected token list depends on states to have
+       correct lookahead information, and it depends on the parser not
+       to perform extra reductions after fetching a lookahead from the
+       scanner and before detecting a syntax error.  Thus, state merging
+       (from LALR or IELR) and default reductions corrupt the expected
+       token list.  However, the list is correct for canonical LR with
+       one exception: it will still contain any token that will not be
+       accepted due to an error action in a later state.
+  */
+  if (yytoken != YYEMPTY)
     {
-      int yytype = YYTRANSLATE (yychar);
-      YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
-      YYSIZE_T yysize = yysize0;
-      YYSIZE_T yysize1;
-      int yysize_overflow = 0;
-      enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
-      char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
-      int yyx;
-
-# if 0
-      /* This is so xgettext sees the translatable formats that are
-        constructed on the fly.  */
-      YY_("syntax error, unexpected %s");
-      YY_("syntax error, unexpected %s, expecting %s");
-      YY_("syntax error, unexpected %s, expecting %s or %s");
-      YY_("syntax error, unexpected %s, expecting %s or %s or %s");
-      YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
-# endif
-      char *yyfmt;
-      char const *yyf;
-      static char const yyunexpected[] = "syntax error, unexpected %s";
-      static char const yyexpecting[] = ", expecting %s";
-      static char const yyor[] = " or %s";
-      char yyformat[sizeof yyunexpected
-                   + sizeof yyexpecting - 1
-                   + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
-                      * (sizeof yyor - 1))];
-      char const *yyprefix = yyexpecting;
-
-      /* 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 yycount = 1;
-
-      yyarg[0] = yytname[yytype];
-      yyfmt = yystpcpy (yyformat, yyunexpected);
-
-      for (yyx = yyxbegin; yyx < yyxend; ++yyx)
-       if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
-         {
-           if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
-             {
-               yycount = 1;
-               yysize = yysize0;
-               yyformat[sizeof yyunexpected - 1] = '\0';
-               break;
-             }
-           yyarg[yycount++] = yytname[yyx];
-           yysize1 = yysize + yytnamerr (0, yytname[yyx]);
-           yysize_overflow |= (yysize1 < yysize);
-           yysize = yysize1;
-           yyfmt = yystpcpy (yyfmt, yyprefix);
-           yyprefix = yyor;
-         }
+      int yyn = yypact[*yyssp];
+      yyarg[yycount++] = yytname[yytoken];
+      if (!yypact_value_is_default (yyn))
+        {
+          /* Start YYX at -YYN if negative to avoid negative indexes in
+             YYCHECK.  In other words, skip the first -YYN actions for
+             this state because they are default actions.  */
+          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 yyx;
+
+          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+            if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
+                && !yytable_value_is_error (yytable[yyx + yyn]))
+              {
+                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+                  {
+                    yycount = 1;
+                    yysize = yysize0;
+                    break;
+                  }
+                yyarg[yycount++] = yytname[yyx];
+                yysize1 = yysize + yytnamerr (0, yytname[yyx]);
+                if (! (yysize <= yysize1
+                       && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+                  return 2;
+                yysize = yysize1;
+              }
+        }
+    }
 
-      yyf = YY_(yyformat);
-      yysize1 = yysize + yystrlen (yyf);
-      yysize_overflow |= (yysize1 < yysize);
-      yysize = yysize1;
+  switch (yycount)
+    {
+# define YYCASE_(N, S)                      \
+      case N:                               \
+        yyformat = S;                       \
+      break
+      YYCASE_(0, YY_("syntax error"));
+      YYCASE_(1, YY_("syntax error, unexpected %s"));
+      YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
+      YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
+      YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
+      YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
+# undef YYCASE_
+    }
 
-      if (yysize_overflow)
-       return YYSIZE_MAXIMUM;
+  yysize1 = yysize + yystrlen (yyformat);
+  if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+    return 2;
+  yysize = yysize1;
 
-      if (yyresult)
-       {
-         /* Avoid sprintf, as that infringes on the user's name space.
-            Don't have undefined behavior even if the translation
-            produced a string with the wrong number of "%s"s.  */
-         char *yyp = yyresult;
-         int yyi = 0;
-         while ((*yyp = *yyf) != '\0')
-           {
-             if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
-               {
-                 yyp += yytnamerr (yyp, yyarg[yyi++]);
-                 yyf += 2;
-               }
-             else
-               {
-                 yyp++;
-                 yyf++;
-               }
-           }
-       }
-      return yysize;
+  if (*yymsg_alloc < yysize)
+    {
+      *yymsg_alloc = 2 * yysize;
+      if (! (yysize <= *yymsg_alloc
+             && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
+        *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
+      return 1;
     }
+
+  /* Avoid sprintf, as that infringes on the user's name space.
+     Don't have undefined behavior even if the translation
+     produced a string with the wrong number of "%s"s.  */
+  {
+    char *yyp = *yymsg;
+    int yyi = 0;
+    while ((*yyp = *yyformat) != '\0')
+      if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
+        {
+          yyp += yytnamerr (yyp, yyarg[yyi++]);
+          yyformat += 2;
+        }
+      else
+        {
+          yyp++;
+          yyformat++;
+        }
+  }
+  return 0;
 }
 #endif /* YYERROR_VERBOSE */
-\f
 
 /*-----------------------------------------------.
 | Release the memory associated to this symbol.  |
@@ -1297,14 +1315,14 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
 #if (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
 static void
-yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, yyscan_t                 scanner)
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, void *scanner)
 #else
 static void
 yydestruct (yymsg, yytype, yyvaluep, scanner)
     const char *yymsg;
     int yytype;
     YYSTYPE *yyvaluep;
-    yyscan_t                 scanner;
+    void *scanner;
 #endif
 {
   YYUSE (yyvaluep);
@@ -1317,195 +1335,341 @@ yydestruct (yymsg, yytype, yyvaluep, scanner)
   switch (yytype)
     {
       case 5: /* "HELP_TOPIC" */
-#line 172 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 167 "parser.y"
        { free((yyvaluep->str));                     };
-#line 1323 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1345 "parser.cpp"
        break;
       case 8: /* "STR" */
-#line 172 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 167 "parser.y"
        { free((yyvaluep->str));                     };
-#line 1328 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1354 "parser.cpp"
        break;
       case 9: /* "IDENTIFIER" */
-#line 172 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 167 "parser.y"
        { free((yyvaluep->str));                     };
-#line 1333 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1363 "parser.cpp"
        break;
       case 25: /* "PARAM" */
-#line 173 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 168 "parser.y"
        { if((yyvaluep->str)) free((yyvaluep->str));              };
-#line 1338 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1372 "parser.cpp"
        break;
       case 28: /* "CMP_OP" */
-#line 172 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 167 "parser.y"
        { free((yyvaluep->str));                     };
-#line 1343 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1381 "parser.cpp"
        break;
       case 51: /* "command" */
-#line 174 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 169 "parser.y"
        { if((yyvaluep->sel)) _gmx_selelem_free((yyvaluep->sel)); };
-#line 1348 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1390 "parser.cpp"
        break;
       case 52: /* "cmd_plain" */
-#line 174 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 169 "parser.y"
        { if((yyvaluep->sel)) _gmx_selelem_free((yyvaluep->sel)); };
-#line 1353 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1399 "parser.cpp"
        break;
       case 54: /* "help_topic" */
-#line 180 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 175 "parser.y"
        { _gmx_selexpr_free_values((yyvaluep->val)); };
-#line 1358 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1408 "parser.cpp"
        break;
       case 55: /* "selection" */
-#line 175 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 170 "parser.y"
        { _gmx_selelem_free_chain((yyvaluep->sel));  };
-#line 1363 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1417 "parser.cpp"
        break;
       case 59: /* "string" */
-#line 172 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 167 "parser.y"
        { free((yyvaluep->str));                     };
-#line 1368 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1426 "parser.cpp"
        break;
       case 60: /* "sel_expr" */
-#line 176 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 171 "parser.y"
        { _gmx_selelem_free((yyvaluep->sel));        };
-#line 1373 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1435 "parser.cpp"
        break;
       case 62: /* "num_expr" */
-#line 176 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 171 "parser.y"
        { _gmx_selelem_free((yyvaluep->sel));        };
-#line 1378 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1444 "parser.cpp"
        break;
       case 63: /* "str_expr" */
-#line 176 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 171 "parser.y"
        { _gmx_selelem_free((yyvaluep->sel));        };
-#line 1383 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1453 "parser.cpp"
        break;
       case 64: /* "pos_expr" */
-#line 176 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 171 "parser.y"
        { _gmx_selelem_free((yyvaluep->sel));        };
-#line 1388 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1462 "parser.cpp"
        break;
       case 65: /* "method_params" */
-#line 177 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 172 "parser.y"
        { _gmx_selexpr_free_params((yyvaluep->param)); };
-#line 1393 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1471 "parser.cpp"
        break;
       case 66: /* "method_param_list" */
-#line 177 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 172 "parser.y"
        { _gmx_selexpr_free_params((yyvaluep->param)); };
-#line 1398 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1480 "parser.cpp"
        break;
       case 67: /* "method_param" */
-#line 177 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 172 "parser.y"
        { _gmx_selexpr_free_params((yyvaluep->param)); };
-#line 1403 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1489 "parser.cpp"
        break;
       case 68: /* "value_list" */
-#line 178 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 173 "parser.y"
        { _gmx_selexpr_free_values((yyvaluep->val)); };
-#line 1408 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1498 "parser.cpp"
        break;
       case 69: /* "value_list_contents" */
-#line 178 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 173 "parser.y"
        { _gmx_selexpr_free_values((yyvaluep->val)); };
-#line 1413 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1507 "parser.cpp"
        break;
       case 70: /* "basic_value_list" */
-#line 179 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 174 "parser.y"
        { _gmx_selexpr_free_values((yyvaluep->val)); };
-#line 1418 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1516 "parser.cpp"
        break;
       case 71: /* "basic_value_list_contents" */
-#line 179 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 174 "parser.y"
        { _gmx_selexpr_free_values((yyvaluep->val)); };
-#line 1423 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1525 "parser.cpp"
        break;
       case 72: /* "value_item" */
-#line 178 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 173 "parser.y"
        { _gmx_selexpr_free_values((yyvaluep->val)); };
-#line 1428 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1534 "parser.cpp"
        break;
       case 73: /* "basic_value_item" */
-#line 179 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 174 "parser.y"
        { _gmx_selexpr_free_values((yyvaluep->val)); };
-#line 1433 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1543 "parser.cpp"
        break;
       case 74: /* "value_item_range" */
-#line 178 "parser.y"
+
+/* Line 1391 of yacc.c  */
+#line 173 "parser.y"
        { _gmx_selexpr_free_values((yyvaluep->val)); };
-#line 1438 "parser.cpp"
+
+/* Line 1391 of yacc.c  */
+#line 1552 "parser.cpp"
        break;
 
       default:
        break;
     }
 }
-\f
 
-/* Prevent warnings from -Wmissing-prototypes.  */
 
-#ifdef YYPARSE_PARAM
-#if defined __STDC__ || defined __cplusplus
-int yyparse (void *YYPARSE_PARAM);
-#else
-int yyparse ();
-#endif
-#else /* ! YYPARSE_PARAM */
-#if defined __STDC__ || defined __cplusplus
-int yyparse (yyscan_t                 scanner);
-#else
-int yyparse ();
-#endif
-#endif /* ! YYPARSE_PARAM */
+struct yypstate
+  {
+    /* Number of syntax errors so far.  */
+    int yynerrs;
 
+    int yystate;
+    /* Number of tokens to shift before error messages enabled.  */
+    int yyerrstatus;
 
+    /* The stacks and their tools:
+       `yyss': related to states.
+       `yyvs': related to semantic values.
 
+       Refer to the stacks thru separate pointers, to allow yyoverflow
+       to reallocate them elsewhere.  */
 
+    /* The state stack.  */
+    yytype_int16 yyssa[YYINITDEPTH];
+    yytype_int16 *yyss;
+    yytype_int16 *yyssp;
 
+    /* The semantic value stack.  */
+    YYSTYPE yyvsa[YYINITDEPTH];
+    YYSTYPE *yyvs;
+    YYSTYPE *yyvsp;
 
-/*----------.
-| yyparse.  |
-`----------*/
+    YYSIZE_T yystacksize;
+    /* Used to determine if this is the first time this instance has
+       been used.  */
+    int yynew;
+  };
 
-#ifdef YYPARSE_PARAM
+/* Initialize the parser data structure.  */
 #if (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
-int
-yyparse (void *YYPARSE_PARAM)
+yypstate *
+yypstate_new (void)
 #else
-int
-yyparse (YYPARSE_PARAM)
-    void *YYPARSE_PARAM;
+yypstate *
+yypstate_new ()
+
 #endif
-#else /* ! YYPARSE_PARAM */
+{
+  yypstate *yyps;
+  yyps = (yypstate *) malloc (sizeof *yyps);
+  if (!yyps)
+    return 0;
+  yyps->yynew = 1;
+  return yyps;
+}
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+void
+yypstate_delete (yypstate *yyps)
+#else
+void
+yypstate_delete (yyps)
+    yypstate *yyps;
+#endif
+{
+#ifndef yyoverflow
+  /* If the stack was reallocated but the parse did not complete, then the
+     stack still needs to be freed.  */
+  if (!yyps->yynew && yyps->yyss != yyps->yyssa)
+    YYSTACK_FREE (yyps->yyss);
+#endif
+  free (yyps);
+}
+
+#define _gmx_sel_yynerrs yyps->_gmx_sel_yynerrs
+#define yystate yyps->yystate
+#define yyerrstatus yyps->yyerrstatus
+#define yyssa yyps->yyssa
+#define yyss yyps->yyss
+#define yyssp yyps->yyssp
+#define yyvsa yyps->yyvsa
+#define yyvs yyps->yyvs
+#define yyvsp yyps->yyvsp
+#define yystacksize yyps->yystacksize
+
+
+/*---------------.
+| yypush_parse.  |
+`---------------*/
+
 #if (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
 int
-yyparse (yyscan_t                 scanner)
+yypush_parse (yypstate *yyps, int yypushed_char, YYSTYPE const *yypushed_val, void *scanner)
 #else
 int
-yyparse (scanner)
-    yyscan_t                 scanner;
-#endif
+yypush_parse (yyps, yypushed_char, yypushed_val, scanner)
+    yypstate *yyps;
+    int yypushed_char;
+    YYSTYPE const *yypushed_val;
+    void *scanner;
 #endif
 {
-  /* The look-ahead symbol.  */
+/* The lookahead symbol.  */
 int yychar;
 
-/* The semantic value of the look-ahead symbol.  */
+/* The semantic value of the lookahead symbol.  */
 YYSTYPE yylval;
 
-/* Number of syntax errors so far.  */
-int yynerrs;
-
-  int yystate;
   int yyn;
   int yyresult;
-  /* Number of tokens to shift before error messages enabled.  */
-  int yyerrstatus;
-  /* Look-ahead token as an internal (translated) token number.  */
-  int yytoken = 0;
+  /* Lookahead token as an internal (translated) token number.  */
+  int yytoken;
+  /* The variables used to return semantic value and location from the
+     action routines.  */
+  YYSTYPE yyval;
+
 #if YYERROR_VERBOSE
   /* Buffer for error messages, and its allocated size.  */
   char yymsgbuf[128];
@@ -1513,51 +1677,34 @@ int yynerrs;
   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
 #endif
 
-  /* Three stacks and their tools:
-     `yyss': related to states,
-     `yyvs': related to semantic values,
-     `yyls': related to locations.
-
-     Refer to the stacks thru separate pointers, to allow yyoverflow
-     to reallocate them elsewhere.  */
-
-  /* The state stack.  */
-  yytype_int16 yyssa[YYINITDEPTH];
-  yytype_int16 *yyss = yyssa;
-  yytype_int16 *yyssp;
-
-  /* The semantic value stack.  */
-  YYSTYPE yyvsa[YYINITDEPTH];
-  YYSTYPE *yyvs = yyvsa;
-  YYSTYPE *yyvsp;
-
-
-
 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
 
-  YYSIZE_T yystacksize = YYINITDEPTH;
-
-  /* The variables used to return semantic value and location from the
-     action routines.  */
-  YYSTYPE yyval;
-
-
   /* The number of symbols on the RHS of the reduced rule.
      Keep to zero when no symbol should be popped.  */
   int yylen = 0;
 
+  if (!yyps->yynew)
+    {
+      yyn = yypact[yystate];
+      goto yyread_pushed_token;
+    }
+
+  yytoken = 0;
+  yyss = yyssa;
+  yyvs = yyvsa;
+  yystacksize = YYINITDEPTH;
+
   YYDPRINTF ((stderr, "Starting parse\n"));
 
   yystate = 0;
   yyerrstatus = 0;
   yynerrs = 0;
-  yychar = YYEMPTY;            /* Cause a token to be read.  */
+  yychar = YYEMPTY; /* Cause a token to be read.  */
 
   /* Initialize stack pointers.
      Waste one element of value and location stack
      so that they stay on the same level as the state stack.
      The wasted elements are never initialized.  */
-
   yyssp = yyss;
   yyvsp = yyvs;
 
@@ -1587,7 +1734,6 @@ int yynerrs;
        YYSTYPE *yyvs1 = yyvs;
        yytype_int16 *yyss1 = yyss;
 
-
        /* Each stack pointer address is followed by the size of the
           data in use in that stack, in bytes.  This used to be a
           conditional around just the two extra args, but that might
@@ -1595,7 +1741,6 @@ int yynerrs;
        yyoverflow (YY_("memory exhausted"),
                    &yyss1, yysize * sizeof (*yyssp),
                    &yyvs1, yysize * sizeof (*yyvsp),
-
                    &yystacksize);
 
        yyss = yyss1;
@@ -1618,9 +1763,8 @@ int yynerrs;
          (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
        if (! yyptr)
          goto yyexhaustedlab;
-       YYSTACK_RELOCATE (yyss);
-       YYSTACK_RELOCATE (yyvs);
-
+       YYSTACK_RELOCATE (yyss_alloc, yyss);
+       YYSTACK_RELOCATE (yyvs_alloc, yyvs);
 #  undef YYSTACK_RELOCATE
        if (yyss1 != yyssa)
          YYSTACK_FREE (yyss1);
@@ -1631,7 +1775,6 @@ int yynerrs;
       yyssp = yyss + yysize - 1;
       yyvsp = yyvs + yysize - 1;
 
-
       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
                  (unsigned long int) yystacksize));
 
@@ -1641,6 +1784,9 @@ int yynerrs;
 
   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
 
+  if (yystate == YYFINAL)
+    YYACCEPT;
+
   goto yybackup;
 
 /*-----------.
@@ -1649,20 +1795,30 @@ int yynerrs;
 yybackup:
 
   /* Do appropriate processing given the current state.  Read a
-     look-ahead token if we need one and don't already have one.  */
+     lookahead token if we need one and don't already have one.  */
 
-  /* First try to decide what to do without reference to look-ahead token.  */
+  /* First try to decide what to do without reference to lookahead token.  */
   yyn = yypact[yystate];
-  if (yyn == YYPACT_NINF)
+  if (yypact_value_is_default (yyn))
     goto yydefault;
 
-  /* Not known => get a look-ahead token if don't already have one.  */
+  /* Not known => get a lookahead token if don't already have one.  */
 
-  /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
+  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
   if (yychar == YYEMPTY)
     {
+      if (!yyps->yynew)
+        {
+          YYDPRINTF ((stderr, "Return for a new token:\n"));
+          yyresult = YYPUSH_MORE;
+          goto yypushreturn;
+        }
+      yyps->yynew = 0;
+yyread_pushed_token:
       YYDPRINTF ((stderr, "Reading a token: "));
-      yychar = YYLEX;
+      yychar = yypushed_char;
+      if (yypushed_val)
+        yylval = *yypushed_val;
     }
 
   if (yychar <= YYEOF)
@@ -1684,26 +1840,22 @@ yybackup:
   yyn = yytable[yyn];
   if (yyn <= 0)
     {
-      if (yyn == 0 || yyn == YYTABLE_NINF)
-       goto yyerrlab;
+      if (yytable_value_is_error (yyn))
+        goto yyerrlab;
       yyn = -yyn;
       goto yyreduce;
     }
 
-  if (yyn == YYFINAL)
-    YYACCEPT;
-
   /* Count tokens shifted since error; after three, turn off error
      status.  */
   if (yyerrstatus)
     yyerrstatus--;
 
-  /* Shift the look-ahead token.  */
+  /* Shift the lookahead token.  */
   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
 
-  /* Discard the shifted token unless it is eof.  */
-  if (yychar != YYEOF)
-    yychar = YYEMPTY;
+  /* Discard the shifted token.  */
+  yychar = YYEMPTY;
 
   yystate = yyn;
   *++yyvsp = yylval;
@@ -1743,26 +1895,34 @@ yyreduce:
   switch (yyn)
     {
         case 2:
-#line 194 "parser.y"
-    { (yyval.sel) = NULL ;}
+
+/* Line 1806 of yacc.c  */
+#line 188 "parser.y"
+    { (yyval.sel) = NULL; }
     break;
 
   case 3:
-#line 196 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 190 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_append_selection((yyvsp[(2) - (2)].sel), (yyvsp[(1) - (2)].sel), scanner);
                  if (_gmx_sel_parser_should_finish(scanner))
                      YYACCEPT;
-             ;}
+             }
     break;
 
   case 4:
-#line 204 "parser.y"
-    { (yyval.sel) = (yyvsp[(1) - (2)].sel); ;}
+
+/* Line 1806 of yacc.c  */
+#line 198 "parser.y"
+    { (yyval.sel) = (yyvsp[(1) - (2)].sel); }
     break;
 
   case 5:
-#line 206 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 200 "parser.y"
     {
                  (yyval.sel) = NULL;
                  _gmx_selparser_error(scanner, "invalid selection '%s'",
@@ -1777,24 +1937,30 @@ yyreduce:
                  {
                      YYABORT;
                  }
-             ;}
+             }
     break;
 
   case 6:
-#line 225 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 219 "parser.y"
     {
                  (yyval.sel) = NULL;
                  _gmx_sel_handle_empty_cmd(scanner);
-             ;}
+             }
     break;
 
   case 7:
-#line 229 "parser.y"
-    { (yyval.sel) = NULL; ;}
+
+/* Line 1806 of yacc.c  */
+#line 223 "parser.y"
+    { (yyval.sel) = NULL; }
     break;
 
   case 8:
-#line 231 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 225 "parser.y"
     {
                  t_selelem *s, *p;
                  s = _gmx_sel_init_group_by_id((yyvsp[(1) - (1)].i), scanner);
@@ -1802,11 +1968,13 @@ yyreduce:
                  p = _gmx_sel_init_position(s, NULL, scanner);
                  if (p == NULL) YYERROR;
                  (yyval.sel) = _gmx_sel_init_selection(strdup(s->name), p, scanner);
-             ;}
+             }
     break;
 
   case 9:
-#line 240 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 234 "parser.y"
     {
                  t_selelem *s, *p;
                  s = _gmx_sel_init_group_by_name((yyvsp[(1) - (1)].str), scanner);
@@ -1815,513 +1983,687 @@ yyreduce:
                  p = _gmx_sel_init_position(s, NULL, scanner);
                  if (p == NULL) YYERROR;
                  (yyval.sel) = _gmx_sel_init_selection(strdup(s->name), p, scanner);
-             ;}
+             }
     break;
 
   case 10:
-#line 250 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_selection(NULL, (yyvsp[(1) - (1)].sel), scanner); ;}
+
+/* Line 1806 of yacc.c  */
+#line 244 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_selection(NULL, (yyvsp[(1) - (1)].sel), scanner); }
     break;
 
   case 11:
-#line 252 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_selection((yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].sel), scanner);   ;}
+
+/* Line 1806 of yacc.c  */
+#line 246 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_selection((yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].sel), scanner);   }
     break;
 
   case 12:
-#line 254 "parser.y"
-    { (yyval.sel) = _gmx_sel_assign_variable((yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].sel), scanner);  ;}
+
+/* Line 1806 of yacc.c  */
+#line 248 "parser.y"
+    { (yyval.sel) = _gmx_sel_assign_variable((yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].sel), scanner);  }
     break;
 
   case 13:
-#line 256 "parser.y"
-    { (yyval.sel) = _gmx_sel_assign_variable((yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].sel), scanner);  ;}
+
+/* Line 1806 of yacc.c  */
+#line 250 "parser.y"
+    { (yyval.sel) = _gmx_sel_assign_variable((yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].sel), scanner);  }
     break;
 
   case 14:
-#line 258 "parser.y"
-    { (yyval.sel) = _gmx_sel_assign_variable((yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].sel), scanner);  ;}
+
+/* Line 1806 of yacc.c  */
+#line 252 "parser.y"
+    { (yyval.sel) = _gmx_sel_assign_variable((yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].sel), scanner);  }
     break;
 
   case 15:
-#line 264 "parser.y"
-    { _gmx_sel_handle_help_cmd(process_value_list((yyvsp[(2) - (2)].val), NULL), scanner); ;}
+
+/* Line 1806 of yacc.c  */
+#line 258 "parser.y"
+    { _gmx_sel_handle_help_cmd(process_value_list((yyvsp[(2) - (2)].val), NULL), scanner); }
     break;
 
   case 16:
-#line 267 "parser.y"
-    { (yyval.val) = NULL; ;}
+
+/* Line 1806 of yacc.c  */
+#line 261 "parser.y"
+    { (yyval.val) = NULL; }
     break;
 
   case 17:
-#line 269 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 263 "parser.y"
     {
                  (yyval.val) = _gmx_selexpr_create_value(STR_VALUE);
                  (yyval.val)->u.s = (yyvsp[(2) - (2)].str); (yyval.val)->next = (yyvsp[(1) - (2)].val);
-             ;}
+             }
     break;
 
   case 18:
-#line 276 "parser.y"
-    { (yyval.sel) = (yyvsp[(1) - (1)].sel); ;}
+
+/* Line 1806 of yacc.c  */
+#line 270 "parser.y"
+    { (yyval.sel) = (yyvsp[(1) - (1)].sel); }
     break;
 
   case 19:
-#line 278 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 272 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_position((yyvsp[(1) - (1)].sel), NULL, scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 20:
-#line 282 "parser.y"
-    { (yyval.sel) = (yyvsp[(2) - (3)].sel); ;}
+
+/* Line 1806 of yacc.c  */
+#line 276 "parser.y"
+    { (yyval.sel) = (yyvsp[(2) - (3)].sel); }
     break;
 
   case 21:
-#line 284 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 278 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_modifier((yyvsp[(2) - (3)].meth), (yyvsp[(3) - (3)].param), (yyvsp[(1) - (3)].sel), scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 22:
-#line 295 "parser.y"
-    { (yyval.i) = (yyvsp[(1) - (1)].i); ;}
+
+/* Line 1806 of yacc.c  */
+#line 289 "parser.y"
+    { (yyval.i) = (yyvsp[(1) - (1)].i); }
     break;
 
   case 23:
-#line 296 "parser.y"
-    { (yyval.i) = -(yyvsp[(2) - (2)].i); ;}
+
+/* Line 1806 of yacc.c  */
+#line 290 "parser.y"
+    { (yyval.i) = -(yyvsp[(2) - (2)].i); }
     break;
 
   case 24:
-#line 300 "parser.y"
-    { (yyval.r) = (yyvsp[(1) - (1)].r); ;}
+
+/* Line 1806 of yacc.c  */
+#line 294 "parser.y"
+    { (yyval.r) = (yyvsp[(1) - (1)].r); }
     break;
 
   case 25:
-#line 301 "parser.y"
-    { (yyval.r) = -(yyvsp[(2) - (2)].r); ;}
+
+/* Line 1806 of yacc.c  */
+#line 295 "parser.y"
+    { (yyval.r) = -(yyvsp[(2) - (2)].r); }
     break;
 
   case 26:
-#line 304 "parser.y"
-    { (yyval.r) = (yyvsp[(1) - (1)].i); ;}
+
+/* Line 1806 of yacc.c  */
+#line 298 "parser.y"
+    { (yyval.r) = (yyvsp[(1) - (1)].i); }
     break;
 
   case 27:
-#line 305 "parser.y"
-    { (yyval.r) = (yyvsp[(1) - (1)].r); ;}
+
+/* Line 1806 of yacc.c  */
+#line 299 "parser.y"
+    { (yyval.r) = (yyvsp[(1) - (1)].r); }
     break;
 
   case 28:
-#line 308 "parser.y"
-    { (yyval.str) = (yyvsp[(1) - (1)].str); ;}
+
+/* Line 1806 of yacc.c  */
+#line 302 "parser.y"
+    { (yyval.str) = (yyvsp[(1) - (1)].str); }
     break;
 
   case 29:
-#line 309 "parser.y"
-    { (yyval.str) = (yyvsp[(1) - (1)].str); ;}
+
+/* Line 1806 of yacc.c  */
+#line 303 "parser.y"
+    { (yyval.str) = (yyvsp[(1) - (1)].str); }
     break;
 
   case 30:
-#line 318 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 312 "parser.y"
     {
                  (yyval.sel) = _gmx_selelem_create(SEL_BOOLEAN);
                  (yyval.sel)->u.boolt = BOOL_NOT;
                  (yyval.sel)->child = (yyvsp[(2) - (2)].sel);
-             ;}
+             }
     break;
 
   case 31:
-#line 324 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 318 "parser.y"
     {
                  (yyval.sel) = _gmx_selelem_create(SEL_BOOLEAN);
                  (yyval.sel)->u.boolt = BOOL_AND;
                  (yyval.sel)->child = (yyvsp[(1) - (3)].sel); (yyval.sel)->child->next = (yyvsp[(3) - (3)].sel);
-             ;}
+             }
     break;
 
   case 32:
-#line 330 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 324 "parser.y"
     {
                  (yyval.sel) = _gmx_selelem_create(SEL_BOOLEAN);
                  (yyval.sel)->u.boolt = BOOL_OR;
                  (yyval.sel)->child = (yyvsp[(1) - (3)].sel); (yyval.sel)->child->next = (yyvsp[(3) - (3)].sel);
-             ;}
+             }
     break;
 
   case 33:
-#line 341 "parser.y"
-    { (yyval.sel) = (yyvsp[(2) - (3)].sel); ;}
+
+/* Line 1806 of yacc.c  */
+#line 335 "parser.y"
+    { (yyval.sel) = (yyvsp[(2) - (3)].sel); }
     break;
 
   case 34:
-#line 346 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 340 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_comparison((yyvsp[(1) - (3)].sel), (yyvsp[(3) - (3)].sel), (yyvsp[(2) - (3)].str), scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 35:
-#line 354 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 348 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_group_by_name((yyvsp[(2) - (2)].str), scanner);
                  free((yyvsp[(2) - (2)].str));
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 36:
-#line 360 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 354 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_group_by_id((yyvsp[(2) - (2)].i), scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 37:
-#line 367 "parser.y"
-    { (yyval.str) = NULL; ;}
+
+/* Line 1806 of yacc.c  */
+#line 361 "parser.y"
+    { (yyval.str) = NULL; }
     break;
 
   case 38:
-#line 368 "parser.y"
-    { (yyval.str) = (yyvsp[(1) - (1)].str);   ;}
+
+/* Line 1806 of yacc.c  */
+#line 362 "parser.y"
+    { (yyval.str) = (yyvsp[(1) - (1)].str);   }
     break;
 
   case 39:
-#line 373 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 367 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_keyword((yyvsp[(2) - (2)].meth), NULL, (yyvsp[(1) - (2)].str), scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 40:
-#line 378 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 372 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_keyword((yyvsp[(2) - (3)].meth), process_value_list((yyvsp[(3) - (3)].val), NULL), (yyvsp[(1) - (3)].str), scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 41:
-#line 383 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 377 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_keyword((yyvsp[(2) - (3)].meth), process_value_list((yyvsp[(3) - (3)].val), NULL), (yyvsp[(1) - (3)].str), scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 42:
-#line 391 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 385 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_method((yyvsp[(2) - (3)].meth), (yyvsp[(3) - (3)].param), (yyvsp[(1) - (3)].str), scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 43:
-#line 403 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 397 "parser.y"
     {
                  (yyval.sel) = _gmx_selelem_create(SEL_CONST);
                  _gmx_selelem_set_vtype((yyval.sel), INT_VALUE);
                  _gmx_selvalue_reserve(&(yyval.sel)->v, 1);
                  (yyval.sel)->v.u.i[0] = (yyvsp[(1) - (1)].i);
-             ;}
+             }
     break;
 
   case 44:
-#line 410 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 404 "parser.y"
     {
                  (yyval.sel) = _gmx_selelem_create(SEL_CONST);
                  _gmx_selelem_set_vtype((yyval.sel), REAL_VALUE);
                  _gmx_selvalue_reserve(&(yyval.sel)->v, 1);
                  (yyval.sel)->v.u.r[0] = (yyvsp[(1) - (1)].r);
-             ;}
+             }
     break;
 
   case 45:
-#line 420 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 414 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_keyword((yyvsp[(2) - (2)].meth), NULL, (yyvsp[(1) - (2)].str), scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 46:
-#line 425 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 419 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_method((yyvsp[(2) - (3)].meth), (yyvsp[(3) - (3)].param), (yyvsp[(1) - (3)].str), scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 47:
-#line 433 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(1) - (3)].sel), (yyvsp[(3) - (3)].sel), '+', scanner); ;}
+
+/* Line 1806 of yacc.c  */
+#line 427 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(1) - (3)].sel), (yyvsp[(3) - (3)].sel), '+', scanner); }
     break;
 
   case 48:
-#line 435 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(1) - (3)].sel), (yyvsp[(3) - (3)].sel), '-', scanner); ;}
+
+/* Line 1806 of yacc.c  */
+#line 429 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(1) - (3)].sel), (yyvsp[(3) - (3)].sel), '-', scanner); }
     break;
 
   case 49:
-#line 437 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(1) - (3)].sel), (yyvsp[(3) - (3)].sel), '*', scanner); ;}
+
+/* Line 1806 of yacc.c  */
+#line 431 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(1) - (3)].sel), (yyvsp[(3) - (3)].sel), '*', scanner); }
     break;
 
   case 50:
-#line 439 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(1) - (3)].sel), (yyvsp[(3) - (3)].sel), '/', scanner); ;}
+
+/* Line 1806 of yacc.c  */
+#line 433 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(1) - (3)].sel), (yyvsp[(3) - (3)].sel), '/', scanner); }
     break;
 
   case 51:
-#line 441 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(2) - (2)].sel), NULL, '-', scanner); ;}
+
+/* Line 1806 of yacc.c  */
+#line 435 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(2) - (2)].sel), NULL, '-', scanner); }
     break;
 
   case 52:
-#line 443 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(1) - (3)].sel), (yyvsp[(3) - (3)].sel), '^', scanner); ;}
+
+/* Line 1806 of yacc.c  */
+#line 437 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_arithmetic((yyvsp[(1) - (3)].sel), (yyvsp[(3) - (3)].sel), '^', scanner); }
     break;
 
   case 53:
-#line 444 "parser.y"
-    { (yyval.sel) = (yyvsp[(2) - (3)].sel); ;}
+
+/* Line 1806 of yacc.c  */
+#line 438 "parser.y"
+    { (yyval.sel) = (yyvsp[(2) - (3)].sel); }
     break;
 
   case 54:
-#line 452 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 446 "parser.y"
     {
                  (yyval.sel) = _gmx_selelem_create(SEL_CONST);
                  _gmx_selelem_set_vtype((yyval.sel), STR_VALUE);
                  _gmx_selvalue_reserve(&(yyval.sel)->v, 1);
                  (yyval.sel)->v.u.s[0] = (yyvsp[(1) - (1)].str);
-             ;}
+             }
     break;
 
   case 55:
-#line 459 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 453 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_keyword((yyvsp[(2) - (2)].meth), NULL, (yyvsp[(1) - (2)].str), scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 56:
-#line 471 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_const_position((yyvsp[(2) - (7)].r), (yyvsp[(4) - (7)].r), (yyvsp[(6) - (7)].r)); ;}
+
+/* Line 1806 of yacc.c  */
+#line 465 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_const_position((yyvsp[(2) - (7)].r), (yyvsp[(4) - (7)].r), (yyvsp[(6) - (7)].r)); }
     break;
 
   case 57:
-#line 475 "parser.y"
-    { (yyval.sel) = (yyvsp[(2) - (3)].sel); ;}
+
+/* Line 1806 of yacc.c  */
+#line 469 "parser.y"
+    { (yyval.sel) = (yyvsp[(2) - (3)].sel); }
     break;
 
   case 58:
-#line 480 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 474 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_method((yyvsp[(1) - (2)].meth), (yyvsp[(2) - (2)].param), NULL, scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 59:
-#line 488 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 482 "parser.y"
     {
                  (yyval.sel) = _gmx_sel_init_position((yyvsp[(3) - (3)].sel), (yyvsp[(1) - (3)].str), scanner);
                  if ((yyval.sel) == NULL) YYERROR;
-             ;}
+             }
     break;
 
   case 60:
-#line 499 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_variable_ref((yyvsp[(1) - (1)].sel)); ;}
+
+/* Line 1806 of yacc.c  */
+#line 493 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_variable_ref((yyvsp[(1) - (1)].sel)); }
     break;
 
   case 61:
-#line 503 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_variable_ref((yyvsp[(1) - (1)].sel)); ;}
+
+/* Line 1806 of yacc.c  */
+#line 497 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_variable_ref((yyvsp[(1) - (1)].sel)); }
     break;
 
   case 62:
-#line 507 "parser.y"
-    { (yyval.sel) = _gmx_sel_init_variable_ref((yyvsp[(1) - (1)].sel)); ;}
+
+/* Line 1806 of yacc.c  */
+#line 501 "parser.y"
+    { (yyval.sel) = _gmx_sel_init_variable_ref((yyvsp[(1) - (1)].sel)); }
     break;
 
   case 63:
-#line 516 "parser.y"
-    { (yyval.param) = process_param_list((yyvsp[(1) - (1)].param)); ;}
+
+/* Line 1806 of yacc.c  */
+#line 510 "parser.y"
+    { (yyval.param) = process_param_list((yyvsp[(1) - (1)].param)); }
     break;
 
   case 64:
-#line 518 "parser.y"
-    { (yyval.param) = process_param_list((yyvsp[(1) - (2)].param)); ;}
+
+/* Line 1806 of yacc.c  */
+#line 512 "parser.y"
+    { (yyval.param) = process_param_list((yyvsp[(1) - (2)].param)); }
     break;
 
   case 65:
-#line 522 "parser.y"
-    { (yyval.param) = NULL;              ;}
+
+/* Line 1806 of yacc.c  */
+#line 516 "parser.y"
+    { (yyval.param) = NULL;              }
     break;
 
   case 66:
-#line 524 "parser.y"
-    { (yyvsp[(2) - (2)].param)->next = (yyvsp[(1) - (2)].param); (yyval.param) = (yyvsp[(2) - (2)].param); ;}
+
+/* Line 1806 of yacc.c  */
+#line 518 "parser.y"
+    { (yyvsp[(2) - (2)].param)->next = (yyvsp[(1) - (2)].param); (yyval.param) = (yyvsp[(2) - (2)].param); }
     break;
 
   case 67:
-#line 529 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 523 "parser.y"
     {
                  (yyval.param) = _gmx_selexpr_create_param((yyvsp[(1) - (2)].str));
                  (yyval.param)->value = process_value_list((yyvsp[(2) - (2)].val), &(yyval.param)->nval);
-             ;}
+             }
     break;
 
   case 68:
-#line 535 "parser.y"
-    { (yyval.val) = NULL; ;}
+
+/* Line 1806 of yacc.c  */
+#line 529 "parser.y"
+    { (yyval.val) = NULL; }
     break;
 
   case 69:
-#line 536 "parser.y"
-    { (yyval.val) = (yyvsp[(1) - (1)].val);   ;}
+
+/* Line 1806 of yacc.c  */
+#line 530 "parser.y"
+    { (yyval.val) = (yyvsp[(1) - (1)].val);   }
     break;
 
   case 70:
-#line 537 "parser.y"
-    { (yyval.val) = (yyvsp[(2) - (3)].val);   ;}
+
+/* Line 1806 of yacc.c  */
+#line 531 "parser.y"
+    { (yyval.val) = (yyvsp[(2) - (3)].val);   }
     break;
 
   case 71:
-#line 541 "parser.y"
-    { (yyval.val) = (yyvsp[(1) - (1)].val); ;}
+
+/* Line 1806 of yacc.c  */
+#line 535 "parser.y"
+    { (yyval.val) = (yyvsp[(1) - (1)].val); }
     break;
 
   case 72:
-#line 543 "parser.y"
-    { (yyvsp[(2) - (2)].val)->next = (yyvsp[(1) - (2)].val); (yyval.val) = (yyvsp[(2) - (2)].val); ;}
+
+/* Line 1806 of yacc.c  */
+#line 537 "parser.y"
+    { (yyvsp[(2) - (2)].val)->next = (yyvsp[(1) - (2)].val); (yyval.val) = (yyvsp[(2) - (2)].val); }
     break;
 
   case 73:
-#line 545 "parser.y"
-    { (yyvsp[(3) - (3)].val)->next = (yyvsp[(1) - (3)].val); (yyval.val) = (yyvsp[(3) - (3)].val); ;}
+
+/* Line 1806 of yacc.c  */
+#line 539 "parser.y"
+    { (yyvsp[(3) - (3)].val)->next = (yyvsp[(1) - (3)].val); (yyval.val) = (yyvsp[(3) - (3)].val); }
     break;
 
   case 74:
-#line 549 "parser.y"
-    { (yyval.val) = (yyvsp[(1) - (1)].val); ;}
+
+/* Line 1806 of yacc.c  */
+#line 543 "parser.y"
+    { (yyval.val) = (yyvsp[(1) - (1)].val); }
     break;
 
   case 75:
-#line 550 "parser.y"
-    { (yyval.val) = (yyvsp[(2) - (3)].val); ;}
+
+/* Line 1806 of yacc.c  */
+#line 544 "parser.y"
+    { (yyval.val) = (yyvsp[(2) - (3)].val); }
     break;
 
   case 76:
-#line 554 "parser.y"
-    { (yyval.val) = (yyvsp[(1) - (1)].val); ;}
+
+/* Line 1806 of yacc.c  */
+#line 548 "parser.y"
+    { (yyval.val) = (yyvsp[(1) - (1)].val); }
     break;
 
   case 77:
-#line 556 "parser.y"
-    { (yyvsp[(2) - (2)].val)->next = (yyvsp[(1) - (2)].val); (yyval.val) = (yyvsp[(2) - (2)].val); ;}
+
+/* Line 1806 of yacc.c  */
+#line 550 "parser.y"
+    { (yyvsp[(2) - (2)].val)->next = (yyvsp[(1) - (2)].val); (yyval.val) = (yyvsp[(2) - (2)].val); }
     break;
 
   case 78:
-#line 558 "parser.y"
-    { (yyvsp[(3) - (3)].val)->next = (yyvsp[(1) - (3)].val); (yyval.val) = (yyvsp[(3) - (3)].val); ;}
+
+/* Line 1806 of yacc.c  */
+#line 552 "parser.y"
+    { (yyvsp[(3) - (3)].val)->next = (yyvsp[(1) - (3)].val); (yyval.val) = (yyvsp[(3) - (3)].val); }
     break;
 
   case 79:
-#line 562 "parser.y"
-    { (yyval.val) = _gmx_selexpr_create_value_expr((yyvsp[(1) - (1)].sel)); ;}
+
+/* Line 1806 of yacc.c  */
+#line 556 "parser.y"
+    { (yyval.val) = _gmx_selexpr_create_value_expr((yyvsp[(1) - (1)].sel)); }
     break;
 
   case 80:
-#line 564 "parser.y"
-    { (yyval.val) = _gmx_selexpr_create_value_expr((yyvsp[(1) - (1)].sel)); ;}
+
+/* Line 1806 of yacc.c  */
+#line 558 "parser.y"
+    { (yyval.val) = _gmx_selexpr_create_value_expr((yyvsp[(1) - (1)].sel)); }
     break;
 
   case 81:
-#line 566 "parser.y"
-    { (yyval.val) = _gmx_selexpr_create_value_expr((yyvsp[(1) - (1)].sel)); ;}
+
+/* Line 1806 of yacc.c  */
+#line 560 "parser.y"
+    { (yyval.val) = _gmx_selexpr_create_value_expr((yyvsp[(1) - (1)].sel)); }
     break;
 
   case 82:
-#line 568 "parser.y"
-    { (yyval.val) = _gmx_selexpr_create_value_expr((yyvsp[(1) - (1)].sel)); ;}
+
+/* Line 1806 of yacc.c  */
+#line 562 "parser.y"
+    { (yyval.val) = _gmx_selexpr_create_value_expr((yyvsp[(1) - (1)].sel)); }
     break;
 
   case 83:
-#line 569 "parser.y"
-    { (yyval.val) = (yyvsp[(1) - (1)].val); ;}
+
+/* Line 1806 of yacc.c  */
+#line 563 "parser.y"
+    { (yyval.val) = (yyvsp[(1) - (1)].val); }
     break;
 
   case 84:
-#line 574 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 568 "parser.y"
     {
                  (yyval.val) = _gmx_selexpr_create_value(INT_VALUE);
                  (yyval.val)->u.i.i1 = (yyval.val)->u.i.i2 = (yyvsp[(1) - (1)].i);
-             ;}
+             }
     break;
 
   case 85:
-#line 579 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 573 "parser.y"
     {
                  (yyval.val) = _gmx_selexpr_create_value(REAL_VALUE);
                  (yyval.val)->u.r.r1 = (yyval.val)->u.r.r2 = (yyvsp[(1) - (1)].r);
-             ;}
+             }
     break;
 
   case 86:
-#line 584 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 578 "parser.y"
     {
                  (yyval.val) = _gmx_selexpr_create_value(STR_VALUE);
                  (yyval.val)->u.s = (yyvsp[(1) - (1)].str);
-             ;}
+             }
     break;
 
   case 87:
-#line 588 "parser.y"
-    { (yyval.val) = (yyvsp[(1) - (1)].val); ;}
+
+/* Line 1806 of yacc.c  */
+#line 582 "parser.y"
+    { (yyval.val) = (yyvsp[(1) - (1)].val); }
     break;
 
   case 88:
-#line 593 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 587 "parser.y"
     {
                  (yyval.val) = _gmx_selexpr_create_value(INT_VALUE);
                  (yyval.val)->u.i.i1 = (yyvsp[(1) - (3)].i); (yyval.val)->u.i.i2 = (yyvsp[(3) - (3)].i);
-             ;}
+             }
     break;
 
   case 89:
-#line 598 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 592 "parser.y"
     {
                  (yyval.val) = _gmx_selexpr_create_value(REAL_VALUE);
                  (yyval.val)->u.r.r1 = (yyvsp[(1) - (3)].i); (yyval.val)->u.r.r2 = (yyvsp[(3) - (3)].r);
-             ;}
+             }
     break;
 
   case 90:
-#line 603 "parser.y"
+
+/* Line 1806 of yacc.c  */
+#line 597 "parser.y"
     {
                  (yyval.val) = _gmx_selexpr_create_value(REAL_VALUE);
                  (yyval.val)->u.r.r1 = (yyvsp[(1) - (3)].r); (yyval.val)->u.r.r2 = (yyvsp[(3) - (3)].r);
-             ;}
+             }
     break;
 
 
-/* Line 1267 of yacc.c.  */
-#line 2323 "parser.cpp"
+
+/* Line 1806 of yacc.c  */
+#line 2654 "parser.cpp"
       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 or
+     if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
+     incorrect destructor might then be invoked immediately.  In the
+     case of YYERROR or YYBACKUP, 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);
 
   YYPOPSTACK (yylen);
@@ -2330,7 +2672,6 @@ yyreduce:
 
   *++yyvsp = yyval;
 
-
   /* Now `shift' the result of the reduction.  Determine what state
      that goes to, based on the state we popped back to and the rule
      number reduced by.  */
@@ -2350,6 +2691,10 @@ yyreduce:
 | 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 = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
+
   /* If not already recovering from an error, report this error.  */
   if (!yyerrstatus)
     {
@@ -2357,37 +2702,36 @@ yyerrlab:
 #if ! YYERROR_VERBOSE
       yyerror (scanner, YY_("syntax error"));
 #else
+# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
+                                        yyssp, yytoken)
       {
-       YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
-       if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
-         {
-           YYSIZE_T yyalloc = 2 * yysize;
-           if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
-             yyalloc = YYSTACK_ALLOC_MAXIMUM;
-           if (yymsg != yymsgbuf)
-             YYSTACK_FREE (yymsg);
-           yymsg = (char *) YYSTACK_ALLOC (yyalloc);
-           if (yymsg)
-             yymsg_alloc = yyalloc;
-           else
-             {
-               yymsg = yymsgbuf;
-               yymsg_alloc = sizeof yymsgbuf;
-             }
-         }
-
-       if (0 < yysize && yysize <= yymsg_alloc)
-         {
-           (void) yysyntax_error (yymsg, yystate, yychar);
-           yyerror (scanner, yymsg);
-         }
-       else
-         {
-           yyerror (scanner, YY_("syntax error"));
-           if (yysize != 0)
-             goto yyexhaustedlab;
-         }
+        char const *yymsgp = YY_("syntax error");
+        int yysyntax_error_status;
+        yysyntax_error_status = YYSYNTAX_ERROR;
+        if (yysyntax_error_status == 0)
+          yymsgp = yymsg;
+        else if (yysyntax_error_status == 1)
+          {
+            if (yymsg != yymsgbuf)
+              YYSTACK_FREE (yymsg);
+            yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
+            if (!yymsg)
+              {
+                yymsg = yymsgbuf;
+                yymsg_alloc = sizeof yymsgbuf;
+                yysyntax_error_status = 2;
+              }
+            else
+              {
+                yysyntax_error_status = YYSYNTAX_ERROR;
+                yymsgp = yymsg;
+              }
+          }
+        yyerror (scanner, yymsgp);
+        if (yysyntax_error_status == 2)
+          goto yyexhaustedlab;
       }
+# undef YYSYNTAX_ERROR
 #endif
     }
 
@@ -2395,7 +2739,7 @@ yyerrlab:
 
   if (yyerrstatus == 3)
     {
-      /* If just tried and failed to reuse look-ahead token after an
+      /* If just tried and failed to reuse lookahead token after an
         error, discard it.  */
 
       if (yychar <= YYEOF)
@@ -2412,7 +2756,7 @@ yyerrlab:
        }
     }
 
-  /* Else will try to reuse look-ahead token after shifting the error
+  /* Else will try to reuse lookahead token after shifting the error
      token.  */
   goto yyerrlab1;
 
@@ -2446,7 +2790,7 @@ yyerrlab1:
   for (;;)
     {
       yyn = yypact[yystate];
-      if (yyn != YYPACT_NINF)
+      if (!yypact_value_is_default (yyn))
        {
          yyn += YYTERROR;
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
@@ -2469,9 +2813,6 @@ yyerrlab1:
       YY_STACK_PRINT (yyss, yyssp);
     }
 
-  if (yyn == YYFINAL)
-    YYACCEPT;
-
   *++yyvsp = yylval;
 
 
@@ -2496,7 +2837,7 @@ yyabortlab:
   yyresult = 1;
   goto yyreturn;
 
-#ifndef yyoverflow
+#if !defined(yyoverflow) || YYERROR_VERBOSE
 /*-------------------------------------------------.
 | yyexhaustedlab -- memory exhaustion comes here.  |
 `-------------------------------------------------*/
@@ -2507,9 +2848,14 @@ yyexhaustedlab:
 #endif
 
 yyreturn:
-  if (yychar != YYEOF && yychar != YYEMPTY)
-     yydestruct ("Cleanup: discarding lookahead",
-                yytoken, &yylval, scanner);
+  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 ("Cleanup: discarding lookahead",
+                  yytoken, &yylval, scanner);
+    }
   /* Do not reclaim the symbols of the rule which action triggered
      this YYABORT or YYACCEPT.  */
   YYPOPSTACK (yylen);
@@ -2524,6 +2870,9 @@ yyreturn:
   if (yyss != yyssa)
     YYSTACK_FREE (yyss);
 #endif
+  yyps->yynew = 1;
+
+yypushreturn:
 #if YYERROR_VERBOSE
   if (yymsg != yymsgbuf)
     YYSTACK_FREE (yymsg);
@@ -2533,7 +2882,9 @@ yyreturn:
 }
 
 
-#line 609 "parser.y"
+
+/* Line 2067 of yacc.c  */
+#line 603 "parser.y"
 
 
 static t_selexpr_value *
index f599c71cb6be2a3ae43591d49660aec3e0984f02..ba7b184e77e17b3e7af73a7cbb8e1bbe90eb92a4 100644 (file)
@@ -1,24 +1,21 @@
-/* A Bison parser, made by GNU Bison 2.3.  */
+/* A Bison parser, made by GNU Bison 2.5.  */
 
-/* Skeleton interface for Bison's Yacc-like parsers in C
-
-   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
-   Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
+/* Bison interface for Yacc-like parsers in C
+   
+      Copyright (C) 1984, 1989-1990, 2000-2011 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
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+   
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-
+   
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* As a special exception, you may create a larger work that contains
    part or all of the Bison parser skeleton and distribute that work
    special exception, which will cause the skeleton and the resulting
    Bison output files to be licensed under the GNU General Public
    License without this special exception.
-
+   
    This special exception was added by the Free Software Foundation in
    version 2.2 of Bison.  */
 
+
 /* Tokens.  */
 #ifndef YYTOKENTYPE
 # define YYTOKENTYPE
      NUM_REDUCT = 290
    };
 #endif
-/* Tokens.  */
-#define INVALID 258
-#define HELP 259
-#define HELP_TOPIC 260
-#define TOK_INT 261
-#define TOK_REAL 262
-#define STR 263
-#define IDENTIFIER 264
-#define CMD_SEP 265
-#define GROUP 266
-#define TO 267
-#define VARIABLE_NUMERIC 268
-#define VARIABLE_GROUP 269
-#define VARIABLE_POS 270
-#define KEYWORD_NUMERIC 271
-#define KEYWORD_STR 272
-#define KEYWORD_POS 273
-#define KEYWORD_GROUP 274
-#define METHOD_NUMERIC 275
-#define METHOD_GROUP 276
-#define METHOD_POS 277
-#define MODIFIER 278
-#define EMPTY_POSMOD 279
-#define PARAM 280
-#define END_OF_METHOD 281
-#define OF 282
-#define CMP_OP 283
-#define PARAM_REDUCT 284
-#define XOR 285
-#define OR 286
-#define AND 287
-#define NOT 288
-#define UNARY_NEG 289
-#define NUM_REDUCT 290
-
 
 
 
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
-#line 72 "parser.y"
 {
+
+/* Line 2068 of yacc.c  */
+#line 72 "parser.y"
+
     int                         i;
     real                        r;
     char                       *str;
@@ -125,14 +91,40 @@ typedef union YYSTYPE
 
     struct t_selexpr_value     *val;
     struct t_selexpr_param     *param;
-}
-/* Line 1529 of yacc.c.  */
-#line 131 "parser.h"
-       YYSTYPE;
+
+
+
+/* Line 2068 of yacc.c  */
+#line 99 "parser.h"
+} YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
-# define YYSTYPE_IS_TRIVIAL 1
 #endif
 
 
 
+
+#ifndef YYPUSH_DECLS
+#  define YYPUSH_DECLS
+struct _gmx_sel_yypstate;
+typedef struct _gmx_sel_yypstate _gmx_sel_yypstate;
+enum { YYPUSH_MORE = 4 };
+#if defined __STDC__ || defined __cplusplus
+int _gmx_sel_yypush_parse (_gmx_sel_yypstate *yyps, int yypushed_char, YYSTYPE const *yypushed_val, void *scanner);
+#else
+int _gmx_sel_yypush_parse ();
+#endif
+
+#if defined __STDC__ || defined __cplusplus
+_gmx_sel_yypstate * _gmx_sel_yypstate_new (void);
+#else
+_gmx_sel_yypstate * _gmx_sel_yypstate_new ();
+#endif
+#if defined __STDC__ || defined __cplusplus
+void _gmx_sel_yypstate_delete (_gmx_sel_yypstate *yyps);
+#else
+void _gmx_sel_yypstate_delete ();
+#endif
+#endif
+
index cb7071b8133bbed8e63ee794bfc35b7f365fadda..31dd905050c7eb6b2288ba8ee45a38069347e7aa 100644 (file)
@@ -80,11 +80,6 @@ yyerror(yyscan_t, char const *s);
     struct t_selexpr_value     *val;
     struct t_selexpr_param     *param;
 };
-/* NOTE: The Intel compiler seems to report warnings for the above line about
- * "definition at end of file not followed by a semicolon or a declarator".
- * This is due to the compiler misinterpreting #line directives in the
- * generated files parser.c/.h, and changing them would be more trouble than
- * it's worth. */
 
 /* Invalid token to report lexer errors */
 %token INVALID
@@ -182,16 +177,15 @@ yyerror(yyscan_t, char const *s);
 %expect 50
 %debug
 %pure-parser
+%define api.push-pull push
 
-/* If you change these, you also need to update the prototype in parsetree.c. */
-%name-prefix="_gmx_sel_yyb"
-%parse-param { yyscan_t                 scanner }
-%lex-param   { yyscan_t                 scanner }
+%name-prefix="_gmx_sel_yy"
+%parse-param { void *scanner }
 
 %%
 
 /* The start rule: allow one or more commands */
-commands:    /* empty */        { $$ = NULL }
+commands:    /* empty */        { $$ = NULL; }
            | commands command
              {
                  $$ = _gmx_sel_append_selection($2, $1, scanner);
index 5fa92659fea4b6a059be6d6574c149884d06da3a..451e8d058825b437941456e8359092c7a3211fde 100644 (file)
@@ -54,6 +54,7 @@ typedef int flex_int32_t;
 typedef unsigned char flex_uint8_t; 
 typedef unsigned short int flex_uint16_t;
 typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
 
 /* Limits of integral types. */
 #ifndef INT8_MIN
@@ -84,8 +85,6 @@ typedef unsigned int flex_uint32_t;
 #define UINT32_MAX             (4294967295U)
 #endif
 
-#endif /* ! C99 */
-
 #endif /* ! FLEXINT_H */
 
 #ifdef __cplusplus
@@ -159,15 +158,7 @@ typedef void* yyscan_t;
 
 /* Size of default input buffer. */
 #ifndef YY_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k.
- * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
- * Ditto for the __ia64__ case accordingly.
- */
-#define YY_BUF_SIZE 32768
-#else
 #define YY_BUF_SIZE 16384
-#endif /* __ia64__ */
 #endif
 
 /* The state buf must be large enough to hold one state per character in the main buffer.
@@ -572,7 +563,7 @@ static yyconst flex_int16_t yy_chk[193] =
 
 
 
-#line 576 "scanner.cpp"
+#line 567 "scanner.cpp"
 
 #define INITIAL 0
 #define matchof 1
@@ -695,12 +686,7 @@ static int input (yyscan_t yyscanner );
 
 /* Amount of stuff to slurp up with each read. */
 #ifndef YY_READ_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k */
-#define YY_READ_BUF_SIZE 16384
-#else
 #define YY_READ_BUF_SIZE 8192
-#endif /* __ia64__ */
 #endif
 
 /* Copy whatever the last rule matched to the standard output. */
@@ -708,7 +694,7 @@ static int input (yyscan_t yyscanner );
 /* This used to be an fputs(), but since the string might contain NUL's,
  * we now use fwrite().
  */
-#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
+#define ECHO fwrite( yytext, yyleng, 1, yyout )
 #endif
 
 /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
@@ -828,6 +814,7 @@ YY_DECL
     else if (state->bCmdStart)
     {
         BEGIN(cmdstart);
+        state->bCmdStart = false;
     }
     else if (YYSTATE != help)
     {
@@ -835,7 +822,7 @@ YY_DECL
     }
 
 
-#line 839 "scanner.cpp"
+#line 826 "scanner.cpp"
 
        if ( !yyg->yy_init )
                {
@@ -916,38 +903,39 @@ do_action:        /* This label is used only to access EOF actions. */
 
 case 1:
 YY_RULE_SETUP
-#line 117 "scanner.l"
+#line 118 "scanner.l"
 
        YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 118 "scanner.l"
+#line 119 "scanner.l"
 { yylval->i   = strtol(yytext, NULL, 10);    ADD_TOKEN; return TOK_INT; }
        YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 119 "scanner.l"
+#line 120 "scanner.l"
 { yylval->r   = strtod(yytext, NULL);        ADD_TOKEN; return TOK_REAL; }
        YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 120 "scanner.l"
+#line 121 "scanner.l"
 { yylval->str = gmx_strndup(yytext+1, yyleng-2); ADD_TOKEN; return STR;  }
        YY_BREAK
 case 5:
 /* rule 5 can match eol */
 YY_RULE_SETUP
-#line 122 "scanner.l"
+#line 123 "scanner.l"
 { _gmx_sel_lexer_add_token(" ", 1, state); }
        YY_BREAK
 case 6:
 /* rule 6 can match eol */
 YY_RULE_SETUP
-#line 123 "scanner.l"
+#line 124 "scanner.l"
 {
                     if (yytext[0] == ';' || state->bInteractive)
                     {
                         rtrim(state->pselstr);
+                        state->bCmdStart = true;
                         return CMD_SEP;
                     }
                     else
@@ -956,118 +944,123 @@ YY_RULE_SETUP
                     }
                 }
        YY_BREAK
+case YY_STATE_EOF(cmdstart):
+#line 137 "scanner.l"
+{ state->bCmdStart = true; yyterminate(); }
+       YY_BREAK
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(matchof):
+case YY_STATE_EOF(matchbool):
+case YY_STATE_EOF(help):
+#line 138 "scanner.l"
+{ state->bCmdStart = true; return CMD_SEP; }
+       YY_BREAK
 case 7:
 YY_RULE_SETUP
-#line 135 "scanner.l"
+#line 140 "scanner.l"
 { BEGIN(help); return HELP; }
        YY_BREAK
 
 case 8:
 YY_RULE_SETUP
-#line 137 "scanner.l"
+#line 142 "scanner.l"
 
        YY_BREAK
 case 9:
 YY_RULE_SETUP
-#line 138 "scanner.l"
+#line 143 "scanner.l"
 { yylval->str = gmx_strndup(yytext, yyleng); return HELP_TOPIC; }
        YY_BREAK
 case 10:
 /* rule 10 can match eol */
 YY_RULE_SETUP
-#line 139 "scanner.l"
-{ return CMD_SEP; }
+#line 144 "scanner.l"
+{ state->bCmdStart = true; return CMD_SEP; }
        YY_BREAK
 case 11:
 YY_RULE_SETUP
-#line 140 "scanner.l"
+#line 145 "scanner.l"
 { return INVALID; }
        YY_BREAK
 
 
 case 12:
 YY_RULE_SETUP
-#line 144 "scanner.l"
+#line 149 "scanner.l"
 { ADD_TOKEN; yylval->i = 1; return TOK_INT; }
        YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 145 "scanner.l"
+#line 150 "scanner.l"
 { ADD_TOKEN; yylval->i = 0; return TOK_INT; }
        YY_BREAK
 
 case 14:
 YY_RULE_SETUP
-#line 147 "scanner.l"
+#line 152 "scanner.l"
 { ADD_TOKEN; return GROUP; }
        YY_BREAK
 case 15:
 YY_RULE_SETUP
-#line 148 "scanner.l"
+#line 153 "scanner.l"
 { ADD_TOKEN; return TO; }
        YY_BREAK
 case 16:
 YY_RULE_SETUP
-#line 149 "scanner.l"
+#line 154 "scanner.l"
 { ADD_TOKEN; BEGIN(0); return OF; }
        YY_BREAK
 case 17:
 YY_RULE_SETUP
-#line 150 "scanner.l"
+#line 155 "scanner.l"
 { ADD_TOKEN; return AND; }
        YY_BREAK
 case 18:
 YY_RULE_SETUP
-#line 151 "scanner.l"
+#line 156 "scanner.l"
 { ADD_TOKEN; return OR; }
        YY_BREAK
 case 19:
 YY_RULE_SETUP
-#line 152 "scanner.l"
+#line 157 "scanner.l"
 { ADD_TOKEN; return XOR; }
        YY_BREAK
 case 20:
 YY_RULE_SETUP
-#line 153 "scanner.l"
+#line 158 "scanner.l"
 { ADD_TOKEN; return NOT; }
        YY_BREAK
 case 21:
 YY_RULE_SETUP
-#line 154 "scanner.l"
+#line 159 "scanner.l"
 { yylval->str = gmx_strndup(yytext, yyleng); ADD_TOKEN; return CMP_OP; }
        YY_BREAK
 case 22:
 YY_RULE_SETUP
-#line 156 "scanner.l"
+#line 161 "scanner.l"
 { return _gmx_sel_lexer_process_identifier(yylval, yytext, yyleng, state); }
        YY_BREAK
 case 23:
 YY_RULE_SETUP
-#line 158 "scanner.l"
+#line 163 "scanner.l"
 { _gmx_sel_lexer_add_token(" ", 1, state); }
        YY_BREAK
 case 24:
 YY_RULE_SETUP
-#line 159 "scanner.l"
+#line 164 "scanner.l"
 { yylval->str = gmx_strndup(yytext, yyleng); ADD_TOKEN; return STR; }
        YY_BREAK
 case 25:
 YY_RULE_SETUP
-#line 160 "scanner.l"
+#line 165 "scanner.l"
 { ADD_TOKEN; return yytext[0]; }
        YY_BREAK
 case 26:
 YY_RULE_SETUP
-#line 161 "scanner.l"
+#line 166 "scanner.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
        YY_BREAK
-#line 1065 "scanner.cpp"
-case YY_STATE_EOF(INITIAL):
-case YY_STATE_EOF(matchof):
-case YY_STATE_EOF(matchbool):
-case YY_STATE_EOF(cmdstart):
-case YY_STATE_EOF(help):
-       yyterminate();
+#line 1064 "scanner.cpp"
 
        case YY_END_OF_BUFFER:
                {
@@ -1834,8 +1827,8 @@ YY_BUFFER_STATE _gmx_sel_yy_scan_string (yyconst char * yystr , yyscan_t yyscann
 
 /** Setup the input buffer state to scan the given bytes. The next call to _gmx_sel_yylex() will
  * scan from a @e copy of @a bytes.
- * @param yybytes the byte buffer to scan
- * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ * @param bytes the byte buffer to scan
+ * @param len the number of bytes in the buffer pointed to by @a bytes.
  * @param yyscanner The scanner object.
  * @return the newly allocated buffer state object.
  */
@@ -2217,4 +2210,4 @@ void _gmx_sel_yyfree (void * ptr , yyscan_t yyscanner)
 
 #define YYTABLES_NAME "yytables"
 
-#line 161 "scanner.l"
+#line 166 "scanner.l"
index f0a812fe58e3f50129db526f9fcd816f175839d7..5c7f62316601f737309f0332d82b9a74ae15b69d 100644 (file)
@@ -104,8 +104,8 @@ _gmx_sel_set_lex_input_file(yyscan_t scanner, FILE *fp);
 void
 _gmx_sel_set_lex_input_str(yyscan_t scanner, const char *str);
 
-/** A wrapper for the actual scanner, used by the Bison parser. */
-int
-_gmx_sel_yyblex(YYSTYPE *yylval, yyscan_t yyscanner);
+/** The scanning function generated by Flex. */
+#define YY_DECL int _gmx_sel_yylex(YYSTYPE *yylval, yyscan_t yyscanner)
+YY_DECL;
 
 #endif
index eca1aa7e91f83770592d6f9bbc61a99418c02b99..82035d809974534640c4b9aa19029dba69466d3d 100644 (file)
@@ -107,6 +107,7 @@ COMMENT    (#.*)
     else if (state->bCmdStart)
     {
         BEGIN(cmdstart);
+        state->bCmdStart = false;
     }
     else if (YYSTATE != help)
     {
@@ -124,6 +125,7 @@ COMMENT    (#.*)
                     if (yytext[0] == ';' || state->bInteractive)
                     {
                         rtrim(state->pselstr);
+                        state->bCmdStart = true;
                         return CMD_SEP;
                     }
                     else
@@ -132,11 +134,14 @@ COMMENT    (#.*)
                     }
                 }
 
+<cmdstart><<EOF>> { state->bCmdStart = true; yyterminate(); }
+<<EOF>>         { state->bCmdStart = true; return CMD_SEP; }
+
 <cmdstart>help  { BEGIN(help); return HELP; }
 <help>{
 [[:blank:]]+
 {IDENTIFIER}    { yylval->str = gmx_strndup(yytext, yyleng); return HELP_TOPIC; }
-";"|\n          { return CMD_SEP; }
+";"|\n          { state->bCmdStart = true; return CMD_SEP; }
 .               { return INVALID; }
 }
 
index abb400cb31da000c3e10e0c95146dd74a620e410..4d8fe17cc11e28a280bccf40e5edbc7dd14a2ba2 100644 (file)
@@ -58,6 +58,7 @@ typedef int flex_int32_t;
 typedef unsigned char flex_uint8_t; 
 typedef unsigned short int flex_uint16_t;
 typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
 
 /* Limits of integral types. */
 #ifndef INT8_MIN
@@ -88,8 +89,6 @@ typedef unsigned int flex_uint32_t;
 #define UINT32_MAX             (4294967295U)
 #endif
 
-#endif /* ! C99 */
-
 #endif /* ! FLEXINT_H */
 
 #ifdef __cplusplus
@@ -132,15 +131,7 @@ typedef void* yyscan_t;
 
 /* Size of default input buffer. */
 #ifndef YY_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k.
- * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
- * Ditto for the __ia64__ case accordingly.
- */
-#define YY_BUF_SIZE 32768
-#else
 #define YY_BUF_SIZE 16384
-#endif /* __ia64__ */
 #endif
 
 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
@@ -305,12 +296,7 @@ static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
 
 /* Amount of stuff to slurp up with each read. */
 #ifndef YY_READ_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k */
-#define YY_READ_BUF_SIZE 16384
-#else
 #define YY_READ_BUF_SIZE 8192
-#endif /* __ia64__ */
 #endif
 
 /* Number of entries by which start-condition stack grows. */
@@ -343,8 +329,8 @@ extern int _gmx_sel_yylex (yyscan_t yyscanner);
 #undef YY_DECL
 #endif
 
-#line 161 "scanner.l"
+#line 166 "scanner.l"
 
-#line 349 "scanner_flex.h"
+#line 335 "scanner_flex.h"
 #undef _gmx_sel_yyIN_HEADER
 #endif /* _gmx_sel_yyHEADER_H */
index 833c65cf1aa4b68e94f479c978e75332a2e261a7..f11b1ed44c76ceabaa8fe33e3860149b42cd4736 100644 (file)
 #undef yytext
 #undef yyleng
 
-static bool
-read_stdin_line(gmx_sel_lexer_t *state)
-{
-    char *ptr     = state->inputstr;
-    int   max_len = state->nalloc_input;
-    int   totlen = 0;
-
-    if (feof(stdin))
-    {
-        return false;
-    }
-    if (state->bInteractive)
-    {
-        if (!state->errors->isEmpty())
-        {
-            fprintf(stderr, "%s", state->errors->toString().c_str());
-            state->errors->clear();
-        }
-        fprintf(stderr, "> ");
-    }
-    /* For some reason (at least on my Linux), fgets() doesn't return until
-     * the user presses Ctrl-D _twice_ at the end of a non-empty line.
-     * This can be a bit confusing for users, but there's not much we can
-     * do, and the chances of a normal user noticing this are not very big. */
-    while (fgets(ptr, max_len, stdin) != NULL)
-    {
-        int len = strlen(ptr);
-
-        totlen += len;
-        if (len >= 2 && ptr[len - 1] == '\n' && ptr[len - 2] == '\\')
-        {
-            if (state->bInteractive)
-            {
-                fprintf(stderr, "... ");
-            }
-        }
-        else if ((len >= 1 && ptr[len - 1] == '\n') || len < max_len - 1)
-        {
-            break;
-        }
-        ptr     += len;
-        max_len -= len;
-        if (max_len <= 2)
-        {
-            max_len += state->nalloc_input;
-            state->nalloc_input *= 2;
-            len = ptr - state->inputstr;
-            srenew(state->inputstr, state->nalloc_input);
-            ptr = state->inputstr + len;
-        }
-    }
-    if (state->bInteractive && (totlen == 0 || ptr[totlen - 1] != '\n'))
-    {
-        fprintf(stderr, "\n");
-    }
-    if (ferror(stdin))
-    {
-        GMX_ERROR_NORET(gmx::eeInvalidInput, "Selection reading failed");
-    }
-    return totlen > 0;
-}
-
-int
-_gmx_sel_yyblex(YYSTYPE *yylval, yyscan_t yyscanner)
-{
-    gmx_sel_lexer_t *state = _gmx_sel_yyget_extra(yyscanner);
-    bool bCmdStart;
-    int token;
-
-    if (!state->bBuffer && !state->inputstr)
-    {
-        state->nalloc_input = 1024;
-        snew(state->inputstr, state->nalloc_input);
-        read_stdin_line(state);
-        _gmx_sel_set_lex_input_str(yyscanner, state->inputstr);
-    }
-    bCmdStart = state->bCmdStart;
-    token = _gmx_sel_yylex(yylval, yyscanner);
-    while (state->inputstr && token == 0 && read_stdin_line(state))
-    {
-        _gmx_sel_set_lex_input_str(yyscanner, state->inputstr);
-        token = _gmx_sel_yylex(yylval, yyscanner);
-    }
-    if (token == 0 && !bCmdStart)
-    {
-        token = CMD_SEP;
-        rtrim(state->pselstr);
-    }
-    state->bCmdStart = (token == CMD_SEP);
-    return token;
-}
-
 static int
 init_param_token(YYSTYPE *yylval, gmx_ana_selparam_t *param, bool bBoolNo)
 {
@@ -483,8 +391,6 @@ _gmx_sel_init_lexer(yyscan_t *scannerp, struct gmx_ana_selcollection_t *sc,
     state->nexpsel   = (maxnr > 0 ? static_cast<int>(sc->sel.size()) + maxnr : -1);
 
     state->bInteractive = bInteractive;
-    state->nalloc_input = 0;
-    state->inputstr     = NULL;
 
     snew(state->pselstr, STRSTORE_ALLOCSTEP);
     state->pselstr[0]   = 0;
@@ -512,7 +418,6 @@ _gmx_sel_free_lexer(yyscan_t scanner)
 {
     gmx_sel_lexer_t *state = _gmx_sel_yyget_extra(scanner);
 
-    sfree(state->inputstr);
     sfree(state->pselstr);
     sfree(state->mstack);
     if (state->bBuffer)
index 3a280b31ceb5c8c8b90c30fc2c60d77bcadb6e42..e8fe599a00685bda930ef1c30342eccd5f3255f1 100644 (file)
@@ -44,10 +44,6 @@ class MessageStringCollector;
 
 #include "parser.h"
 
-/** The scanning function generated by Flex. */
-#define YY_DECL int _gmx_sel_yylex(YYSTYPE *yylval, yyscan_t yyscanner)
-YY_DECL;
-
 /* These need to be defined before including scanner_flex.h, because it
  * uses YY_EXTRA_TYPE. But we also need to include it before defining
  * gmx_sel_lexer_t; hence the forward declaration. */
@@ -81,10 +77,6 @@ typedef struct gmx_sel_lexer_t
 
     //! Whether the parser is interactive.
     bool                             bInteractive;
-    //! Current input string (line) for an interactive scanner.
-    char                            *inputstr;
-    //! Number of bytes allocated for \a inputstr.
-    int                              nalloc_input;
 
     //! Pretty-printed version of the string parsed since last clear.
     char                            *pselstr;
index e04ad2caa57a7b98e9fc4ba3d90cdceac281b65d..3c87658e2e5d0ce095a7e44f00abde669906f7ca 100644 (file)
@@ -125,21 +125,6 @@ class SelectionCollection::Impl
          * Does not throw.
          */
         void clearSymbolTable();
-        /*! \brief
-         * Helper function that runs the parser once the tokenizer has been
-         * initialized.
-         *
-         * \param[in,out] scanner Scanner data structure.
-         * \param[in]     maxnr   Maximum number of selections to parse
-         *      (if -1, parse as many as provided by the user).
-         * \returns       Vector of parsed selections.
-         * \throws        std::bad_alloc if out of memory.
-         * \throws        InvalidInputError if there is a parsing error.
-         *
-         * Used internally to implement parseFromStdin(), parseFromFile() and
-         * parseFromString().
-         */
-        SelectionList runParser(void *scanner, int maxnr);
         /*! \brief
          * Replace group references by group contents.
          *
index 61ca1fec9e11c2f5b204b720871492a70b71123d..12bd304b5d8b4483ed8dd5c7db49d47288ffc7b5 100644 (file)
@@ -41,6 +41,8 @@
 
 #include <cstdio>
 
+#include <boost/shared_ptr.hpp>
+
 #include "gromacs/legacyheaders/oenv.h"
 #include "gromacs/legacyheaders/smalloc.h"
 #include "gromacs/legacyheaders/xvgr.h"
 #include "gromacs/utility/file.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/messagestringcollector.h"
+#include "gromacs/utility/stringutil.h"
 
 #include "compiler.h"
 #include "mempool.h"
+#include "parser.h"
 #include "poscalc.h"
 #include "scanner.h"
 #include "selectioncollection-impl.h"
 #include "selmethod.h"
 #include "symrec.h"
 
-/* In parser.y */
-/*! \brief
- * Parser function generated by Bison.
- */
-int
-_gmx_sel_yybparse(void *scanner);
-
 namespace gmx
 {
 
@@ -124,19 +121,134 @@ SelectionCollection::Impl::clearSymbolTable()
 }
 
 
-SelectionList
-SelectionCollection::Impl::runParser(yyscan_t scanner, int maxnr)
+namespace
+{
+
+bool promptLine(File *infile, bool bInteractive, std::string *line)
 {
-    gmx_ana_selcollection_t *sc = &_sc;
-    GMX_ASSERT(sc == _gmx_sel_lexer_selcollection(scanner),
-               "Incorrectly initialized lexer");
+    if (bInteractive)
+    {
+        fprintf(stderr, "> ");
+    }
+    if (!infile->readLine(line))
+    {
+        return false;
+    }
+    while(endsWith(*line, "\\\n"))
+    {
+        line->resize(line->length() - 2);
+        if (bInteractive)
+        {
+            fprintf(stderr, "... ");
+        }
+        std::string buffer;
+        // Return value ignored, buffer remains empty and works correctly
+        // if there is nothing to read.
+        infile->readLine(&buffer);
+        line->append(buffer);
+    }
+    if (endsWith(*line, "\n"))
+    {
+        line->resize(line->length() - 1);
+    }
+    else if (bInteractive)
+    {
+        fprintf(stderr, "\n");
+    }
+    return line;
+}
+
+int runParserLoop(yyscan_t scanner, _gmx_sel_yypstate *parserState,
+                  bool bInteractive)
+{
+    int status = YYPUSH_MORE;
+    int prevToken = 0;
+    do
+    {
+        YYSTYPE value;
+        int token = _gmx_sel_yylex(&value, scanner);
+        if (bInteractive)
+        {
+            if (token == 0)
+            {
+                break;
+            }
+            if (prevToken == CMD_SEP && token == CMD_SEP)
+            {
+                continue;
+            }
+            prevToken = token;
+        }
+        status = _gmx_sel_yypush_parse(parserState, token, &value, scanner);
+    }
+    while (status == YYPUSH_MORE);
+    return status;
+}
+
+/*! \brief
+ * Helper function that runs the parser once the tokenizer has been
+ * initialized.
+ *
+ * \param[in,out] scanner Scanner data structure.
+ * \param[in]     bStdIn  Whether to use a line-based reading
+ *      algorithm designed for interactive input.
+ * \param[in]     maxnr   Maximum number of selections to parse
+ *      (if -1, parse as many as provided by the user).
+ * \returns       Vector of parsed selections.
+ * \throws        std::bad_alloc if out of memory.
+ * \throws        InvalidInputError if there is a parsing error.
+ *
+ * Used internally to implement parseFromStdin(), parseFromFile() and
+ * parseFromString().
+ */
+SelectionList runParser(yyscan_t scanner, bool bStdIn, int maxnr)
+{
+    boost::shared_ptr<void> scannerGuard(scanner, &_gmx_sel_free_lexer);
+    gmx_ana_selcollection_t *sc = _gmx_sel_lexer_selcollection(scanner);
 
     MessageStringCollector errors;
     _gmx_sel_set_lexer_error_reporter(scanner, &errors);
 
     int oldCount = sc->sel.size();
-    int bOk = !_gmx_sel_yybparse(scanner);
-    _gmx_sel_free_lexer(scanner);
+    bool bOk = false;
+    {
+        boost::shared_ptr<_gmx_sel_yypstate> parserState(
+                _gmx_sel_yypstate_new(), &_gmx_sel_yypstate_delete);
+        if (bStdIn)
+        {
+            File &stdinFile(File::standardInput());
+            bool bInteractive = _gmx_sel_is_lexer_interactive(scanner);
+            std::string line;
+            int status;
+            while (promptLine(&stdinFile, bInteractive, &line))
+            {
+                line.append("\n");
+                _gmx_sel_set_lex_input_str(scanner, line.c_str());
+                status = runParserLoop(scanner, parserState.get(), true);
+                if (status != YYPUSH_MORE)
+                {
+                    // TODO: Check if there is more input, and issue an
+                    // error/warning if some input was ignored.
+                    goto early_termination;
+                }
+                if (!errors.isEmpty() && bInteractive)
+                {
+                    fprintf(stderr, "%s", errors.toString().c_str());
+                    errors.clear();
+                }
+            }
+            status = _gmx_sel_yypush_parse(parserState.get(), 0, NULL,
+                                           scanner);
+early_termination:
+            bOk = (status == 0);
+        }
+        else
+        {
+            int status = runParserLoop(scanner, parserState.get(), false);
+            bOk = (status == 0);
+        }
+    }
+    scannerGuard.reset();
     int nr = sc->sel.size() - oldCount;
     if (maxnr > 0 && nr != maxnr)
     {
@@ -154,13 +266,15 @@ SelectionCollection::Impl::runParser(yyscan_t scanner, int maxnr)
     SelectionList result;
     SelectionDataList::const_iterator i;
     result.reserve(nr);
-    for (i = _sc.sel.begin() + oldCount; i != _sc.sel.end(); ++i)
+    for (i = sc->sel.begin() + oldCount; i != sc->sel.end(); ++i)
     {
         result.push_back(Selection(i->get()));
     }
     return result;
 }
 
+} // namespace
+
 
 void SelectionCollection::Impl::resolveExternalGroups(
         t_selelem *root, MessageStringCollector *errors)
@@ -387,9 +501,7 @@ SelectionCollection::parseFromStdin(int nr, bool bInteractive)
     _gmx_sel_init_lexer(&scanner, &_impl->_sc, bInteractive, nr,
                         _impl->_bExternalGroupsSet,
                         _impl->_grps);
-    /* We don't set the lexer input here, which causes it to use a special
-     * internal implementation for reading from stdin. */
-    return _impl->runParser(scanner, nr);
+    return runParser(scanner, true, nr);
 }
 
 
@@ -404,7 +516,7 @@ SelectionCollection::parseFromFile(const std::string &filename)
                         _impl->_bExternalGroupsSet,
                         _impl->_grps);
     _gmx_sel_set_lex_input_file(scanner, file.handle());
-    return _impl->runParser(scanner, -1);
+    return runParser(scanner, false, -1);
 }
 
 
@@ -417,7 +529,7 @@ SelectionCollection::parseFromString(const std::string &str)
                         _impl->_bExternalGroupsSet,
                         _impl->_grps);
     _gmx_sel_set_lex_input_str(scanner, str.c_str());
-    return _impl->runParser(scanner, -1);
+    return runParser(scanner, false, -1);
 }
 
 
index fd12ca404de9263f15badf71788fd6d1938653b9..83cfe806b07d7b08e1fcb4cefcc3db072c866aac 100644 (file)
@@ -182,6 +182,32 @@ void File::readBytes(void *buffer, size_t bytes)
     }
 }
 
+bool File::readLine(std::string *line)
+{
+    line->clear();
+    const size_t bufsize = 256;
+    std::string result;
+    char buf[bufsize];
+    buf[0] = '\0';
+    FILE *fp = handle();
+    while (fgets(buf, bufsize, fp) != NULL)
+    {
+        size_t length = std::strlen(buf);
+        result.append(buf, length);
+        if (length < bufsize - 1 || buf[length - 1] == '\n')
+        {
+            break;
+        }
+    }
+    if (ferror(fp))
+    {
+        GMX_THROW_WITH_ERRNO(FileIOError("Error while reading file"),
+                             "fgets", errno);
+    }
+    *line = result;
+    return !result.empty() || !feof(fp);
+}
+
 void File::writeString(const char *str)
 {
     if (fprintf(handle(), "%s", str) < 0)
@@ -207,6 +233,13 @@ void File::writeLine()
     writeString("\n");
 }
 
+// static
+File &File::standardInput()
+{
+    static File stdinObject(stdin, false);
+    return stdinObject;
+}
+
 // static
 File &File::standardOutput()
 {
index 244a74f423969b80274c0df81553a6fab429aa9d..0601717894afe58af2f1b7688129a09f179f4be6 100644 (file)
@@ -120,6 +120,27 @@ class File
          * The file must be open.
          */
         void readBytes(void *buffer, size_t bytes);
+        /*! \brief
+         * Reads a single line from the file.
+         *
+         * \param[out] line    String to receive the line.
+         * \returns    false if nothing was read because the file ended.
+         * \throws     std::bad_alloc if out of memory.
+         * \throws     FileIOError on any I/O error.
+         *
+         * On error or when false is returned, \p line will be empty.
+         * Terminating newline will be present in \p line if it was present in
+         * the file.
+         * To loop over all lines in the file, use:
+         * \code
+std::string line;
+while (file.readLine(&line))
+{
+    // ...
+}
+         * \endcode
+         */
+        bool readLine(std::string *line);
 
         /*! \brief
          * Writes a string to the file.
@@ -153,6 +174,12 @@ class File
          */
         void writeLine();
 
+        /*! \brief
+         * Returns a File object for accessing stdin.
+         *
+         * \throws    std::bad_alloc if out of memory (only on first call).
+         */
+        static File &standardInput();
         /*! \brief
          * Returns a File object for accessing stdout.
          *