├── test ├── Makefile ├── README.md ├── test.l ├── test.y ├── test.output ├── test.tab.h ├── test.tab.c └── lex.yy.c /test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanved77/flexbison/HEAD/test -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | default: 2 | clear 3 | flex -l test.l 4 | bison -dv test.y 5 | gcc -o test test.tab.c lex.yy.c -lfl 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flex, Bison, Yacc Sample Code 2 | ## Code for the [YouTube Tutorial](https://www.youtube.com/playlist?list=PLIrl0f9NJZy4oOOAVPU6MyRdFjJFGtceu) 3 | 4 | Here is the code or the tutorial I have put up on YouTube. If you guys have any questions regarding this code or tutorial or want me to do any sort of tutorial series on something else you can definitely contact me on - sanved@binghamton.edu 5 | 6 | I have also made one which parses a simple programming language - https://github.com/sanved77/mini-compiler 7 | -------------------------------------------------------------------------------- /test.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | #include 5 | #include "test.tab.h" 6 | void showError(); 7 | %} 8 | 9 | 10 | numbers ([0-9])+ 11 | alpha ([a-zA-Z])+ 12 | 13 | %% 14 | 15 | {alpha} {sscanf(yytext, "%s", yylval.name); return (STRING);} 16 | {numbers} {yylval.number = atoi(yytext); return (NUM);} 17 | ";" {return (SEMICOLON);} 18 | . {showError(); return(OTHER);} 19 | 20 | %% 21 | 22 | 23 | void showError(){ 24 | printf("Other input"); 25 | } 26 | int yywrap(){ 27 | return 1; 28 | } 29 | -------------------------------------------------------------------------------- /test.y: -------------------------------------------------------------------------------- 1 | 2 | %{ 3 | #include 4 | 5 | int yylex(); 6 | int yyerror(char *s); 7 | 8 | %} 9 | 10 | %token STRING NUM OTHER SEMICOLON 11 | 12 | %type STRING 13 | %type NUM 14 | 15 | %union{ 16 | char name[20]; 17 | int number; 18 | } 19 | 20 | %% 21 | 22 | prog: 23 | stmts 24 | ; 25 | 26 | stmts: 27 | | stmt SEMICOLON stmts 28 | 29 | stmt: 30 | STRING { 31 | printf("Your entered a string - %s", $1); 32 | } 33 | | NUM { 34 | printf("The number you entered is - %d", $1); 35 | } 36 | | OTHER 37 | ; 38 | 39 | %% 40 | 41 | int yyerror(char *s) 42 | { 43 | printf("Syntax Error on line %s\n", s); 44 | return 0; 45 | } 46 | 47 | int main() 48 | { 49 | yyparse(); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /test.output: -------------------------------------------------------------------------------- 1 | Grammar 2 | 3 | 0 $accept: prog $end 4 | 5 | 1 prog: stmts 6 | 7 | 2 stmts: %empty 8 | 3 | stmt SEMICOLON stmts 9 | 10 | 4 stmt: STRING 11 | 5 | NUM 12 | 6 | OTHER 13 | 14 | 15 | Terminals, with rules where they appear 16 | 17 | $end (0) 0 18 | error (256) 19 | STRING (258) 4 20 | NUM (259) 5 21 | OTHER (260) 6 22 | SEMICOLON (261) 3 23 | 24 | 25 | Nonterminals, with rules where they appear 26 | 27 | $accept (7) 28 | on left: 0 29 | prog (8) 30 | on left: 1, on right: 0 31 | stmts (9) 32 | on left: 2 3, on right: 1 3 33 | stmt (10) 34 | on left: 4 5 6, on right: 3 35 | 36 | 37 | State 0 38 | 39 | 0 $accept: . prog $end 40 | 41 | STRING shift, and go to state 1 42 | NUM shift, and go to state 2 43 | OTHER shift, and go to state 3 44 | 45 | $default reduce using rule 2 (stmts) 46 | 47 | prog go to state 4 48 | stmts go to state 5 49 | stmt go to state 6 50 | 51 | 52 | State 1 53 | 54 | 4 stmt: STRING . 55 | 56 | $default reduce using rule 4 (stmt) 57 | 58 | 59 | State 2 60 | 61 | 5 stmt: NUM . 62 | 63 | $default reduce using rule 5 (stmt) 64 | 65 | 66 | State 3 67 | 68 | 6 stmt: OTHER . 69 | 70 | $default reduce using rule 6 (stmt) 71 | 72 | 73 | State 4 74 | 75 | 0 $accept: prog . $end 76 | 77 | $end shift, and go to state 7 78 | 79 | 80 | State 5 81 | 82 | 1 prog: stmts . 83 | 84 | $default reduce using rule 1 (prog) 85 | 86 | 87 | State 6 88 | 89 | 3 stmts: stmt . SEMICOLON stmts 90 | 91 | SEMICOLON shift, and go to state 8 92 | 93 | 94 | State 7 95 | 96 | 0 $accept: prog $end . 97 | 98 | $default accept 99 | 100 | 101 | State 8 102 | 103 | 3 stmts: stmt SEMICOLON . stmts 104 | 105 | STRING shift, and go to state 1 106 | NUM shift, and go to state 2 107 | OTHER shift, and go to state 3 108 | 109 | $default reduce using rule 2 (stmts) 110 | 111 | stmts go to state 9 112 | stmt go to state 6 113 | 114 | 115 | State 9 116 | 117 | 3 stmts: stmt SEMICOLON stmts . 118 | 119 | $default reduce using rule 3 (stmts) 120 | -------------------------------------------------------------------------------- /test.tab.h: -------------------------------------------------------------------------------- 1 | /* A Bison parser, made by GNU Bison 3.0.4. */ 2 | 3 | /* Bison interface for Yacc-like parsers in C 4 | 5 | Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | /* As a special exception, you may create a larger work that contains 21 | part or all of the Bison parser skeleton and distribute that work 22 | under terms of your choice, so long as that work isn't itself a 23 | parser generator using the skeleton or a modified version thereof 24 | as a parser skeleton. Alternatively, if you modify or redistribute 25 | the parser skeleton itself, you may (at your option) remove this 26 | special exception, which will cause the skeleton and the resulting 27 | Bison output files to be licensed under the GNU General Public 28 | License without this special exception. 29 | 30 | This special exception was added by the Free Software Foundation in 31 | version 2.2 of Bison. */ 32 | 33 | #ifndef YY_YY_TEST_TAB_H_INCLUDED 34 | # define YY_YY_TEST_TAB_H_INCLUDED 35 | /* Debug traces. */ 36 | #ifndef YYDEBUG 37 | # define YYDEBUG 0 38 | #endif 39 | #if YYDEBUG 40 | extern int yydebug; 41 | #endif 42 | 43 | /* Token type. */ 44 | #ifndef YYTOKENTYPE 45 | # define YYTOKENTYPE 46 | enum yytokentype 47 | { 48 | STRING = 258, 49 | NUM = 259, 50 | OTHER = 260, 51 | SEMICOLON = 261 52 | }; 53 | #endif 54 | 55 | /* Value type. */ 56 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 57 | 58 | union YYSTYPE 59 | { 60 | #line 15 "test.y" /* yacc.c:1909 */ 61 | 62 | char name[20]; 63 | int number; 64 | 65 | #line 66 "test.tab.h" /* yacc.c:1909 */ 66 | }; 67 | 68 | typedef union YYSTYPE YYSTYPE; 69 | # define YYSTYPE_IS_TRIVIAL 1 70 | # define YYSTYPE_IS_DECLARED 1 71 | #endif 72 | 73 | 74 | extern YYSTYPE yylval; 75 | 76 | int yyparse (void); 77 | 78 | #endif /* !YY_YY_TEST_TAB_H_INCLUDED */ 79 | -------------------------------------------------------------------------------- /test.tab.c: -------------------------------------------------------------------------------- 1 | /* A Bison parser, made by GNU Bison 3.0.4. */ 2 | 3 | /* Bison implementation for Yacc-like parsers in C 4 | 5 | Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | /* As a special exception, you may create a larger work that contains 21 | part or all of the Bison parser skeleton and distribute that work 22 | under terms of your choice, so long as that work isn't itself a 23 | parser generator using the skeleton or a modified version thereof 24 | as a parser skeleton. Alternatively, if you modify or redistribute 25 | the parser skeleton itself, you may (at your option) remove this 26 | special exception, which will cause the skeleton and the resulting 27 | Bison output files to be licensed under the GNU General Public 28 | License without this special exception. 29 | 30 | This special exception was added by the Free Software Foundation in 31 | version 2.2 of Bison. */ 32 | 33 | /* C LALR(1) parser skeleton written by Richard Stallman, by 34 | simplifying the original so-called "semantic" parser. */ 35 | 36 | /* All symbols defined below should begin with yy or YY, to avoid 37 | infringing on user name space. This should be done even for local 38 | variables, as they might otherwise be expanded by user macros. 39 | There are some unavoidable exceptions within include files to 40 | define necessary library symbols; they are noted "INFRINGES ON 41 | USER NAME SPACE" below. */ 42 | 43 | /* Identify Bison output. */ 44 | #define YYBISON 1 45 | 46 | /* Bison version. */ 47 | #define YYBISON_VERSION "3.0.4" 48 | 49 | /* Skeleton name. */ 50 | #define YYSKELETON_NAME "yacc.c" 51 | 52 | /* Pure parsers. */ 53 | #define YYPURE 0 54 | 55 | /* Push parsers. */ 56 | #define YYPUSH 0 57 | 58 | /* Pull parsers. */ 59 | #define YYPULL 1 60 | 61 | 62 | 63 | 64 | /* Copy the first part of user declarations. */ 65 | #line 2 "test.y" /* yacc.c:339 */ 66 | 67 | #include 68 | 69 | int yylex(); 70 | int yyerror(char *s); 71 | 72 | 73 | #line 74 "test.tab.c" /* yacc.c:339 */ 74 | 75 | # ifndef YY_NULLPTR 76 | # if defined __cplusplus && 201103L <= __cplusplus 77 | # define YY_NULLPTR nullptr 78 | # else 79 | # define YY_NULLPTR 0 80 | # endif 81 | # endif 82 | 83 | /* Enabling verbose error messages. */ 84 | #ifdef YYERROR_VERBOSE 85 | # undef YYERROR_VERBOSE 86 | # define YYERROR_VERBOSE 1 87 | #else 88 | # define YYERROR_VERBOSE 0 89 | #endif 90 | 91 | /* In a future release of Bison, this section will be replaced 92 | by #include "test.tab.h". */ 93 | #ifndef YY_YY_TEST_TAB_H_INCLUDED 94 | # define YY_YY_TEST_TAB_H_INCLUDED 95 | /* Debug traces. */ 96 | #ifndef YYDEBUG 97 | # define YYDEBUG 0 98 | #endif 99 | #if YYDEBUG 100 | extern int yydebug; 101 | #endif 102 | 103 | /* Token type. */ 104 | #ifndef YYTOKENTYPE 105 | # define YYTOKENTYPE 106 | enum yytokentype 107 | { 108 | STRING = 258, 109 | NUM = 259, 110 | OTHER = 260, 111 | SEMICOLON = 261 112 | }; 113 | #endif 114 | 115 | /* Value type. */ 116 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 117 | 118 | union YYSTYPE 119 | { 120 | #line 15 "test.y" /* yacc.c:355 */ 121 | 122 | char name[20]; 123 | int number; 124 | 125 | #line 126 "test.tab.c" /* yacc.c:355 */ 126 | }; 127 | 128 | typedef union YYSTYPE YYSTYPE; 129 | # define YYSTYPE_IS_TRIVIAL 1 130 | # define YYSTYPE_IS_DECLARED 1 131 | #endif 132 | 133 | 134 | extern YYSTYPE yylval; 135 | 136 | int yyparse (void); 137 | 138 | #endif /* !YY_YY_TEST_TAB_H_INCLUDED */ 139 | 140 | /* Copy the second part of user declarations. */ 141 | 142 | #line 143 "test.tab.c" /* yacc.c:358 */ 143 | 144 | #ifdef short 145 | # undef short 146 | #endif 147 | 148 | #ifdef YYTYPE_UINT8 149 | typedef YYTYPE_UINT8 yytype_uint8; 150 | #else 151 | typedef unsigned char yytype_uint8; 152 | #endif 153 | 154 | #ifdef YYTYPE_INT8 155 | typedef YYTYPE_INT8 yytype_int8; 156 | #else 157 | typedef signed char yytype_int8; 158 | #endif 159 | 160 | #ifdef YYTYPE_UINT16 161 | typedef YYTYPE_UINT16 yytype_uint16; 162 | #else 163 | typedef unsigned short int yytype_uint16; 164 | #endif 165 | 166 | #ifdef YYTYPE_INT16 167 | typedef YYTYPE_INT16 yytype_int16; 168 | #else 169 | typedef short int yytype_int16; 170 | #endif 171 | 172 | #ifndef YYSIZE_T 173 | # ifdef __SIZE_TYPE__ 174 | # define YYSIZE_T __SIZE_TYPE__ 175 | # elif defined size_t 176 | # define YYSIZE_T size_t 177 | # elif ! defined YYSIZE_T 178 | # include /* INFRINGES ON USER NAME SPACE */ 179 | # define YYSIZE_T size_t 180 | # else 181 | # define YYSIZE_T unsigned int 182 | # endif 183 | #endif 184 | 185 | #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) 186 | 187 | #ifndef YY_ 188 | # if defined YYENABLE_NLS && YYENABLE_NLS 189 | # if ENABLE_NLS 190 | # include /* INFRINGES ON USER NAME SPACE */ 191 | # define YY_(Msgid) dgettext ("bison-runtime", Msgid) 192 | # endif 193 | # endif 194 | # ifndef YY_ 195 | # define YY_(Msgid) Msgid 196 | # endif 197 | #endif 198 | 199 | #ifndef YY_ATTRIBUTE 200 | # if (defined __GNUC__ \ 201 | && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ 202 | || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C 203 | # define YY_ATTRIBUTE(Spec) __attribute__(Spec) 204 | # else 205 | # define YY_ATTRIBUTE(Spec) /* empty */ 206 | # endif 207 | #endif 208 | 209 | #ifndef YY_ATTRIBUTE_PURE 210 | # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) 211 | #endif 212 | 213 | #ifndef YY_ATTRIBUTE_UNUSED 214 | # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) 215 | #endif 216 | 217 | #if !defined _Noreturn \ 218 | && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) 219 | # if defined _MSC_VER && 1200 <= _MSC_VER 220 | # define _Noreturn __declspec (noreturn) 221 | # else 222 | # define _Noreturn YY_ATTRIBUTE ((__noreturn__)) 223 | # endif 224 | #endif 225 | 226 | /* Suppress unused-variable warnings by "using" E. */ 227 | #if ! defined lint || defined __GNUC__ 228 | # define YYUSE(E) ((void) (E)) 229 | #else 230 | # define YYUSE(E) /* empty */ 231 | #endif 232 | 233 | #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ 234 | /* Suppress an incorrect diagnostic about yylval being uninitialized. */ 235 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ 236 | _Pragma ("GCC diagnostic push") \ 237 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ 238 | _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") 239 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ 240 | _Pragma ("GCC diagnostic pop") 241 | #else 242 | # define YY_INITIAL_VALUE(Value) Value 243 | #endif 244 | #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 245 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 246 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END 247 | #endif 248 | #ifndef YY_INITIAL_VALUE 249 | # define YY_INITIAL_VALUE(Value) /* Nothing. */ 250 | #endif 251 | 252 | 253 | #if ! defined yyoverflow || YYERROR_VERBOSE 254 | 255 | /* The parser invokes alloca or malloc; define the necessary symbols. */ 256 | 257 | # ifdef YYSTACK_USE_ALLOCA 258 | # if YYSTACK_USE_ALLOCA 259 | # ifdef __GNUC__ 260 | # define YYSTACK_ALLOC __builtin_alloca 261 | # elif defined __BUILTIN_VA_ARG_INCR 262 | # include /* INFRINGES ON USER NAME SPACE */ 263 | # elif defined _AIX 264 | # define YYSTACK_ALLOC __alloca 265 | # elif defined _MSC_VER 266 | # include /* INFRINGES ON USER NAME SPACE */ 267 | # define alloca _alloca 268 | # else 269 | # define YYSTACK_ALLOC alloca 270 | # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS 271 | # include /* INFRINGES ON USER NAME SPACE */ 272 | /* Use EXIT_SUCCESS as a witness for stdlib.h. */ 273 | # ifndef EXIT_SUCCESS 274 | # define EXIT_SUCCESS 0 275 | # endif 276 | # endif 277 | # endif 278 | # endif 279 | # endif 280 | 281 | # ifdef YYSTACK_ALLOC 282 | /* Pacify GCC's 'empty if-body' warning. */ 283 | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) 284 | # ifndef YYSTACK_ALLOC_MAXIMUM 285 | /* The OS might guarantee only one guard page at the bottom of the stack, 286 | and a page size can be as small as 4096 bytes. So we cannot safely 287 | invoke alloca (N) if N exceeds 4096. Use a slightly smaller number 288 | to allow for a few compiler-allocated temporary stack slots. */ 289 | # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ 290 | # endif 291 | # else 292 | # define YYSTACK_ALLOC YYMALLOC 293 | # define YYSTACK_FREE YYFREE 294 | # ifndef YYSTACK_ALLOC_MAXIMUM 295 | # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM 296 | # endif 297 | # if (defined __cplusplus && ! defined EXIT_SUCCESS \ 298 | && ! ((defined YYMALLOC || defined malloc) \ 299 | && (defined YYFREE || defined free))) 300 | # include /* INFRINGES ON USER NAME SPACE */ 301 | # ifndef EXIT_SUCCESS 302 | # define EXIT_SUCCESS 0 303 | # endif 304 | # endif 305 | # ifndef YYMALLOC 306 | # define YYMALLOC malloc 307 | # if ! defined malloc && ! defined EXIT_SUCCESS 308 | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ 309 | # endif 310 | # endif 311 | # ifndef YYFREE 312 | # define YYFREE free 313 | # if ! defined free && ! defined EXIT_SUCCESS 314 | void free (void *); /* INFRINGES ON USER NAME SPACE */ 315 | # endif 316 | # endif 317 | # endif 318 | #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ 319 | 320 | 321 | #if (! defined yyoverflow \ 322 | && (! defined __cplusplus \ 323 | || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) 324 | 325 | /* A type that is properly aligned for any stack member. */ 326 | union yyalloc 327 | { 328 | yytype_int16 yyss_alloc; 329 | YYSTYPE yyvs_alloc; 330 | }; 331 | 332 | /* The size of the maximum gap between one aligned stack and the next. */ 333 | # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) 334 | 335 | /* The size of an array large to enough to hold all stacks, each with 336 | N elements. */ 337 | # define YYSTACK_BYTES(N) \ 338 | ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ 339 | + YYSTACK_GAP_MAXIMUM) 340 | 341 | # define YYCOPY_NEEDED 1 342 | 343 | /* Relocate STACK from its old location to the new one. The 344 | local variables YYSIZE and YYSTACKSIZE give the old and new number of 345 | elements in the stack, and YYPTR gives the new location of the 346 | stack. Advance YYPTR to a properly aligned location for the next 347 | stack. */ 348 | # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ 349 | do \ 350 | { \ 351 | YYSIZE_T yynewbytes; \ 352 | YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ 353 | Stack = &yyptr->Stack_alloc; \ 354 | yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ 355 | yyptr += yynewbytes / sizeof (*yyptr); \ 356 | } \ 357 | while (0) 358 | 359 | #endif 360 | 361 | #if defined YYCOPY_NEEDED && YYCOPY_NEEDED 362 | /* Copy COUNT objects from SRC to DST. The source and destination do 363 | not overlap. */ 364 | # ifndef YYCOPY 365 | # if defined __GNUC__ && 1 < __GNUC__ 366 | # define YYCOPY(Dst, Src, Count) \ 367 | __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) 368 | # else 369 | # define YYCOPY(Dst, Src, Count) \ 370 | do \ 371 | { \ 372 | YYSIZE_T yyi; \ 373 | for (yyi = 0; yyi < (Count); yyi++) \ 374 | (Dst)[yyi] = (Src)[yyi]; \ 375 | } \ 376 | while (0) 377 | # endif 378 | # endif 379 | #endif /* !YYCOPY_NEEDED */ 380 | 381 | /* YYFINAL -- State number of the termination state. */ 382 | #define YYFINAL 7 383 | /* YYLAST -- Last index in YYTABLE. */ 384 | #define YYLAST 7 385 | 386 | /* YYNTOKENS -- Number of terminals. */ 387 | #define YYNTOKENS 7 388 | /* YYNNTS -- Number of nonterminals. */ 389 | #define YYNNTS 4 390 | /* YYNRULES -- Number of rules. */ 391 | #define YYNRULES 7 392 | /* YYNSTATES -- Number of states. */ 393 | #define YYNSTATES 10 394 | 395 | /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned 396 | by yylex, with out-of-bounds checking. */ 397 | #define YYUNDEFTOK 2 398 | #define YYMAXUTOK 261 399 | 400 | #define YYTRANSLATE(YYX) \ 401 | ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) 402 | 403 | /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM 404 | as returned by yylex, without out-of-bounds checking. */ 405 | static const yytype_uint8 yytranslate[] = 406 | { 407 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 408 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 409 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 410 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 411 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 412 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 413 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 414 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 415 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 416 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 417 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 418 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 419 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 420 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 421 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 422 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 423 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 424 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 425 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 426 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 427 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 428 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 429 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 430 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 431 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 432 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 433 | 5, 6 434 | }; 435 | 436 | #if YYDEBUG 437 | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ 438 | static const yytype_uint8 yyrline[] = 439 | { 440 | 0, 23, 23, 26, 27, 30, 33, 36 441 | }; 442 | #endif 443 | 444 | #if YYDEBUG || YYERROR_VERBOSE || 0 445 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 446 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ 447 | static const char *const yytname[] = 448 | { 449 | "$end", "error", "$undefined", "STRING", "NUM", "OTHER", "SEMICOLON", 450 | "$accept", "prog", "stmts", "stmt", YY_NULLPTR 451 | }; 452 | #endif 453 | 454 | # ifdef YYPRINT 455 | /* YYTOKNUM[NUM] -- (External) token number corresponding to the 456 | (internal) symbol number NUM (which must be that of a token). */ 457 | static const yytype_uint16 yytoknum[] = 458 | { 459 | 0, 256, 257, 258, 259, 260, 261 460 | }; 461 | # endif 462 | 463 | #define YYPACT_NINF -4 464 | 465 | #define yypact_value_is_default(Yystate) \ 466 | (!!((Yystate) == (-4))) 467 | 468 | #define YYTABLE_NINF -1 469 | 470 | #define yytable_value_is_error(Yytable_value) \ 471 | 0 472 | 473 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 474 | STATE-NUM. */ 475 | static const yytype_int8 yypact[] = 476 | { 477 | -3, -4, -4, -4, 3, -4, -2, -4, -3, -4 478 | }; 479 | 480 | /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. 481 | Performed when YYTABLE does not specify something else to do. Zero 482 | means the default is an error. */ 483 | static const yytype_uint8 yydefact[] = 484 | { 485 | 3, 5, 6, 7, 0, 2, 0, 1, 3, 4 486 | }; 487 | 488 | /* YYPGOTO[NTERM-NUM]. */ 489 | static const yytype_int8 yypgoto[] = 490 | { 491 | -4, -4, -1, -4 492 | }; 493 | 494 | /* YYDEFGOTO[NTERM-NUM]. */ 495 | static const yytype_int8 yydefgoto[] = 496 | { 497 | -1, 4, 5, 6 498 | }; 499 | 500 | /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If 501 | positive, shift that token. If negative, reduce the rule whose 502 | number is the opposite. If YYTABLE_NINF, syntax error. */ 503 | static const yytype_uint8 yytable[] = 504 | { 505 | 1, 2, 3, 7, 8, 0, 0, 9 506 | }; 507 | 508 | static const yytype_int8 yycheck[] = 509 | { 510 | 3, 4, 5, 0, 6, -1, -1, 8 511 | }; 512 | 513 | /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing 514 | symbol of state STATE-NUM. */ 515 | static const yytype_uint8 yystos[] = 516 | { 517 | 0, 3, 4, 5, 8, 9, 10, 0, 6, 9 518 | }; 519 | 520 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ 521 | static const yytype_uint8 yyr1[] = 522 | { 523 | 0, 7, 8, 9, 9, 10, 10, 10 524 | }; 525 | 526 | /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ 527 | static const yytype_uint8 yyr2[] = 528 | { 529 | 0, 2, 1, 0, 3, 1, 1, 1 530 | }; 531 | 532 | 533 | #define yyerrok (yyerrstatus = 0) 534 | #define yyclearin (yychar = YYEMPTY) 535 | #define YYEMPTY (-2) 536 | #define YYEOF 0 537 | 538 | #define YYACCEPT goto yyacceptlab 539 | #define YYABORT goto yyabortlab 540 | #define YYERROR goto yyerrorlab 541 | 542 | 543 | #define YYRECOVERING() (!!yyerrstatus) 544 | 545 | #define YYBACKUP(Token, Value) \ 546 | do \ 547 | if (yychar == YYEMPTY) \ 548 | { \ 549 | yychar = (Token); \ 550 | yylval = (Value); \ 551 | YYPOPSTACK (yylen); \ 552 | yystate = *yyssp; \ 553 | goto yybackup; \ 554 | } \ 555 | else \ 556 | { \ 557 | yyerror (YY_("syntax error: cannot back up")); \ 558 | YYERROR; \ 559 | } \ 560 | while (0) 561 | 562 | /* Error token number */ 563 | #define YYTERROR 1 564 | #define YYERRCODE 256 565 | 566 | 567 | 568 | /* Enable debugging if requested. */ 569 | #if YYDEBUG 570 | 571 | # ifndef YYFPRINTF 572 | # include /* INFRINGES ON USER NAME SPACE */ 573 | # define YYFPRINTF fprintf 574 | # endif 575 | 576 | # define YYDPRINTF(Args) \ 577 | do { \ 578 | if (yydebug) \ 579 | YYFPRINTF Args; \ 580 | } while (0) 581 | 582 | /* This macro is provided for backward compatibility. */ 583 | #ifndef YY_LOCATION_PRINT 584 | # define YY_LOCATION_PRINT(File, Loc) ((void) 0) 585 | #endif 586 | 587 | 588 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ 589 | do { \ 590 | if (yydebug) \ 591 | { \ 592 | YYFPRINTF (stderr, "%s ", Title); \ 593 | yy_symbol_print (stderr, \ 594 | Type, Value); \ 595 | YYFPRINTF (stderr, "\n"); \ 596 | } \ 597 | } while (0) 598 | 599 | 600 | /*----------------------------------------. 601 | | Print this symbol's value on YYOUTPUT. | 602 | `----------------------------------------*/ 603 | 604 | static void 605 | yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) 606 | { 607 | FILE *yyo = yyoutput; 608 | YYUSE (yyo); 609 | if (!yyvaluep) 610 | return; 611 | # ifdef YYPRINT 612 | if (yytype < YYNTOKENS) 613 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); 614 | # endif 615 | YYUSE (yytype); 616 | } 617 | 618 | 619 | /*--------------------------------. 620 | | Print this symbol on YYOUTPUT. | 621 | `--------------------------------*/ 622 | 623 | static void 624 | yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) 625 | { 626 | YYFPRINTF (yyoutput, "%s %s (", 627 | yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); 628 | 629 | yy_symbol_value_print (yyoutput, yytype, yyvaluep); 630 | YYFPRINTF (yyoutput, ")"); 631 | } 632 | 633 | /*------------------------------------------------------------------. 634 | | yy_stack_print -- Print the state stack from its BOTTOM up to its | 635 | | TOP (included). | 636 | `------------------------------------------------------------------*/ 637 | 638 | static void 639 | yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) 640 | { 641 | YYFPRINTF (stderr, "Stack now"); 642 | for (; yybottom <= yytop; yybottom++) 643 | { 644 | int yybot = *yybottom; 645 | YYFPRINTF (stderr, " %d", yybot); 646 | } 647 | YYFPRINTF (stderr, "\n"); 648 | } 649 | 650 | # define YY_STACK_PRINT(Bottom, Top) \ 651 | do { \ 652 | if (yydebug) \ 653 | yy_stack_print ((Bottom), (Top)); \ 654 | } while (0) 655 | 656 | 657 | /*------------------------------------------------. 658 | | Report that the YYRULE is going to be reduced. | 659 | `------------------------------------------------*/ 660 | 661 | static void 662 | yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) 663 | { 664 | unsigned long int yylno = yyrline[yyrule]; 665 | int yynrhs = yyr2[yyrule]; 666 | int yyi; 667 | YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", 668 | yyrule - 1, yylno); 669 | /* The symbols being reduced. */ 670 | for (yyi = 0; yyi < yynrhs; yyi++) 671 | { 672 | YYFPRINTF (stderr, " $%d = ", yyi + 1); 673 | yy_symbol_print (stderr, 674 | yystos[yyssp[yyi + 1 - yynrhs]], 675 | &(yyvsp[(yyi + 1) - (yynrhs)]) 676 | ); 677 | YYFPRINTF (stderr, "\n"); 678 | } 679 | } 680 | 681 | # define YY_REDUCE_PRINT(Rule) \ 682 | do { \ 683 | if (yydebug) \ 684 | yy_reduce_print (yyssp, yyvsp, Rule); \ 685 | } while (0) 686 | 687 | /* Nonzero means print parse trace. It is left uninitialized so that 688 | multiple parsers can coexist. */ 689 | int yydebug; 690 | #else /* !YYDEBUG */ 691 | # define YYDPRINTF(Args) 692 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) 693 | # define YY_STACK_PRINT(Bottom, Top) 694 | # define YY_REDUCE_PRINT(Rule) 695 | #endif /* !YYDEBUG */ 696 | 697 | 698 | /* YYINITDEPTH -- initial size of the parser's stacks. */ 699 | #ifndef YYINITDEPTH 700 | # define YYINITDEPTH 200 701 | #endif 702 | 703 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 704 | if the built-in stack extension method is used). 705 | 706 | Do not make this value too large; the results are undefined if 707 | YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) 708 | evaluated with infinite-precision integer arithmetic. */ 709 | 710 | #ifndef YYMAXDEPTH 711 | # define YYMAXDEPTH 10000 712 | #endif 713 | 714 | 715 | #if YYERROR_VERBOSE 716 | 717 | # ifndef yystrlen 718 | # if defined __GLIBC__ && defined _STRING_H 719 | # define yystrlen strlen 720 | # else 721 | /* Return the length of YYSTR. */ 722 | static YYSIZE_T 723 | yystrlen (const char *yystr) 724 | { 725 | YYSIZE_T yylen; 726 | for (yylen = 0; yystr[yylen]; yylen++) 727 | continue; 728 | return yylen; 729 | } 730 | # endif 731 | # endif 732 | 733 | # ifndef yystpcpy 734 | # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE 735 | # define yystpcpy stpcpy 736 | # else 737 | /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in 738 | YYDEST. */ 739 | static char * 740 | yystpcpy (char *yydest, const char *yysrc) 741 | { 742 | char *yyd = yydest; 743 | const char *yys = yysrc; 744 | 745 | while ((*yyd++ = *yys++) != '\0') 746 | continue; 747 | 748 | return yyd - 1; 749 | } 750 | # endif 751 | # endif 752 | 753 | # ifndef yytnamerr 754 | /* Copy to YYRES the contents of YYSTR after stripping away unnecessary 755 | quotes and backslashes, so that it's suitable for yyerror. The 756 | heuristic is that double-quoting is unnecessary unless the string 757 | contains an apostrophe, a comma, or backslash (other than 758 | backslash-backslash). YYSTR is taken from yytname. If YYRES is 759 | null, do not copy; instead, return the length of what the result 760 | would have been. */ 761 | static YYSIZE_T 762 | yytnamerr (char *yyres, const char *yystr) 763 | { 764 | if (*yystr == '"') 765 | { 766 | YYSIZE_T yyn = 0; 767 | char const *yyp = yystr; 768 | 769 | for (;;) 770 | switch (*++yyp) 771 | { 772 | case '\'': 773 | case ',': 774 | goto do_not_strip_quotes; 775 | 776 | case '\\': 777 | if (*++yyp != '\\') 778 | goto do_not_strip_quotes; 779 | /* Fall through. */ 780 | default: 781 | if (yyres) 782 | yyres[yyn] = *yyp; 783 | yyn++; 784 | break; 785 | 786 | case '"': 787 | if (yyres) 788 | yyres[yyn] = '\0'; 789 | return yyn; 790 | } 791 | do_not_strip_quotes: ; 792 | } 793 | 794 | if (! yyres) 795 | return yystrlen (yystr); 796 | 797 | return yystpcpy (yyres, yystr) - yyres; 798 | } 799 | # endif 800 | 801 | /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message 802 | about the unexpected token YYTOKEN for the state stack whose top is 803 | YYSSP. 804 | 805 | Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is 806 | not large enough to hold the message. In that case, also set 807 | *YYMSG_ALLOC to the required number of bytes. Return 2 if the 808 | required number of bytes is too large to store. */ 809 | static int 810 | yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, 811 | yytype_int16 *yyssp, int yytoken) 812 | { 813 | YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); 814 | YYSIZE_T yysize = yysize0; 815 | enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; 816 | /* Internationalized format string. */ 817 | const char *yyformat = YY_NULLPTR; 818 | /* Arguments of yyformat. */ 819 | char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; 820 | /* Number of reported tokens (one for the "unexpected", one per 821 | "expected"). */ 822 | int yycount = 0; 823 | 824 | /* There are many possibilities here to consider: 825 | - If this state is a consistent state with a default action, then 826 | the only way this function was invoked is if the default action 827 | is an error action. In that case, don't check for expected 828 | tokens because there are none. 829 | - The only way there can be no lookahead present (in yychar) is if 830 | this state is a consistent state with a default action. Thus, 831 | detecting the absence of a lookahead is sufficient to determine 832 | that there is no unexpected or expected token to report. In that 833 | case, just report a simple "syntax error". 834 | - Don't assume there isn't a lookahead just because this state is a 835 | consistent state with a default action. There might have been a 836 | previous inconsistent state, consistent state with a non-default 837 | action, or user semantic action that manipulated yychar. 838 | - Of course, the expected token list depends on states to have 839 | correct lookahead information, and it depends on the parser not 840 | to perform extra reductions after fetching a lookahead from the 841 | scanner and before detecting a syntax error. Thus, state merging 842 | (from LALR or IELR) and default reductions corrupt the expected 843 | token list. However, the list is correct for canonical LR with 844 | one exception: it will still contain any token that will not be 845 | accepted due to an error action in a later state. 846 | */ 847 | if (yytoken != YYEMPTY) 848 | { 849 | int yyn = yypact[*yyssp]; 850 | yyarg[yycount++] = yytname[yytoken]; 851 | if (!yypact_value_is_default (yyn)) 852 | { 853 | /* Start YYX at -YYN if negative to avoid negative indexes in 854 | YYCHECK. In other words, skip the first -YYN actions for 855 | this state because they are default actions. */ 856 | int yyxbegin = yyn < 0 ? -yyn : 0; 857 | /* Stay within bounds of both yycheck and yytname. */ 858 | int yychecklim = YYLAST - yyn + 1; 859 | int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; 860 | int yyx; 861 | 862 | for (yyx = yyxbegin; yyx < yyxend; ++yyx) 863 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR 864 | && !yytable_value_is_error (yytable[yyx + yyn])) 865 | { 866 | if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) 867 | { 868 | yycount = 1; 869 | yysize = yysize0; 870 | break; 871 | } 872 | yyarg[yycount++] = yytname[yyx]; 873 | { 874 | YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); 875 | if (! (yysize <= yysize1 876 | && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) 877 | return 2; 878 | yysize = yysize1; 879 | } 880 | } 881 | } 882 | } 883 | 884 | switch (yycount) 885 | { 886 | # define YYCASE_(N, S) \ 887 | case N: \ 888 | yyformat = S; \ 889 | break 890 | YYCASE_(0, YY_("syntax error")); 891 | YYCASE_(1, YY_("syntax error, unexpected %s")); 892 | YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); 893 | YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); 894 | YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); 895 | YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); 896 | # undef YYCASE_ 897 | } 898 | 899 | { 900 | YYSIZE_T yysize1 = yysize + yystrlen (yyformat); 901 | if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) 902 | return 2; 903 | yysize = yysize1; 904 | } 905 | 906 | if (*yymsg_alloc < yysize) 907 | { 908 | *yymsg_alloc = 2 * yysize; 909 | if (! (yysize <= *yymsg_alloc 910 | && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) 911 | *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; 912 | return 1; 913 | } 914 | 915 | /* Avoid sprintf, as that infringes on the user's name space. 916 | Don't have undefined behavior even if the translation 917 | produced a string with the wrong number of "%s"s. */ 918 | { 919 | char *yyp = *yymsg; 920 | int yyi = 0; 921 | while ((*yyp = *yyformat) != '\0') 922 | if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) 923 | { 924 | yyp += yytnamerr (yyp, yyarg[yyi++]); 925 | yyformat += 2; 926 | } 927 | else 928 | { 929 | yyp++; 930 | yyformat++; 931 | } 932 | } 933 | return 0; 934 | } 935 | #endif /* YYERROR_VERBOSE */ 936 | 937 | /*-----------------------------------------------. 938 | | Release the memory associated to this symbol. | 939 | `-----------------------------------------------*/ 940 | 941 | static void 942 | yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) 943 | { 944 | YYUSE (yyvaluep); 945 | if (!yymsg) 946 | yymsg = "Deleting"; 947 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); 948 | 949 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 950 | YYUSE (yytype); 951 | YY_IGNORE_MAYBE_UNINITIALIZED_END 952 | } 953 | 954 | 955 | 956 | 957 | /* The lookahead symbol. */ 958 | int yychar; 959 | 960 | /* The semantic value of the lookahead symbol. */ 961 | YYSTYPE yylval; 962 | /* Number of syntax errors so far. */ 963 | int yynerrs; 964 | 965 | 966 | /*----------. 967 | | yyparse. | 968 | `----------*/ 969 | 970 | int 971 | yyparse (void) 972 | { 973 | int yystate; 974 | /* Number of tokens to shift before error messages enabled. */ 975 | int yyerrstatus; 976 | 977 | /* The stacks and their tools: 978 | 'yyss': related to states. 979 | 'yyvs': related to semantic values. 980 | 981 | Refer to the stacks through separate pointers, to allow yyoverflow 982 | to reallocate them elsewhere. */ 983 | 984 | /* The state stack. */ 985 | yytype_int16 yyssa[YYINITDEPTH]; 986 | yytype_int16 *yyss; 987 | yytype_int16 *yyssp; 988 | 989 | /* The semantic value stack. */ 990 | YYSTYPE yyvsa[YYINITDEPTH]; 991 | YYSTYPE *yyvs; 992 | YYSTYPE *yyvsp; 993 | 994 | YYSIZE_T yystacksize; 995 | 996 | int yyn; 997 | int yyresult; 998 | /* Lookahead token as an internal (translated) token number. */ 999 | int yytoken = 0; 1000 | /* The variables used to return semantic value and location from the 1001 | action routines. */ 1002 | YYSTYPE yyval; 1003 | 1004 | #if YYERROR_VERBOSE 1005 | /* Buffer for error messages, and its allocated size. */ 1006 | char yymsgbuf[128]; 1007 | char *yymsg = yymsgbuf; 1008 | YYSIZE_T yymsg_alloc = sizeof yymsgbuf; 1009 | #endif 1010 | 1011 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) 1012 | 1013 | /* The number of symbols on the RHS of the reduced rule. 1014 | Keep to zero when no symbol should be popped. */ 1015 | int yylen = 0; 1016 | 1017 | yyssp = yyss = yyssa; 1018 | yyvsp = yyvs = yyvsa; 1019 | yystacksize = YYINITDEPTH; 1020 | 1021 | YYDPRINTF ((stderr, "Starting parse\n")); 1022 | 1023 | yystate = 0; 1024 | yyerrstatus = 0; 1025 | yynerrs = 0; 1026 | yychar = YYEMPTY; /* Cause a token to be read. */ 1027 | goto yysetstate; 1028 | 1029 | /*------------------------------------------------------------. 1030 | | yynewstate -- Push a new state, which is found in yystate. | 1031 | `------------------------------------------------------------*/ 1032 | yynewstate: 1033 | /* In all cases, when you get here, the value and location stacks 1034 | have just been pushed. So pushing a state here evens the stacks. */ 1035 | yyssp++; 1036 | 1037 | yysetstate: 1038 | *yyssp = yystate; 1039 | 1040 | if (yyss + yystacksize - 1 <= yyssp) 1041 | { 1042 | /* Get the current used size of the three stacks, in elements. */ 1043 | YYSIZE_T yysize = yyssp - yyss + 1; 1044 | 1045 | #ifdef yyoverflow 1046 | { 1047 | /* Give user a chance to reallocate the stack. Use copies of 1048 | these so that the &'s don't force the real ones into 1049 | memory. */ 1050 | YYSTYPE *yyvs1 = yyvs; 1051 | yytype_int16 *yyss1 = yyss; 1052 | 1053 | /* Each stack pointer address is followed by the size of the 1054 | data in use in that stack, in bytes. This used to be a 1055 | conditional around just the two extra args, but that might 1056 | be undefined if yyoverflow is a macro. */ 1057 | yyoverflow (YY_("memory exhausted"), 1058 | &yyss1, yysize * sizeof (*yyssp), 1059 | &yyvs1, yysize * sizeof (*yyvsp), 1060 | &yystacksize); 1061 | 1062 | yyss = yyss1; 1063 | yyvs = yyvs1; 1064 | } 1065 | #else /* no yyoverflow */ 1066 | # ifndef YYSTACK_RELOCATE 1067 | goto yyexhaustedlab; 1068 | # else 1069 | /* Extend the stack our own way. */ 1070 | if (YYMAXDEPTH <= yystacksize) 1071 | goto yyexhaustedlab; 1072 | yystacksize *= 2; 1073 | if (YYMAXDEPTH < yystacksize) 1074 | yystacksize = YYMAXDEPTH; 1075 | 1076 | { 1077 | yytype_int16 *yyss1 = yyss; 1078 | union yyalloc *yyptr = 1079 | (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); 1080 | if (! yyptr) 1081 | goto yyexhaustedlab; 1082 | YYSTACK_RELOCATE (yyss_alloc, yyss); 1083 | YYSTACK_RELOCATE (yyvs_alloc, yyvs); 1084 | # undef YYSTACK_RELOCATE 1085 | if (yyss1 != yyssa) 1086 | YYSTACK_FREE (yyss1); 1087 | } 1088 | # endif 1089 | #endif /* no yyoverflow */ 1090 | 1091 | yyssp = yyss + yysize - 1; 1092 | yyvsp = yyvs + yysize - 1; 1093 | 1094 | YYDPRINTF ((stderr, "Stack size increased to %lu\n", 1095 | (unsigned long int) yystacksize)); 1096 | 1097 | if (yyss + yystacksize - 1 <= yyssp) 1098 | YYABORT; 1099 | } 1100 | 1101 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 1102 | 1103 | if (yystate == YYFINAL) 1104 | YYACCEPT; 1105 | 1106 | goto yybackup; 1107 | 1108 | /*-----------. 1109 | | yybackup. | 1110 | `-----------*/ 1111 | yybackup: 1112 | 1113 | /* Do appropriate processing given the current state. Read a 1114 | lookahead token if we need one and don't already have one. */ 1115 | 1116 | /* First try to decide what to do without reference to lookahead token. */ 1117 | yyn = yypact[yystate]; 1118 | if (yypact_value_is_default (yyn)) 1119 | goto yydefault; 1120 | 1121 | /* Not known => get a lookahead token if don't already have one. */ 1122 | 1123 | /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ 1124 | if (yychar == YYEMPTY) 1125 | { 1126 | YYDPRINTF ((stderr, "Reading a token: ")); 1127 | yychar = yylex (); 1128 | } 1129 | 1130 | if (yychar <= YYEOF) 1131 | { 1132 | yychar = yytoken = YYEOF; 1133 | YYDPRINTF ((stderr, "Now at end of input.\n")); 1134 | } 1135 | else 1136 | { 1137 | yytoken = YYTRANSLATE (yychar); 1138 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); 1139 | } 1140 | 1141 | /* If the proper action on seeing token YYTOKEN is to reduce or to 1142 | detect an error, take that action. */ 1143 | yyn += yytoken; 1144 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) 1145 | goto yydefault; 1146 | yyn = yytable[yyn]; 1147 | if (yyn <= 0) 1148 | { 1149 | if (yytable_value_is_error (yyn)) 1150 | goto yyerrlab; 1151 | yyn = -yyn; 1152 | goto yyreduce; 1153 | } 1154 | 1155 | /* Count tokens shifted since error; after three, turn off error 1156 | status. */ 1157 | if (yyerrstatus) 1158 | yyerrstatus--; 1159 | 1160 | /* Shift the lookahead token. */ 1161 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 1162 | 1163 | /* Discard the shifted token. */ 1164 | yychar = YYEMPTY; 1165 | 1166 | yystate = yyn; 1167 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1168 | *++yyvsp = yylval; 1169 | YY_IGNORE_MAYBE_UNINITIALIZED_END 1170 | 1171 | goto yynewstate; 1172 | 1173 | 1174 | /*-----------------------------------------------------------. 1175 | | yydefault -- do the default action for the current state. | 1176 | `-----------------------------------------------------------*/ 1177 | yydefault: 1178 | yyn = yydefact[yystate]; 1179 | if (yyn == 0) 1180 | goto yyerrlab; 1181 | goto yyreduce; 1182 | 1183 | 1184 | /*-----------------------------. 1185 | | yyreduce -- Do a reduction. | 1186 | `-----------------------------*/ 1187 | yyreduce: 1188 | /* yyn is the number of a rule to reduce with. */ 1189 | yylen = yyr2[yyn]; 1190 | 1191 | /* If YYLEN is nonzero, implement the default value of the action: 1192 | '$$ = $1'. 1193 | 1194 | Otherwise, the following line sets YYVAL to garbage. 1195 | This behavior is undocumented and Bison 1196 | users should not rely upon it. Assigning to YYVAL 1197 | unconditionally makes the parser a bit smaller, and it avoids a 1198 | GCC warning that YYVAL may be used uninitialized. */ 1199 | yyval = yyvsp[1-yylen]; 1200 | 1201 | 1202 | YY_REDUCE_PRINT (yyn); 1203 | switch (yyn) 1204 | { 1205 | case 5: 1206 | #line 30 "test.y" /* yacc.c:1646 */ 1207 | { 1208 | printf("Your entered a string - %s", (yyvsp[0].name)); 1209 | } 1210 | #line 1211 "test.tab.c" /* yacc.c:1646 */ 1211 | break; 1212 | 1213 | case 6: 1214 | #line 33 "test.y" /* yacc.c:1646 */ 1215 | { 1216 | printf("The number you entered is - %d", (yyvsp[0].number)); 1217 | } 1218 | #line 1219 "test.tab.c" /* yacc.c:1646 */ 1219 | break; 1220 | 1221 | 1222 | #line 1223 "test.tab.c" /* yacc.c:1646 */ 1223 | default: break; 1224 | } 1225 | /* User semantic actions sometimes alter yychar, and that requires 1226 | that yytoken be updated with the new translation. We take the 1227 | approach of translating immediately before every use of yytoken. 1228 | One alternative is translating here after every semantic action, 1229 | but that translation would be missed if the semantic action invokes 1230 | YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or 1231 | if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an 1232 | incorrect destructor might then be invoked immediately. In the 1233 | case of YYERROR or YYBACKUP, subsequent parser actions might lead 1234 | to an incorrect destructor call or verbose syntax error message 1235 | before the lookahead is translated. */ 1236 | YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); 1237 | 1238 | YYPOPSTACK (yylen); 1239 | yylen = 0; 1240 | YY_STACK_PRINT (yyss, yyssp); 1241 | 1242 | *++yyvsp = yyval; 1243 | 1244 | /* Now 'shift' the result of the reduction. Determine what state 1245 | that goes to, based on the state we popped back to and the rule 1246 | number reduced by. */ 1247 | 1248 | yyn = yyr1[yyn]; 1249 | 1250 | yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; 1251 | if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) 1252 | yystate = yytable[yystate]; 1253 | else 1254 | yystate = yydefgoto[yyn - YYNTOKENS]; 1255 | 1256 | goto yynewstate; 1257 | 1258 | 1259 | /*--------------------------------------. 1260 | | yyerrlab -- here on detecting error. | 1261 | `--------------------------------------*/ 1262 | yyerrlab: 1263 | /* Make sure we have latest lookahead translation. See comments at 1264 | user semantic actions for why this is necessary. */ 1265 | yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); 1266 | 1267 | /* If not already recovering from an error, report this error. */ 1268 | if (!yyerrstatus) 1269 | { 1270 | ++yynerrs; 1271 | #if ! YYERROR_VERBOSE 1272 | yyerror (YY_("syntax error")); 1273 | #else 1274 | # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ 1275 | yyssp, yytoken) 1276 | { 1277 | char const *yymsgp = YY_("syntax error"); 1278 | int yysyntax_error_status; 1279 | yysyntax_error_status = YYSYNTAX_ERROR; 1280 | if (yysyntax_error_status == 0) 1281 | yymsgp = yymsg; 1282 | else if (yysyntax_error_status == 1) 1283 | { 1284 | if (yymsg != yymsgbuf) 1285 | YYSTACK_FREE (yymsg); 1286 | yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); 1287 | if (!yymsg) 1288 | { 1289 | yymsg = yymsgbuf; 1290 | yymsg_alloc = sizeof yymsgbuf; 1291 | yysyntax_error_status = 2; 1292 | } 1293 | else 1294 | { 1295 | yysyntax_error_status = YYSYNTAX_ERROR; 1296 | yymsgp = yymsg; 1297 | } 1298 | } 1299 | yyerror (yymsgp); 1300 | if (yysyntax_error_status == 2) 1301 | goto yyexhaustedlab; 1302 | } 1303 | # undef YYSYNTAX_ERROR 1304 | #endif 1305 | } 1306 | 1307 | 1308 | 1309 | if (yyerrstatus == 3) 1310 | { 1311 | /* If just tried and failed to reuse lookahead token after an 1312 | error, discard it. */ 1313 | 1314 | if (yychar <= YYEOF) 1315 | { 1316 | /* Return failure if at end of input. */ 1317 | if (yychar == YYEOF) 1318 | YYABORT; 1319 | } 1320 | else 1321 | { 1322 | yydestruct ("Error: discarding", 1323 | yytoken, &yylval); 1324 | yychar = YYEMPTY; 1325 | } 1326 | } 1327 | 1328 | /* Else will try to reuse lookahead token after shifting the error 1329 | token. */ 1330 | goto yyerrlab1; 1331 | 1332 | 1333 | /*---------------------------------------------------. 1334 | | yyerrorlab -- error raised explicitly by YYERROR. | 1335 | `---------------------------------------------------*/ 1336 | yyerrorlab: 1337 | 1338 | /* Pacify compilers like GCC when the user code never invokes 1339 | YYERROR and the label yyerrorlab therefore never appears in user 1340 | code. */ 1341 | if (/*CONSTCOND*/ 0) 1342 | goto yyerrorlab; 1343 | 1344 | /* Do not reclaim the symbols of the rule whose action triggered 1345 | this YYERROR. */ 1346 | YYPOPSTACK (yylen); 1347 | yylen = 0; 1348 | YY_STACK_PRINT (yyss, yyssp); 1349 | yystate = *yyssp; 1350 | goto yyerrlab1; 1351 | 1352 | 1353 | /*-------------------------------------------------------------. 1354 | | yyerrlab1 -- common code for both syntax error and YYERROR. | 1355 | `-------------------------------------------------------------*/ 1356 | yyerrlab1: 1357 | yyerrstatus = 3; /* Each real token shifted decrements this. */ 1358 | 1359 | for (;;) 1360 | { 1361 | yyn = yypact[yystate]; 1362 | if (!yypact_value_is_default (yyn)) 1363 | { 1364 | yyn += YYTERROR; 1365 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) 1366 | { 1367 | yyn = yytable[yyn]; 1368 | if (0 < yyn) 1369 | break; 1370 | } 1371 | } 1372 | 1373 | /* Pop the current state because it cannot handle the error token. */ 1374 | if (yyssp == yyss) 1375 | YYABORT; 1376 | 1377 | 1378 | yydestruct ("Error: popping", 1379 | yystos[yystate], yyvsp); 1380 | YYPOPSTACK (1); 1381 | yystate = *yyssp; 1382 | YY_STACK_PRINT (yyss, yyssp); 1383 | } 1384 | 1385 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1386 | *++yyvsp = yylval; 1387 | YY_IGNORE_MAYBE_UNINITIALIZED_END 1388 | 1389 | 1390 | /* Shift the error token. */ 1391 | YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); 1392 | 1393 | yystate = yyn; 1394 | goto yynewstate; 1395 | 1396 | 1397 | /*-------------------------------------. 1398 | | yyacceptlab -- YYACCEPT comes here. | 1399 | `-------------------------------------*/ 1400 | yyacceptlab: 1401 | yyresult = 0; 1402 | goto yyreturn; 1403 | 1404 | /*-----------------------------------. 1405 | | yyabortlab -- YYABORT comes here. | 1406 | `-----------------------------------*/ 1407 | yyabortlab: 1408 | yyresult = 1; 1409 | goto yyreturn; 1410 | 1411 | #if !defined yyoverflow || YYERROR_VERBOSE 1412 | /*-------------------------------------------------. 1413 | | yyexhaustedlab -- memory exhaustion comes here. | 1414 | `-------------------------------------------------*/ 1415 | yyexhaustedlab: 1416 | yyerror (YY_("memory exhausted")); 1417 | yyresult = 2; 1418 | /* Fall through. */ 1419 | #endif 1420 | 1421 | yyreturn: 1422 | if (yychar != YYEMPTY) 1423 | { 1424 | /* Make sure we have latest lookahead translation. See comments at 1425 | user semantic actions for why this is necessary. */ 1426 | yytoken = YYTRANSLATE (yychar); 1427 | yydestruct ("Cleanup: discarding lookahead", 1428 | yytoken, &yylval); 1429 | } 1430 | /* Do not reclaim the symbols of the rule whose action triggered 1431 | this YYABORT or YYACCEPT. */ 1432 | YYPOPSTACK (yylen); 1433 | YY_STACK_PRINT (yyss, yyssp); 1434 | while (yyssp != yyss) 1435 | { 1436 | yydestruct ("Cleanup: popping", 1437 | yystos[*yyssp], yyvsp); 1438 | YYPOPSTACK (1); 1439 | } 1440 | #ifndef yyoverflow 1441 | if (yyss != yyssa) 1442 | YYSTACK_FREE (yyss); 1443 | #endif 1444 | #if YYERROR_VERBOSE 1445 | if (yymsg != yymsgbuf) 1446 | YYSTACK_FREE (yymsg); 1447 | #endif 1448 | return yyresult; 1449 | } 1450 | #line 39 "test.y" /* yacc.c:1906 */ 1451 | 1452 | 1453 | int yyerror(char *s) 1454 | { 1455 | printf("Syntax Error on line %s\n", s); 1456 | return 0; 1457 | } 1458 | 1459 | int main() 1460 | { 1461 | yyparse(); 1462 | return 0; 1463 | } 1464 | -------------------------------------------------------------------------------- /lex.yy.c: -------------------------------------------------------------------------------- 1 | 2 | #line 3 "lex.yy.c" 3 | 4 | #define YY_INT_ALIGNED short int 5 | 6 | /* A lexical scanner generated by flex */ 7 | 8 | #define FLEX_SCANNER 9 | #define YY_FLEX_MAJOR_VERSION 2 10 | #define YY_FLEX_MINOR_VERSION 6 11 | #define YY_FLEX_SUBMINOR_VERSION 4 12 | #if YY_FLEX_SUBMINOR_VERSION > 0 13 | #define FLEX_BETA 14 | #endif 15 | 16 | /* First, we deal with platform-specific or compiler-specific issues. */ 17 | 18 | /* begin standard C headers. */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | /* end standard C headers. */ 25 | 26 | /* flex integer type definitions */ 27 | 28 | #ifndef FLEXINT_H 29 | #define FLEXINT_H 30 | 31 | /* C99 systems have . Non-C99 systems may or may not. */ 32 | 33 | #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 34 | 35 | /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, 36 | * if you want the limit (max/min) macros for int types. 37 | */ 38 | #ifndef __STDC_LIMIT_MACROS 39 | #define __STDC_LIMIT_MACROS 1 40 | #endif 41 | 42 | #include 43 | typedef int8_t flex_int8_t; 44 | typedef uint8_t flex_uint8_t; 45 | typedef int16_t flex_int16_t; 46 | typedef uint16_t flex_uint16_t; 47 | typedef int32_t flex_int32_t; 48 | typedef uint32_t flex_uint32_t; 49 | #else 50 | typedef signed char flex_int8_t; 51 | typedef short int flex_int16_t; 52 | typedef int flex_int32_t; 53 | typedef unsigned char flex_uint8_t; 54 | typedef unsigned short int flex_uint16_t; 55 | typedef unsigned int flex_uint32_t; 56 | 57 | /* Limits of integral types. */ 58 | #ifndef INT8_MIN 59 | #define INT8_MIN (-128) 60 | #endif 61 | #ifndef INT16_MIN 62 | #define INT16_MIN (-32767-1) 63 | #endif 64 | #ifndef INT32_MIN 65 | #define INT32_MIN (-2147483647-1) 66 | #endif 67 | #ifndef INT8_MAX 68 | #define INT8_MAX (127) 69 | #endif 70 | #ifndef INT16_MAX 71 | #define INT16_MAX (32767) 72 | #endif 73 | #ifndef INT32_MAX 74 | #define INT32_MAX (2147483647) 75 | #endif 76 | #ifndef UINT8_MAX 77 | #define UINT8_MAX (255U) 78 | #endif 79 | #ifndef UINT16_MAX 80 | #define UINT16_MAX (65535U) 81 | #endif 82 | #ifndef UINT32_MAX 83 | #define UINT32_MAX (4294967295U) 84 | #endif 85 | 86 | #ifndef SIZE_MAX 87 | #define SIZE_MAX (~(size_t)0) 88 | #endif 89 | 90 | #endif /* ! C99 */ 91 | 92 | #endif /* ! FLEXINT_H */ 93 | 94 | /* begin standard C++ headers. */ 95 | 96 | /* TODO: this is always defined, so inline it */ 97 | #define yyconst const 98 | 99 | #if defined(__GNUC__) && __GNUC__ >= 3 100 | #define yynoreturn __attribute__((__noreturn__)) 101 | #else 102 | #define yynoreturn 103 | #endif 104 | 105 | /* Returned upon end-of-file. */ 106 | #define YY_NULL 0 107 | 108 | /* Promotes a possibly negative, possibly signed char to an 109 | * integer in range [0..255] for use as an array index. 110 | */ 111 | #define YY_SC_TO_UI(c) ((YY_CHAR) (c)) 112 | 113 | /* Enter a start condition. This macro really ought to take a parameter, 114 | * but we do it the disgusting crufty way forced on us by the ()-less 115 | * definition of BEGIN. 116 | */ 117 | #define BEGIN (yy_start) = 1 + 2 * 118 | /* Translate the current start state into a value that can be later handed 119 | * to BEGIN to return to the state. The YYSTATE alias is for lex 120 | * compatibility. 121 | */ 122 | #define YY_START (((yy_start) - 1) / 2) 123 | #define YYSTATE YY_START 124 | /* Action number for EOF rule of a given start state. */ 125 | #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) 126 | /* Special action meaning "start processing a new file". */ 127 | #define YY_NEW_FILE yyrestart( yyin ) 128 | #define YY_END_OF_BUFFER_CHAR 0 129 | 130 | /* Size of default input buffer. */ 131 | #ifndef YY_BUF_SIZE 132 | #ifdef __ia64__ 133 | /* On IA-64, the buffer size is 16k, not 8k. 134 | * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. 135 | * Ditto for the __ia64__ case accordingly. 136 | */ 137 | #define YY_BUF_SIZE 32768 138 | #else 139 | #define YY_BUF_SIZE 16384 140 | #endif /* __ia64__ */ 141 | #endif 142 | 143 | /* The state buf must be large enough to hold one state per character in the main buffer. 144 | */ 145 | #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) 146 | 147 | #ifndef YY_TYPEDEF_YY_BUFFER_STATE 148 | #define YY_TYPEDEF_YY_BUFFER_STATE 149 | typedef struct yy_buffer_state *YY_BUFFER_STATE; 150 | #endif 151 | 152 | #ifndef YY_TYPEDEF_YY_SIZE_T 153 | #define YY_TYPEDEF_YY_SIZE_T 154 | typedef size_t yy_size_t; 155 | #endif 156 | 157 | extern int yyleng; 158 | 159 | extern FILE *yyin, *yyout; 160 | 161 | #define EOB_ACT_CONTINUE_SCAN 0 162 | #define EOB_ACT_END_OF_FILE 1 163 | #define EOB_ACT_LAST_MATCH 2 164 | 165 | /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires 166 | * access to the local variable yy_act. Since yyless() is a macro, it would break 167 | * existing scanners that call yyless() from OUTSIDE yylex. 168 | * One obvious solution it to make yy_act a global. I tried that, and saw 169 | * a 5% performance hit in a non-yylineno scanner, because yy_act is 170 | * normally declared as a register variable-- so it is not worth it. 171 | */ 172 | #define YY_LESS_LINENO(n) \ 173 | do { \ 174 | int yyl;\ 175 | for ( yyl = n; yyl < yyleng; ++yyl )\ 176 | if ( yytext[yyl] == '\n' )\ 177 | --yylineno;\ 178 | }while(0) 179 | #define YY_LINENO_REWIND_TO(dst) \ 180 | do {\ 181 | const char *p;\ 182 | for ( p = yy_cp-1; p >= (dst); --p)\ 183 | if ( *p == '\n' )\ 184 | --yylineno;\ 185 | }while(0) 186 | 187 | /* Return all but the first "n" matched characters back to the input stream. */ 188 | #define yyless(n) \ 189 | do \ 190 | { \ 191 | /* Undo effects of setting up yytext. */ \ 192 | int yyless_macro_arg = (n); \ 193 | YY_LESS_LINENO(yyless_macro_arg);\ 194 | *yy_cp = (yy_hold_char); \ 195 | YY_RESTORE_YY_MORE_OFFSET \ 196 | (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ 197 | YY_DO_BEFORE_ACTION; /* set up yytext again */ \ 198 | } \ 199 | while ( 0 ) 200 | #define unput(c) yyunput( c, (yytext_ptr) ) 201 | 202 | #ifndef YY_STRUCT_YY_BUFFER_STATE 203 | #define YY_STRUCT_YY_BUFFER_STATE 204 | struct yy_buffer_state 205 | { 206 | FILE *yy_input_file; 207 | 208 | char *yy_ch_buf; /* input buffer */ 209 | char *yy_buf_pos; /* current position in input buffer */ 210 | 211 | /* Size of input buffer in bytes, not including room for EOB 212 | * characters. 213 | */ 214 | int yy_buf_size; 215 | 216 | /* Number of characters read into yy_ch_buf, not including EOB 217 | * characters. 218 | */ 219 | int yy_n_chars; 220 | 221 | /* Whether we "own" the buffer - i.e., we know we created it, 222 | * and can realloc() it to grow it, and should free() it to 223 | * delete it. 224 | */ 225 | int yy_is_our_buffer; 226 | 227 | /* Whether this is an "interactive" input source; if so, and 228 | * if we're using stdio for input, then we want to use getc() 229 | * instead of fread(), to make sure we stop fetching input after 230 | * each newline. 231 | */ 232 | int yy_is_interactive; 233 | 234 | /* Whether we're considered to be at the beginning of a line. 235 | * If so, '^' rules will be active on the next match, otherwise 236 | * not. 237 | */ 238 | int yy_at_bol; 239 | 240 | int yy_bs_lineno; /**< The line count. */ 241 | int yy_bs_column; /**< The column count. */ 242 | 243 | /* Whether to try to fill the input buffer when we reach the 244 | * end of it. 245 | */ 246 | int yy_fill_buffer; 247 | 248 | int yy_buffer_status; 249 | 250 | #define YY_BUFFER_NEW 0 251 | #define YY_BUFFER_NORMAL 1 252 | /* When an EOF's been seen but there's still some text to process 253 | * then we mark the buffer as YY_EOF_PENDING, to indicate that we 254 | * shouldn't try reading from the input source any more. We might 255 | * still have a bunch of tokens to match, though, because of 256 | * possible backing-up. 257 | * 258 | * When we actually see the EOF, we change the status to "new" 259 | * (via yyrestart()), so that the user can continue scanning by 260 | * just pointing yyin at a new input file. 261 | */ 262 | #define YY_BUFFER_EOF_PENDING 2 263 | 264 | }; 265 | #endif /* !YY_STRUCT_YY_BUFFER_STATE */ 266 | 267 | /* Stack of input buffers. */ 268 | static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ 269 | static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ 270 | static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ 271 | 272 | /* We provide macros for accessing buffer states in case in the 273 | * future we want to put the buffer states in a more general 274 | * "scanner state". 275 | * 276 | * Returns the top of the stack, or NULL. 277 | */ 278 | #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ 279 | ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ 280 | : NULL) 281 | /* Same as previous macro, but useful when we know that the buffer stack is not 282 | * NULL or when we need an lvalue. For internal use only. 283 | */ 284 | #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] 285 | 286 | /* yy_hold_char holds the character lost when yytext is formed. */ 287 | static char yy_hold_char; 288 | static int yy_n_chars; /* number of characters read into yy_ch_buf */ 289 | int yyleng; 290 | 291 | /* Points to current character in buffer. */ 292 | static char *yy_c_buf_p = NULL; 293 | static int yy_init = 0; /* whether we need to initialize */ 294 | static int yy_start = 0; /* start state number */ 295 | 296 | /* Flag which is used to allow yywrap()'s to do buffer switches 297 | * instead of setting up a fresh yyin. A bit of a hack ... 298 | */ 299 | static int yy_did_buffer_switch_on_eof; 300 | 301 | void yyrestart ( FILE *input_file ); 302 | void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); 303 | YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); 304 | void yy_delete_buffer ( YY_BUFFER_STATE b ); 305 | void yy_flush_buffer ( YY_BUFFER_STATE b ); 306 | void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); 307 | void yypop_buffer_state ( void ); 308 | 309 | static void yyensure_buffer_stack ( void ); 310 | static void yy_load_buffer_state ( void ); 311 | static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); 312 | #define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) 313 | 314 | YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); 315 | YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); 316 | YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); 317 | 318 | void *yyalloc ( yy_size_t ); 319 | void *yyrealloc ( void *, yy_size_t ); 320 | void yyfree ( void * ); 321 | 322 | #define yy_new_buffer yy_create_buffer 323 | #define yy_set_interactive(is_interactive) \ 324 | { \ 325 | if ( ! YY_CURRENT_BUFFER ){ \ 326 | yyensure_buffer_stack (); \ 327 | YY_CURRENT_BUFFER_LVALUE = \ 328 | yy_create_buffer( yyin, YY_BUF_SIZE ); \ 329 | } \ 330 | YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ 331 | } 332 | #define yy_set_bol(at_bol) \ 333 | { \ 334 | if ( ! YY_CURRENT_BUFFER ){\ 335 | yyensure_buffer_stack (); \ 336 | YY_CURRENT_BUFFER_LVALUE = \ 337 | yy_create_buffer( yyin, YY_BUF_SIZE ); \ 338 | } \ 339 | YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ 340 | } 341 | #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) 342 | 343 | /* Begin user sect3 */ 344 | typedef flex_uint8_t YY_CHAR; 345 | 346 | FILE *yyin = NULL, *yyout = NULL; 347 | 348 | typedef int yy_state_type; 349 | 350 | #define YY_FLEX_LEX_COMPAT 351 | extern int yylineno; 352 | int yylineno = 1; 353 | 354 | extern char yytext[]; 355 | 356 | static yy_state_type yy_get_previous_state ( void ); 357 | static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); 358 | static int yy_get_next_buffer ( void ); 359 | static void yynoreturn yy_fatal_error ( const char* msg ); 360 | 361 | /* Done after the current pattern has been matched and before the 362 | * corresponding action - sets up yytext. 363 | */ 364 | #define YY_DO_BEFORE_ACTION \ 365 | (yytext_ptr) = yy_bp; \ 366 | yyleng = (int) (yy_cp - yy_bp); \ 367 | (yy_hold_char) = *yy_cp; \ 368 | *yy_cp = '\0'; \ 369 | if ( yyleng >= YYLMAX ) \ 370 | YY_FATAL_ERROR( "token too large, exceeds YYLMAX" ); \ 371 | yy_flex_strncpy( yytext, (yytext_ptr), yyleng + 1 ); \ 372 | (yy_c_buf_p) = yy_cp; 373 | #define YY_NUM_RULES 5 374 | #define YY_END_OF_BUFFER 6 375 | /* This struct is not used in this scanner, 376 | but its presence is necessary. */ 377 | struct yy_trans_info 378 | { 379 | flex_int32_t yy_verify; 380 | flex_int32_t yy_nxt; 381 | }; 382 | static const flex_int16_t yy_accept[12] = 383 | { 0, 384 | 0, 0, 6, 4, 5, 2, 3, 1, 2, 1, 385 | 0 386 | } ; 387 | 388 | static const YY_CHAR yy_ec[256] = 389 | { 0, 390 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 391 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 392 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 393 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 394 | 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 395 | 3, 3, 3, 3, 3, 3, 3, 1, 4, 1, 396 | 1, 1, 1, 1, 5, 5, 5, 5, 5, 5, 397 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 398 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 399 | 1, 1, 1, 1, 1, 1, 5, 5, 5, 5, 400 | 401 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 402 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 403 | 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 404 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 405 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 406 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 407 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 408 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 409 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 410 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 411 | 412 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 413 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 414 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 415 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 416 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 417 | 1, 1, 1, 1, 1 418 | } ; 419 | 420 | static const YY_CHAR yy_meta[6] = 421 | { 0, 422 | 1, 1, 2, 1, 3 423 | } ; 424 | 425 | static const flex_int16_t yy_base[14] = 426 | { 0, 427 | 0, 0, 8, 9, 9, 0, 9, 0, 0, 0, 428 | 9, 5, 3 429 | } ; 430 | 431 | static const flex_int16_t yy_def[14] = 432 | { 0, 433 | 11, 1, 11, 11, 11, 12, 11, 13, 12, 13, 434 | 0, 11, 11 435 | } ; 436 | 437 | static const flex_int16_t yy_nxt[15] = 438 | { 0, 439 | 4, 5, 6, 7, 8, 10, 9, 11, 3, 11, 440 | 11, 11, 11, 11 441 | } ; 442 | 443 | static const flex_int16_t yy_chk[15] = 444 | { 0, 445 | 1, 1, 1, 1, 1, 13, 12, 3, 11, 11, 446 | 11, 11, 11, 11 447 | } ; 448 | 449 | /* Table of booleans, true if rule could match eol. */ 450 | static const flex_int32_t yy_rule_can_match_eol[6] = 451 | { 0, 452 | 0, 0, 0, 0, 0, }; 453 | 454 | static yy_state_type yy_last_accepting_state; 455 | static char *yy_last_accepting_cpos; 456 | 457 | extern int yy_flex_debug; 458 | int yy_flex_debug = 0; 459 | 460 | /* The intent behind this definition is that it'll catch 461 | * any uses of REJECT which flex missed. 462 | */ 463 | #define REJECT reject_used_but_not_detected 464 | #define yymore() yymore_used_but_not_detected 465 | #define YY_MORE_ADJ 0 466 | #define YY_RESTORE_YY_MORE_OFFSET 467 | #ifndef YYLMAX 468 | #define YYLMAX 8192 469 | #endif 470 | 471 | char yytext[YYLMAX]; 472 | char *yytext_ptr; 473 | #line 1 "test.l" 474 | #line 2 "test.l" 475 | 476 | #include 477 | #include 478 | #include "test.tab.h" 479 | void showError(); 480 | #line 481 "lex.yy.c" 481 | #line 482 "lex.yy.c" 482 | 483 | #define INITIAL 0 484 | 485 | #ifndef YY_NO_UNISTD_H 486 | /* Special case for "unistd.h", since it is non-ANSI. We include it way 487 | * down here because we want the user's section 1 to have been scanned first. 488 | * The user has a chance to override it with an option. 489 | */ 490 | #include 491 | #endif 492 | 493 | #ifndef YY_EXTRA_TYPE 494 | #define YY_EXTRA_TYPE void * 495 | #endif 496 | 497 | static int yy_init_globals ( void ); 498 | 499 | /* Accessor methods to globals. 500 | These are made visible to non-reentrant scanners for convenience. */ 501 | 502 | int yylex_destroy ( void ); 503 | 504 | int yyget_debug ( void ); 505 | 506 | void yyset_debug ( int debug_flag ); 507 | 508 | YY_EXTRA_TYPE yyget_extra ( void ); 509 | 510 | void yyset_extra ( YY_EXTRA_TYPE user_defined ); 511 | 512 | FILE *yyget_in ( void ); 513 | 514 | void yyset_in ( FILE * _in_str ); 515 | 516 | FILE *yyget_out ( void ); 517 | 518 | void yyset_out ( FILE * _out_str ); 519 | 520 | int yyget_leng ( void ); 521 | 522 | char *yyget_text ( void ); 523 | 524 | int yyget_lineno ( void ); 525 | 526 | void yyset_lineno ( int _line_number ); 527 | 528 | /* Macros after this point can all be overridden by user definitions in 529 | * section 1. 530 | */ 531 | 532 | #ifndef YY_SKIP_YYWRAP 533 | #ifdef __cplusplus 534 | extern "C" int yywrap ( void ); 535 | #else 536 | extern int yywrap ( void ); 537 | #endif 538 | #endif 539 | 540 | #ifndef YY_NO_UNPUT 541 | 542 | static void yyunput ( int c, char *buf_ptr ); 543 | 544 | #endif 545 | 546 | #ifndef yytext_ptr 547 | static void yy_flex_strncpy ( char *, const char *, int ); 548 | #endif 549 | 550 | #ifdef YY_NEED_STRLEN 551 | static int yy_flex_strlen ( const char * ); 552 | #endif 553 | 554 | #ifndef YY_NO_INPUT 555 | #ifdef __cplusplus 556 | static int yyinput ( void ); 557 | #else 558 | static int input ( void ); 559 | #endif 560 | 561 | #endif 562 | 563 | /* Amount of stuff to slurp up with each read. */ 564 | #ifndef YY_READ_BUF_SIZE 565 | #ifdef __ia64__ 566 | /* On IA-64, the buffer size is 16k, not 8k */ 567 | #define YY_READ_BUF_SIZE 16384 568 | #else 569 | #define YY_READ_BUF_SIZE 8192 570 | #endif /* __ia64__ */ 571 | #endif 572 | 573 | /* Copy whatever the last rule matched to the standard output. */ 574 | #ifndef ECHO 575 | /* This used to be an fputs(), but since the string might contain NUL's, 576 | * we now use fwrite(). 577 | */ 578 | #define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) 579 | #endif 580 | 581 | /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, 582 | * is returned in "result". 583 | */ 584 | #ifndef YY_INPUT 585 | #define YY_INPUT(buf,result,max_size) \ 586 | if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ 587 | { \ 588 | int c = '*'; \ 589 | int n; \ 590 | for ( n = 0; n < max_size && \ 591 | (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ 592 | buf[n] = (char) c; \ 593 | if ( c == '\n' ) \ 594 | buf[n++] = (char) c; \ 595 | if ( c == EOF && ferror( yyin ) ) \ 596 | YY_FATAL_ERROR( "input in flex scanner failed" ); \ 597 | result = n; \ 598 | } \ 599 | else \ 600 | { \ 601 | errno=0; \ 602 | while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ 603 | { \ 604 | if( errno != EINTR) \ 605 | { \ 606 | YY_FATAL_ERROR( "input in flex scanner failed" ); \ 607 | break; \ 608 | } \ 609 | errno=0; \ 610 | clearerr(yyin); \ 611 | } \ 612 | }\ 613 | \ 614 | 615 | #endif 616 | 617 | /* No semi-colon after return; correct usage is to write "yyterminate();" - 618 | * we don't want an extra ';' after the "return" because that will cause 619 | * some compilers to complain about unreachable statements. 620 | */ 621 | #ifndef yyterminate 622 | #define yyterminate() return YY_NULL 623 | #endif 624 | 625 | /* Number of entries by which start-condition stack grows. */ 626 | #ifndef YY_START_STACK_INCR 627 | #define YY_START_STACK_INCR 25 628 | #endif 629 | 630 | /* Report a fatal error. */ 631 | #ifndef YY_FATAL_ERROR 632 | #define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) 633 | #endif 634 | 635 | /* end tables serialization structures and prototypes */ 636 | 637 | /* Default declaration of generated scanner - a define so the user can 638 | * easily add parameters. 639 | */ 640 | #ifndef YY_DECL 641 | #define YY_DECL_IS_OURS 1 642 | 643 | extern int yylex (void); 644 | 645 | #define YY_DECL int yylex (void) 646 | #endif /* !YY_DECL */ 647 | 648 | /* Code executed at the beginning of each rule, after yytext and yyleng 649 | * have been set up. 650 | */ 651 | #ifndef YY_USER_ACTION 652 | #define YY_USER_ACTION 653 | #endif 654 | 655 | /* Code executed at the end of each rule. */ 656 | #ifndef YY_BREAK 657 | #define YY_BREAK /*LINTED*/break; 658 | #endif 659 | 660 | #define YY_RULE_SETUP \ 661 | YY_USER_ACTION 662 | 663 | /** The main scanner function which does all the work. 664 | */ 665 | YY_DECL 666 | { 667 | yy_state_type yy_current_state; 668 | char *yy_cp, *yy_bp; 669 | int yy_act; 670 | 671 | if ( !(yy_init) ) 672 | { 673 | (yy_init) = 1; 674 | 675 | #ifdef YY_USER_INIT 676 | YY_USER_INIT; 677 | #endif 678 | 679 | if ( ! (yy_start) ) 680 | (yy_start) = 1; /* first start state */ 681 | 682 | if ( ! yyin ) 683 | yyin = stdin; 684 | 685 | if ( ! yyout ) 686 | yyout = stdout; 687 | 688 | if ( ! YY_CURRENT_BUFFER ) { 689 | yyensure_buffer_stack (); 690 | YY_CURRENT_BUFFER_LVALUE = 691 | yy_create_buffer( yyin, YY_BUF_SIZE ); 692 | } 693 | 694 | yy_load_buffer_state( ); 695 | } 696 | 697 | { 698 | #line 13 "test.l" 699 | 700 | 701 | #line 702 "lex.yy.c" 702 | 703 | while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ 704 | { 705 | yy_cp = (yy_c_buf_p); 706 | 707 | /* Support of yytext. */ 708 | *yy_cp = (yy_hold_char); 709 | 710 | /* yy_bp points to the position in yy_ch_buf of the start of 711 | * the current run. 712 | */ 713 | yy_bp = yy_cp; 714 | 715 | yy_current_state = (yy_start); 716 | yy_match: 717 | do 718 | { 719 | YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; 720 | if ( yy_accept[yy_current_state] ) 721 | { 722 | (yy_last_accepting_state) = yy_current_state; 723 | (yy_last_accepting_cpos) = yy_cp; 724 | } 725 | while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 726 | { 727 | yy_current_state = (int) yy_def[yy_current_state]; 728 | if ( yy_current_state >= 12 ) 729 | yy_c = yy_meta[yy_c]; 730 | } 731 | yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; 732 | ++yy_cp; 733 | } 734 | while ( yy_base[yy_current_state] != 9 ); 735 | 736 | yy_find_action: 737 | yy_act = yy_accept[yy_current_state]; 738 | if ( yy_act == 0 ) 739 | { /* have to back up */ 740 | yy_cp = (yy_last_accepting_cpos); 741 | yy_current_state = (yy_last_accepting_state); 742 | yy_act = yy_accept[yy_current_state]; 743 | } 744 | 745 | YY_DO_BEFORE_ACTION; 746 | 747 | if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) 748 | { 749 | int yyl; 750 | for ( yyl = 0; yyl < yyleng; ++yyl ) 751 | if ( yytext[yyl] == '\n' ) 752 | 753 | yylineno++; 754 | ; 755 | } 756 | 757 | do_action: /* This label is used only to access EOF actions. */ 758 | 759 | switch ( yy_act ) 760 | { /* beginning of action switch */ 761 | case 0: /* must back up */ 762 | /* undo the effects of YY_DO_BEFORE_ACTION */ 763 | *yy_cp = (yy_hold_char); 764 | yy_cp = (yy_last_accepting_cpos); 765 | yy_current_state = (yy_last_accepting_state); 766 | goto yy_find_action; 767 | 768 | case 1: 769 | YY_RULE_SETUP 770 | #line 15 "test.l" 771 | {sscanf(yytext, "%s", yylval.name); return (STRING);} 772 | YY_BREAK 773 | case 2: 774 | YY_RULE_SETUP 775 | #line 16 "test.l" 776 | {yylval.number = atoi(yytext); return (NUM);} 777 | YY_BREAK 778 | case 3: 779 | YY_RULE_SETUP 780 | #line 17 "test.l" 781 | {return (SEMICOLON);} 782 | YY_BREAK 783 | case 4: 784 | YY_RULE_SETUP 785 | #line 18 "test.l" 786 | {showError(); return(OTHER);} 787 | YY_BREAK 788 | case 5: 789 | YY_RULE_SETUP 790 | #line 20 "test.l" 791 | ECHO; 792 | YY_BREAK 793 | #line 794 "lex.yy.c" 794 | case YY_STATE_EOF(INITIAL): 795 | yyterminate(); 796 | 797 | case YY_END_OF_BUFFER: 798 | { 799 | /* Amount of text matched not including the EOB char. */ 800 | int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; 801 | 802 | /* Undo the effects of YY_DO_BEFORE_ACTION. */ 803 | *yy_cp = (yy_hold_char); 804 | YY_RESTORE_YY_MORE_OFFSET 805 | 806 | if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) 807 | { 808 | /* We're scanning a new file or input source. It's 809 | * possible that this happened because the user 810 | * just pointed yyin at a new source and called 811 | * yylex(). If so, then we have to assure 812 | * consistency between YY_CURRENT_BUFFER and our 813 | * globals. Here is the right place to do so, because 814 | * this is the first action (other than possibly a 815 | * back-up) that will match for the new input source. 816 | */ 817 | (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; 818 | YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; 819 | YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; 820 | } 821 | 822 | /* Note that here we test for yy_c_buf_p "<=" to the position 823 | * of the first EOB in the buffer, since yy_c_buf_p will 824 | * already have been incremented past the NUL character 825 | * (since all states make transitions on EOB to the 826 | * end-of-buffer state). Contrast this with the test 827 | * in input(). 828 | */ 829 | if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) 830 | { /* This was really a NUL. */ 831 | yy_state_type yy_next_state; 832 | 833 | (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; 834 | 835 | yy_current_state = yy_get_previous_state( ); 836 | 837 | /* Okay, we're now positioned to make the NUL 838 | * transition. We couldn't have 839 | * yy_get_previous_state() go ahead and do it 840 | * for us because it doesn't know how to deal 841 | * with the possibility of jamming (and we don't 842 | * want to build jamming into it because then it 843 | * will run more slowly). 844 | */ 845 | 846 | yy_next_state = yy_try_NUL_trans( yy_current_state ); 847 | 848 | yy_bp = (yytext_ptr) + YY_MORE_ADJ; 849 | 850 | if ( yy_next_state ) 851 | { 852 | /* Consume the NUL. */ 853 | yy_cp = ++(yy_c_buf_p); 854 | yy_current_state = yy_next_state; 855 | goto yy_match; 856 | } 857 | 858 | else 859 | { 860 | yy_cp = (yy_c_buf_p); 861 | goto yy_find_action; 862 | } 863 | } 864 | 865 | else switch ( yy_get_next_buffer( ) ) 866 | { 867 | case EOB_ACT_END_OF_FILE: 868 | { 869 | (yy_did_buffer_switch_on_eof) = 0; 870 | 871 | if ( yywrap( ) ) 872 | { 873 | /* Note: because we've taken care in 874 | * yy_get_next_buffer() to have set up 875 | * yytext, we can now set up 876 | * yy_c_buf_p so that if some total 877 | * hoser (like flex itself) wants to 878 | * call the scanner after we return the 879 | * YY_NULL, it'll still work - another 880 | * YY_NULL will get returned. 881 | */ 882 | (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; 883 | 884 | yy_act = YY_STATE_EOF(YY_START); 885 | goto do_action; 886 | } 887 | 888 | else 889 | { 890 | if ( ! (yy_did_buffer_switch_on_eof) ) 891 | YY_NEW_FILE; 892 | } 893 | break; 894 | } 895 | 896 | case EOB_ACT_CONTINUE_SCAN: 897 | (yy_c_buf_p) = 898 | (yytext_ptr) + yy_amount_of_matched_text; 899 | 900 | yy_current_state = yy_get_previous_state( ); 901 | 902 | yy_cp = (yy_c_buf_p); 903 | yy_bp = (yytext_ptr) + YY_MORE_ADJ; 904 | goto yy_match; 905 | 906 | case EOB_ACT_LAST_MATCH: 907 | (yy_c_buf_p) = 908 | &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; 909 | 910 | yy_current_state = yy_get_previous_state( ); 911 | 912 | yy_cp = (yy_c_buf_p); 913 | yy_bp = (yytext_ptr) + YY_MORE_ADJ; 914 | goto yy_find_action; 915 | } 916 | break; 917 | } 918 | 919 | default: 920 | YY_FATAL_ERROR( 921 | "fatal flex scanner internal error--no action found" ); 922 | } /* end of action switch */ 923 | } /* end of scanning one token */ 924 | } /* end of user's declarations */ 925 | } /* end of yylex */ 926 | 927 | /* yy_get_next_buffer - try to read in a new buffer 928 | * 929 | * Returns a code representing an action: 930 | * EOB_ACT_LAST_MATCH - 931 | * EOB_ACT_CONTINUE_SCAN - continue scanning from current position 932 | * EOB_ACT_END_OF_FILE - end of file 933 | */ 934 | static int yy_get_next_buffer (void) 935 | { 936 | char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; 937 | char *source = (yytext_ptr); 938 | int number_to_move, i; 939 | int ret_val; 940 | 941 | if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) 942 | YY_FATAL_ERROR( 943 | "fatal flex scanner internal error--end of buffer missed" ); 944 | 945 | if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) 946 | { /* Don't try to fill the buffer, so this is an EOF. */ 947 | if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) 948 | { 949 | /* We matched a single character, the EOB, so 950 | * treat this as a final EOF. 951 | */ 952 | return EOB_ACT_END_OF_FILE; 953 | } 954 | 955 | else 956 | { 957 | /* We matched some text prior to the EOB, first 958 | * process it. 959 | */ 960 | return EOB_ACT_LAST_MATCH; 961 | } 962 | } 963 | 964 | /* Try to read more data. */ 965 | 966 | /* First move last chars to start of buffer. */ 967 | number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); 968 | 969 | for ( i = 0; i < number_to_move; ++i ) 970 | *(dest++) = *(source++); 971 | 972 | if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) 973 | /* don't do the read, it's not guaranteed to return an EOF, 974 | * just force an EOF 975 | */ 976 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; 977 | 978 | else 979 | { 980 | int num_to_read = 981 | YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; 982 | 983 | while ( num_to_read <= 0 ) 984 | { /* Not enough room in the buffer - grow it. */ 985 | 986 | /* just a shorter name for the current buffer */ 987 | YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; 988 | 989 | int yy_c_buf_p_offset = 990 | (int) ((yy_c_buf_p) - b->yy_ch_buf); 991 | 992 | if ( b->yy_is_our_buffer ) 993 | { 994 | int new_size = b->yy_buf_size * 2; 995 | 996 | if ( new_size <= 0 ) 997 | b->yy_buf_size += b->yy_buf_size / 8; 998 | else 999 | b->yy_buf_size *= 2; 1000 | 1001 | b->yy_ch_buf = (char *) 1002 | /* Include room in for 2 EOB chars. */ 1003 | yyrealloc( (void *) b->yy_ch_buf, 1004 | (yy_size_t) (b->yy_buf_size + 2) ); 1005 | } 1006 | else 1007 | /* Can't grow it, we don't own it. */ 1008 | b->yy_ch_buf = NULL; 1009 | 1010 | if ( ! b->yy_ch_buf ) 1011 | YY_FATAL_ERROR( 1012 | "fatal error - scanner input buffer overflow" ); 1013 | 1014 | (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; 1015 | 1016 | num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - 1017 | number_to_move - 1; 1018 | 1019 | } 1020 | 1021 | if ( num_to_read > YY_READ_BUF_SIZE ) 1022 | num_to_read = YY_READ_BUF_SIZE; 1023 | 1024 | /* Read in more data. */ 1025 | YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), 1026 | (yy_n_chars), num_to_read ); 1027 | 1028 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); 1029 | } 1030 | 1031 | if ( (yy_n_chars) == 0 ) 1032 | { 1033 | if ( number_to_move == YY_MORE_ADJ ) 1034 | { 1035 | ret_val = EOB_ACT_END_OF_FILE; 1036 | yyrestart( yyin ); 1037 | } 1038 | 1039 | else 1040 | { 1041 | ret_val = EOB_ACT_LAST_MATCH; 1042 | YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = 1043 | YY_BUFFER_EOF_PENDING; 1044 | } 1045 | } 1046 | 1047 | else 1048 | ret_val = EOB_ACT_CONTINUE_SCAN; 1049 | 1050 | if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { 1051 | /* Extend the array by 50%, plus the number we really need. */ 1052 | int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); 1053 | YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( 1054 | (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); 1055 | if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) 1056 | YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); 1057 | /* "- 2" to take care of EOB's */ 1058 | YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); 1059 | } 1060 | 1061 | (yy_n_chars) += number_to_move; 1062 | YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; 1063 | YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; 1064 | 1065 | (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; 1066 | 1067 | return ret_val; 1068 | } 1069 | 1070 | /* yy_get_previous_state - get the state just before the EOB char was reached */ 1071 | 1072 | static yy_state_type yy_get_previous_state (void) 1073 | { 1074 | yy_state_type yy_current_state; 1075 | char *yy_cp; 1076 | 1077 | yy_current_state = (yy_start); 1078 | 1079 | for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) 1080 | { 1081 | YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); 1082 | if ( yy_accept[yy_current_state] ) 1083 | { 1084 | (yy_last_accepting_state) = yy_current_state; 1085 | (yy_last_accepting_cpos) = yy_cp; 1086 | } 1087 | while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 1088 | { 1089 | yy_current_state = (int) yy_def[yy_current_state]; 1090 | if ( yy_current_state >= 12 ) 1091 | yy_c = yy_meta[yy_c]; 1092 | } 1093 | yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; 1094 | } 1095 | 1096 | return yy_current_state; 1097 | } 1098 | 1099 | /* yy_try_NUL_trans - try to make a transition on the NUL character 1100 | * 1101 | * synopsis 1102 | * next_state = yy_try_NUL_trans( current_state ); 1103 | */ 1104 | static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) 1105 | { 1106 | int yy_is_jam; 1107 | char *yy_cp = (yy_c_buf_p); 1108 | 1109 | YY_CHAR yy_c = 1; 1110 | if ( yy_accept[yy_current_state] ) 1111 | { 1112 | (yy_last_accepting_state) = yy_current_state; 1113 | (yy_last_accepting_cpos) = yy_cp; 1114 | } 1115 | while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) 1116 | { 1117 | yy_current_state = (int) yy_def[yy_current_state]; 1118 | if ( yy_current_state >= 12 ) 1119 | yy_c = yy_meta[yy_c]; 1120 | } 1121 | yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; 1122 | yy_is_jam = (yy_current_state == 11); 1123 | 1124 | return yy_is_jam ? 0 : yy_current_state; 1125 | } 1126 | 1127 | #ifndef YY_NO_UNPUT 1128 | 1129 | static void yyunput (int c, char * yy_bp ) 1130 | { 1131 | char *yy_cp; 1132 | 1133 | yy_cp = (yy_c_buf_p); 1134 | 1135 | /* undo effects of setting up yytext */ 1136 | *yy_cp = (yy_hold_char); 1137 | 1138 | if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) 1139 | { /* need to shift things up to make room */ 1140 | /* +2 for EOB chars. */ 1141 | int number_to_move = (yy_n_chars) + 2; 1142 | char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ 1143 | YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; 1144 | char *source = 1145 | &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; 1146 | 1147 | while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) 1148 | *--dest = *--source; 1149 | 1150 | yy_cp += (int) (dest - source); 1151 | yy_bp += (int) (dest - source); 1152 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = 1153 | (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; 1154 | 1155 | if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) 1156 | YY_FATAL_ERROR( "flex scanner push-back overflow" ); 1157 | } 1158 | 1159 | *--yy_cp = (char) c; 1160 | 1161 | if ( c == '\n' ){ 1162 | --yylineno; 1163 | } 1164 | 1165 | (yytext_ptr) = yy_bp; 1166 | (yy_hold_char) = *yy_cp; 1167 | (yy_c_buf_p) = yy_cp; 1168 | } 1169 | 1170 | #endif 1171 | 1172 | #ifndef YY_NO_INPUT 1173 | #ifdef __cplusplus 1174 | static int yyinput (void) 1175 | #else 1176 | static int input (void) 1177 | #endif 1178 | 1179 | { 1180 | int c; 1181 | 1182 | *(yy_c_buf_p) = (yy_hold_char); 1183 | 1184 | if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) 1185 | { 1186 | /* yy_c_buf_p now points to the character we want to return. 1187 | * If this occurs *before* the EOB characters, then it's a 1188 | * valid NUL; if not, then we've hit the end of the buffer. 1189 | */ 1190 | if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) 1191 | /* This was really a NUL. */ 1192 | *(yy_c_buf_p) = '\0'; 1193 | 1194 | else 1195 | { /* need more input */ 1196 | int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); 1197 | ++(yy_c_buf_p); 1198 | 1199 | switch ( yy_get_next_buffer( ) ) 1200 | { 1201 | case EOB_ACT_LAST_MATCH: 1202 | /* This happens because yy_g_n_b() 1203 | * sees that we've accumulated a 1204 | * token and flags that we need to 1205 | * try matching the token before 1206 | * proceeding. But for input(), 1207 | * there's no matching to consider. 1208 | * So convert the EOB_ACT_LAST_MATCH 1209 | * to EOB_ACT_END_OF_FILE. 1210 | */ 1211 | 1212 | /* Reset buffer status. */ 1213 | yyrestart( yyin ); 1214 | 1215 | /*FALLTHROUGH*/ 1216 | 1217 | case EOB_ACT_END_OF_FILE: 1218 | { 1219 | if ( yywrap( ) ) 1220 | return 0; 1221 | 1222 | if ( ! (yy_did_buffer_switch_on_eof) ) 1223 | YY_NEW_FILE; 1224 | #ifdef __cplusplus 1225 | return yyinput(); 1226 | #else 1227 | return input(); 1228 | #endif 1229 | } 1230 | 1231 | case EOB_ACT_CONTINUE_SCAN: 1232 | (yy_c_buf_p) = (yytext_ptr) + offset; 1233 | break; 1234 | } 1235 | } 1236 | } 1237 | 1238 | c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ 1239 | *(yy_c_buf_p) = '\0'; /* preserve yytext */ 1240 | (yy_hold_char) = *++(yy_c_buf_p); 1241 | 1242 | if ( c == '\n' ) 1243 | 1244 | yylineno++; 1245 | ; 1246 | 1247 | return c; 1248 | } 1249 | #endif /* ifndef YY_NO_INPUT */ 1250 | 1251 | /** Immediately switch to a different input stream. 1252 | * @param input_file A readable stream. 1253 | * 1254 | * @note This function does not reset the start condition to @c INITIAL . 1255 | */ 1256 | void yyrestart (FILE * input_file ) 1257 | { 1258 | 1259 | if ( ! YY_CURRENT_BUFFER ){ 1260 | yyensure_buffer_stack (); 1261 | YY_CURRENT_BUFFER_LVALUE = 1262 | yy_create_buffer( yyin, YY_BUF_SIZE ); 1263 | } 1264 | 1265 | yy_init_buffer( YY_CURRENT_BUFFER, input_file ); 1266 | yy_load_buffer_state( ); 1267 | } 1268 | 1269 | /** Switch to a different input buffer. 1270 | * @param new_buffer The new input buffer. 1271 | * 1272 | */ 1273 | void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) 1274 | { 1275 | 1276 | /* TODO. We should be able to replace this entire function body 1277 | * with 1278 | * yypop_buffer_state(); 1279 | * yypush_buffer_state(new_buffer); 1280 | */ 1281 | yyensure_buffer_stack (); 1282 | if ( YY_CURRENT_BUFFER == new_buffer ) 1283 | return; 1284 | 1285 | if ( YY_CURRENT_BUFFER ) 1286 | { 1287 | /* Flush out information for old buffer. */ 1288 | *(yy_c_buf_p) = (yy_hold_char); 1289 | YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); 1290 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); 1291 | } 1292 | 1293 | YY_CURRENT_BUFFER_LVALUE = new_buffer; 1294 | yy_load_buffer_state( ); 1295 | 1296 | /* We don't actually know whether we did this switch during 1297 | * EOF (yywrap()) processing, but the only time this flag 1298 | * is looked at is after yywrap() is called, so it's safe 1299 | * to go ahead and always set it. 1300 | */ 1301 | (yy_did_buffer_switch_on_eof) = 1; 1302 | } 1303 | 1304 | static void yy_load_buffer_state (void) 1305 | { 1306 | (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; 1307 | (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; 1308 | yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; 1309 | (yy_hold_char) = *(yy_c_buf_p); 1310 | } 1311 | 1312 | /** Allocate and initialize an input buffer state. 1313 | * @param file A readable stream. 1314 | * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. 1315 | * 1316 | * @return the allocated buffer state. 1317 | */ 1318 | YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) 1319 | { 1320 | YY_BUFFER_STATE b; 1321 | 1322 | b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); 1323 | if ( ! b ) 1324 | YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); 1325 | 1326 | b->yy_buf_size = size; 1327 | 1328 | /* yy_ch_buf has to be 2 characters longer than the size given because 1329 | * we need to put in 2 end-of-buffer characters. 1330 | */ 1331 | b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); 1332 | if ( ! b->yy_ch_buf ) 1333 | YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); 1334 | 1335 | b->yy_is_our_buffer = 1; 1336 | 1337 | yy_init_buffer( b, file ); 1338 | 1339 | return b; 1340 | } 1341 | 1342 | /** Destroy the buffer. 1343 | * @param b a buffer created with yy_create_buffer() 1344 | * 1345 | */ 1346 | void yy_delete_buffer (YY_BUFFER_STATE b ) 1347 | { 1348 | 1349 | if ( ! b ) 1350 | return; 1351 | 1352 | if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ 1353 | YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; 1354 | 1355 | if ( b->yy_is_our_buffer ) 1356 | yyfree( (void *) b->yy_ch_buf ); 1357 | 1358 | yyfree( (void *) b ); 1359 | } 1360 | 1361 | /* Initializes or reinitializes a buffer. 1362 | * This function is sometimes called more than once on the same buffer, 1363 | * such as during a yyrestart() or at EOF. 1364 | */ 1365 | static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) 1366 | 1367 | { 1368 | int oerrno = errno; 1369 | 1370 | yy_flush_buffer( b ); 1371 | 1372 | b->yy_input_file = file; 1373 | b->yy_fill_buffer = 1; 1374 | 1375 | /* If b is the current buffer, then yy_init_buffer was _probably_ 1376 | * called from yyrestart() or through yy_get_next_buffer. 1377 | * In that case, we don't want to reset the lineno or column. 1378 | */ 1379 | if (b != YY_CURRENT_BUFFER){ 1380 | b->yy_bs_lineno = 1; 1381 | b->yy_bs_column = 0; 1382 | } 1383 | 1384 | b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; 1385 | 1386 | errno = oerrno; 1387 | } 1388 | 1389 | /** Discard all buffered characters. On the next scan, YY_INPUT will be called. 1390 | * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. 1391 | * 1392 | */ 1393 | void yy_flush_buffer (YY_BUFFER_STATE b ) 1394 | { 1395 | if ( ! b ) 1396 | return; 1397 | 1398 | b->yy_n_chars = 0; 1399 | 1400 | /* We always need two end-of-buffer characters. The first causes 1401 | * a transition to the end-of-buffer state. The second causes 1402 | * a jam in that state. 1403 | */ 1404 | b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; 1405 | b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; 1406 | 1407 | b->yy_buf_pos = &b->yy_ch_buf[0]; 1408 | 1409 | b->yy_at_bol = 1; 1410 | b->yy_buffer_status = YY_BUFFER_NEW; 1411 | 1412 | if ( b == YY_CURRENT_BUFFER ) 1413 | yy_load_buffer_state( ); 1414 | } 1415 | 1416 | /** Pushes the new state onto the stack. The new state becomes 1417 | * the current state. This function will allocate the stack 1418 | * if necessary. 1419 | * @param new_buffer The new state. 1420 | * 1421 | */ 1422 | void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) 1423 | { 1424 | if (new_buffer == NULL) 1425 | return; 1426 | 1427 | yyensure_buffer_stack(); 1428 | 1429 | /* This block is copied from yy_switch_to_buffer. */ 1430 | if ( YY_CURRENT_BUFFER ) 1431 | { 1432 | /* Flush out information for old buffer. */ 1433 | *(yy_c_buf_p) = (yy_hold_char); 1434 | YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); 1435 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); 1436 | } 1437 | 1438 | /* Only push if top exists. Otherwise, replace top. */ 1439 | if (YY_CURRENT_BUFFER) 1440 | (yy_buffer_stack_top)++; 1441 | YY_CURRENT_BUFFER_LVALUE = new_buffer; 1442 | 1443 | /* copied from yy_switch_to_buffer. */ 1444 | yy_load_buffer_state( ); 1445 | (yy_did_buffer_switch_on_eof) = 1; 1446 | } 1447 | 1448 | /** Removes and deletes the top of the stack, if present. 1449 | * The next element becomes the new top. 1450 | * 1451 | */ 1452 | void yypop_buffer_state (void) 1453 | { 1454 | if (!YY_CURRENT_BUFFER) 1455 | return; 1456 | 1457 | yy_delete_buffer(YY_CURRENT_BUFFER ); 1458 | YY_CURRENT_BUFFER_LVALUE = NULL; 1459 | if ((yy_buffer_stack_top) > 0) 1460 | --(yy_buffer_stack_top); 1461 | 1462 | if (YY_CURRENT_BUFFER) { 1463 | yy_load_buffer_state( ); 1464 | (yy_did_buffer_switch_on_eof) = 1; 1465 | } 1466 | } 1467 | 1468 | /* Allocates the stack if it does not exist. 1469 | * Guarantees space for at least one push. 1470 | */ 1471 | static void yyensure_buffer_stack (void) 1472 | { 1473 | yy_size_t num_to_alloc; 1474 | 1475 | if (!(yy_buffer_stack)) { 1476 | 1477 | /* First allocation is just for 2 elements, since we don't know if this 1478 | * scanner will even need a stack. We use 2 instead of 1 to avoid an 1479 | * immediate realloc on the next call. 1480 | */ 1481 | num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ 1482 | (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc 1483 | (num_to_alloc * sizeof(struct yy_buffer_state*) 1484 | ); 1485 | if ( ! (yy_buffer_stack) ) 1486 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); 1487 | 1488 | memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); 1489 | 1490 | (yy_buffer_stack_max) = num_to_alloc; 1491 | (yy_buffer_stack_top) = 0; 1492 | return; 1493 | } 1494 | 1495 | if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ 1496 | 1497 | /* Increase the buffer to prepare for a possible push. */ 1498 | yy_size_t grow_size = 8 /* arbitrary grow size */; 1499 | 1500 | num_to_alloc = (yy_buffer_stack_max) + grow_size; 1501 | (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc 1502 | ((yy_buffer_stack), 1503 | num_to_alloc * sizeof(struct yy_buffer_state*) 1504 | ); 1505 | if ( ! (yy_buffer_stack) ) 1506 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); 1507 | 1508 | /* zero only the new slots.*/ 1509 | memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); 1510 | (yy_buffer_stack_max) = num_to_alloc; 1511 | } 1512 | } 1513 | 1514 | /** Setup the input buffer state to scan directly from a user-specified character buffer. 1515 | * @param base the character buffer 1516 | * @param size the size in bytes of the character buffer 1517 | * 1518 | * @return the newly allocated buffer state object. 1519 | */ 1520 | YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) 1521 | { 1522 | YY_BUFFER_STATE b; 1523 | 1524 | if ( size < 2 || 1525 | base[size-2] != YY_END_OF_BUFFER_CHAR || 1526 | base[size-1] != YY_END_OF_BUFFER_CHAR ) 1527 | /* They forgot to leave room for the EOB's. */ 1528 | return NULL; 1529 | 1530 | b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); 1531 | if ( ! b ) 1532 | YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); 1533 | 1534 | b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ 1535 | b->yy_buf_pos = b->yy_ch_buf = base; 1536 | b->yy_is_our_buffer = 0; 1537 | b->yy_input_file = NULL; 1538 | b->yy_n_chars = b->yy_buf_size; 1539 | b->yy_is_interactive = 0; 1540 | b->yy_at_bol = 1; 1541 | b->yy_fill_buffer = 0; 1542 | b->yy_buffer_status = YY_BUFFER_NEW; 1543 | 1544 | yy_switch_to_buffer( b ); 1545 | 1546 | return b; 1547 | } 1548 | 1549 | /** Setup the input buffer state to scan a string. The next call to yylex() will 1550 | * scan from a @e copy of @a str. 1551 | * @param yystr a NUL-terminated string to scan 1552 | * 1553 | * @return the newly allocated buffer state object. 1554 | * @note If you want to scan bytes that may contain NUL values, then use 1555 | * yy_scan_bytes() instead. 1556 | */ 1557 | YY_BUFFER_STATE yy_scan_string (const char * yystr ) 1558 | { 1559 | 1560 | return yy_scan_bytes( yystr, (int) strlen(yystr) ); 1561 | } 1562 | 1563 | /** Setup the input buffer state to scan the given bytes. The next call to yylex() will 1564 | * scan from a @e copy of @a bytes. 1565 | * @param yybytes the byte buffer to scan 1566 | * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. 1567 | * 1568 | * @return the newly allocated buffer state object. 1569 | */ 1570 | YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) 1571 | { 1572 | YY_BUFFER_STATE b; 1573 | char *buf; 1574 | yy_size_t n; 1575 | int i; 1576 | 1577 | /* Get memory for full buffer, including space for trailing EOB's. */ 1578 | n = (yy_size_t) (_yybytes_len + 2); 1579 | buf = (char *) yyalloc( n ); 1580 | if ( ! buf ) 1581 | YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); 1582 | 1583 | for ( i = 0; i < _yybytes_len; ++i ) 1584 | buf[i] = yybytes[i]; 1585 | 1586 | buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; 1587 | 1588 | b = yy_scan_buffer( buf, n ); 1589 | if ( ! b ) 1590 | YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); 1591 | 1592 | /* It's okay to grow etc. this buffer, and we should throw it 1593 | * away when we're done. 1594 | */ 1595 | b->yy_is_our_buffer = 1; 1596 | 1597 | return b; 1598 | } 1599 | 1600 | #ifndef YY_EXIT_FAILURE 1601 | #define YY_EXIT_FAILURE 2 1602 | #endif 1603 | 1604 | static void yynoreturn yy_fatal_error (const char* msg ) 1605 | { 1606 | fprintf( stderr, "%s\n", msg ); 1607 | exit( YY_EXIT_FAILURE ); 1608 | } 1609 | 1610 | /* Redefine yyless() so it works in section 3 code. */ 1611 | 1612 | #undef yyless 1613 | #define yyless(n) \ 1614 | do \ 1615 | { \ 1616 | /* Undo effects of setting up yytext. */ \ 1617 | int yyless_macro_arg = (n); \ 1618 | YY_LESS_LINENO(yyless_macro_arg);\ 1619 | yytext[yyleng] = (yy_hold_char); \ 1620 | (yy_c_buf_p) = yytext + yyless_macro_arg; \ 1621 | (yy_hold_char) = *(yy_c_buf_p); \ 1622 | *(yy_c_buf_p) = '\0'; \ 1623 | yyleng = yyless_macro_arg; \ 1624 | } \ 1625 | while ( 0 ) 1626 | 1627 | /* Accessor methods (get/set functions) to struct members. */ 1628 | 1629 | /** Get the current line number. 1630 | * 1631 | */ 1632 | int yyget_lineno (void) 1633 | { 1634 | 1635 | return yylineno; 1636 | } 1637 | 1638 | /** Get the input stream. 1639 | * 1640 | */ 1641 | FILE *yyget_in (void) 1642 | { 1643 | return yyin; 1644 | } 1645 | 1646 | /** Get the output stream. 1647 | * 1648 | */ 1649 | FILE *yyget_out (void) 1650 | { 1651 | return yyout; 1652 | } 1653 | 1654 | /** Get the length of the current token. 1655 | * 1656 | */ 1657 | int yyget_leng (void) 1658 | { 1659 | return yyleng; 1660 | } 1661 | 1662 | /** Get the current token. 1663 | * 1664 | */ 1665 | 1666 | char *yyget_text (void) 1667 | { 1668 | return yytext; 1669 | } 1670 | 1671 | /** Set the current line number. 1672 | * @param _line_number line number 1673 | * 1674 | */ 1675 | void yyset_lineno (int _line_number ) 1676 | { 1677 | 1678 | yylineno = _line_number; 1679 | } 1680 | 1681 | /** Set the input stream. This does not discard the current 1682 | * input buffer. 1683 | * @param _in_str A readable stream. 1684 | * 1685 | * @see yy_switch_to_buffer 1686 | */ 1687 | void yyset_in (FILE * _in_str ) 1688 | { 1689 | yyin = _in_str ; 1690 | } 1691 | 1692 | void yyset_out (FILE * _out_str ) 1693 | { 1694 | yyout = _out_str ; 1695 | } 1696 | 1697 | int yyget_debug (void) 1698 | { 1699 | return yy_flex_debug; 1700 | } 1701 | 1702 | void yyset_debug (int _bdebug ) 1703 | { 1704 | yy_flex_debug = _bdebug ; 1705 | } 1706 | 1707 | static int yy_init_globals (void) 1708 | { 1709 | /* Initialization is the same as for the non-reentrant scanner. 1710 | * This function is called from yylex_destroy(), so don't allocate here. 1711 | */ 1712 | 1713 | /* We do not touch yylineno unless the option is enabled. */ 1714 | yylineno = 1; 1715 | 1716 | (yy_buffer_stack) = NULL; 1717 | (yy_buffer_stack_top) = 0; 1718 | (yy_buffer_stack_max) = 0; 1719 | (yy_c_buf_p) = NULL; 1720 | (yy_init) = 0; 1721 | (yy_start) = 0; 1722 | 1723 | /* Defined in main.c */ 1724 | #ifdef YY_STDINIT 1725 | yyin = stdin; 1726 | yyout = stdout; 1727 | #else 1728 | yyin = NULL; 1729 | yyout = NULL; 1730 | #endif 1731 | 1732 | /* For future reference: Set errno on error, since we are called by 1733 | * yylex_init() 1734 | */ 1735 | return 0; 1736 | } 1737 | 1738 | /* yylex_destroy is for both reentrant and non-reentrant scanners. */ 1739 | int yylex_destroy (void) 1740 | { 1741 | 1742 | /* Pop the buffer stack, destroying each element. */ 1743 | while(YY_CURRENT_BUFFER){ 1744 | yy_delete_buffer( YY_CURRENT_BUFFER ); 1745 | YY_CURRENT_BUFFER_LVALUE = NULL; 1746 | yypop_buffer_state(); 1747 | } 1748 | 1749 | /* Destroy the stack itself. */ 1750 | yyfree((yy_buffer_stack) ); 1751 | (yy_buffer_stack) = NULL; 1752 | 1753 | /* Reset the globals. This is important in a non-reentrant scanner so the next time 1754 | * yylex() is called, initialization will occur. */ 1755 | yy_init_globals( ); 1756 | 1757 | return 0; 1758 | } 1759 | 1760 | /* 1761 | * Internal utility routines. 1762 | */ 1763 | 1764 | #ifndef yytext_ptr 1765 | static void yy_flex_strncpy (char* s1, const char * s2, int n ) 1766 | { 1767 | 1768 | int i; 1769 | for ( i = 0; i < n; ++i ) 1770 | s1[i] = s2[i]; 1771 | } 1772 | #endif 1773 | 1774 | #ifdef YY_NEED_STRLEN 1775 | static int yy_flex_strlen (const char * s ) 1776 | { 1777 | int n; 1778 | for ( n = 0; s[n]; ++n ) 1779 | ; 1780 | 1781 | return n; 1782 | } 1783 | #endif 1784 | 1785 | void *yyalloc (yy_size_t size ) 1786 | { 1787 | return malloc(size); 1788 | } 1789 | 1790 | void *yyrealloc (void * ptr, yy_size_t size ) 1791 | { 1792 | 1793 | /* The cast to (char *) in the following accommodates both 1794 | * implementations that use char* generic pointers, and those 1795 | * that use void* generic pointers. It works with the latter 1796 | * because both ANSI C and C++ allow castless assignment from 1797 | * any pointer type to void*, and deal with argument conversions 1798 | * as though doing an assignment. 1799 | */ 1800 | return realloc(ptr, size); 1801 | } 1802 | 1803 | void yyfree (void * ptr ) 1804 | { 1805 | free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ 1806 | } 1807 | 1808 | #define YYTABLES_NAME "yytables" 1809 | 1810 | #line 20 "test.l" 1811 | 1812 | 1813 | 1814 | void showError(){ 1815 | printf("Other input"); 1816 | } 1817 | 1818 | --------------------------------------------------------------------------------