X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/14bfd2e9d9e5a17dfc7cbba44872abccad0c1d65..3f21a394f481c829831592adcf3ea040f87805ee:/src/parse-gram.y diff --git a/src/parse-gram.y b/src/parse-gram.y index b6338597..8b57ce80 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -1,4 +1,4 @@ -%{/* Bison Grammar Parser -*- C -*- +/* Bison Grammar Parser -*- C -*- Copyright (C) 2002-2013 Free Software Foundation, Inc. @@ -17,40 +17,30 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include -#include "system.h" - -#include "c-ctype.h" -#include "complain.h" -#include "conflicts.h" -#include "files.h" -#include "getargs.h" -#include "gram.h" -#include "named-ref.h" -#include "quotearg.h" -#include "reader.h" -#include "symlist.h" -#include "symtab.h" -#include "scan-gram.h" -#include "scan-code.h" -#include "xmemdup0.h" - -#define YYLLOC_DEFAULT(Current, Rhs, N) (Current) = lloc_default (Rhs, N) -static YYLTYPE lloc_default (YYLTYPE const *, int); - -#define YY_LOCATION_PRINT(File, Loc) \ - location_print (Loc, File) - -static void version_check (location const *loc, char const *version); - -static void gram_error (location const *, char const *); - -/* A string that describes a char (e.g., 'a' -> "'a'"). */ -static char const *char_name (char); -%} +%code requires +{ + #include "symlist.h" + #include "symtab.h" +} %code { + #include + #include "system.h" + + #include "c-ctype.h" + #include "complain.h" + #include "conflicts.h" + #include "files.h" + #include "getargs.h" + #include "gram.h" + #include "named-ref.h" + #include "quotearg.h" + #include "reader.h" + #include "scan-gram.h" + #include "scan-code.h" + #include "xmemdup0.h" + static int current_prec = 0; static location current_lhs_location; static named_ref *current_lhs_named_ref; @@ -61,20 +51,21 @@ static char const *char_name (char); /** Set the new current left-hand side symbol, possibly common * to several right-hand side parts of rule. */ - static - void - current_lhs (symbol *sym, location loc, named_ref *ref) - { - current_lhs_symbol = sym; - current_lhs_location = loc; - /* In order to simplify memory management, named references for lhs - are always assigned by deep copy into the current symbol_list - node. This is because a single named-ref in the grammar may - result in several uses when the user factors lhs between several - rules using "|". Therefore free the parser's original copy. */ - free (current_lhs_named_ref); - current_lhs_named_ref = ref; - } + static void current_lhs (symbol *sym, location loc, named_ref *ref); + + #define YYLLOC_DEFAULT(Current, Rhs, N) \ + (Current) = lloc_default (Rhs, N) + static YYLTYPE lloc_default (YYLTYPE const *, int); + + #define YY_LOCATION_PRINT(File, Loc) \ + location_print (Loc, File) + + static void version_check (location const *loc, char const *version); + + static void gram_error (location const *, char const *); + + /* A string that describes a char (e.g., 'a' -> "'a'"). */ + static char const *char_name (char); #define YYTYPE_INT16 int_fast16_t #define YYTYPE_INT8 int_fast8_t @@ -82,7 +73,7 @@ static char const *char_name (char); #define YYTYPE_UINT8 uint_fast8_t } -%define api.prefix "gram_" +%define api.prefix {gram_} %define api.pure full %define locations %define parse.error verbose @@ -682,7 +673,7 @@ braceless: "{...}" { code_props plain_code; - $1[strlen ($1) - 1] = '\n'; + $1[strlen ($1) - 1] = '\0'; code_props_plain_init (&plain_code, $1+1, @1); code_props_translate_code (&plain_code); gram_scanner_last_string_free (); @@ -854,3 +845,18 @@ char_name (char c) return quotearg_style (escape_quoting_style, buf); } } + +static +void +current_lhs (symbol *sym, location loc, named_ref *ref) +{ + current_lhs_symbol = sym; + current_lhs_location = loc; + /* In order to simplify memory management, named references for lhs + are always assigned by deep copy into the current symbol_list + node. This is because a single named-ref in the grammar may + result in several uses when the user factors lhs between several + rules using "|". Therefore free the parser's original copy. */ + free (current_lhs_named_ref); + current_lhs_named_ref = ref; +}