X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/527187137ac6314b86246bca71cb996203b4fa10..fa98bb3233f7f291d8efa2565288bc0597f92063:/src/parse-gram.y diff --git a/src/parse-gram.y b/src/parse-gram.y index 74eb4aee..46500db0 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -20,6 +20,7 @@ #include #include "system.h" +#include "c-ctype.h" #include "complain.h" #include "conflicts.h" #include "files.h" @@ -30,6 +31,7 @@ #include "quotearg.h" #include "reader.h" #include "symlist.h" +#include "symtab.h" #include "scan-gram.h" #include "scan-code.h" #include "xmemdup0.h" @@ -85,14 +87,14 @@ static char const *char_name (char); #define YYTYPE_UINT8 uint_fast8_t } -%debug %verbose %defines -%locations -%pure-parser -%define parse.error "verbose" +%define locations +%define api.pure +%define parse.error verbose %define parse.lac full -%name-prefix="gram_" +%define parse.trace +%name-prefix "gram_" %expect 0 %initial-action @@ -185,30 +187,30 @@ static char const *char_name (char); %token TAG_NONE "<>" %type CHAR -%printer { fputs (char_name ($$), stderr); } CHAR +%printer { fputs (char_name ($$), yyo); } CHAR /* braceless is not to be used for rule or symbol actions, as it calls code_props_plain_init. */ %type STRING "%{...%}" EPILOGUE braceless content.opt %type "{...}" "%?{...}" -%printer { fputs (quotearg_style (c_quoting_style, $$), stderr); } +%printer { fputs (quotearg_style (c_quoting_style, $$), yyo); } STRING -%printer { fprintf (stderr, "{\n%s\n}", $$); } +%printer { fprintf (yyo, "{\n%s\n}", $$); } braceless content.opt "{...}" "%{...%}" EPILOGUE -%type BRACKETED_ID ID ID_COLON PERCENT_FLAG TAG variable -%printer { fputs ($$, stderr); } -%printer { fprintf (stderr, "[%s]", $$); } BRACKETED_ID -%printer { fprintf (stderr, "%s:", $$); } ID_COLON -%printer { fprintf (stderr, "%%%s", $$); } PERCENT_FLAG -%printer { fprintf (stderr, "<%s>", $$); } TAG +%type BRACKETED_ID ID ID_COLON PERCENT_FLAG TAG tag variable +%printer { fputs ($$, yyo); } +%printer { fprintf (yyo, "[%s]", $$); } BRACKETED_ID +%printer { fprintf (yyo, "%s:", $$); } ID_COLON +%printer { fprintf (yyo, "%%%s", $$); } PERCENT_FLAG +%printer { fprintf (yyo, "<%s>", $$); } TAG tag %type INT -%printer { fprintf (stderr, "%d", $$); } +%printer { fprintf (yyo, "%d", $$); } %type id id_colon string_as_id symbol symbol.prec -%printer { fprintf (stderr, "%s", $$->tag); } -%printer { fprintf (stderr, "%s:", $$->tag); } id_colon +%printer { fprintf (yyo, "%s", $$->tag); } +%printer { fprintf (yyo, "%s:", $$->tag); } id_colon %type precedence_declarator %type symbols.1 symbols.prec generic_symlist generic_symlist_item @@ -342,7 +344,7 @@ prologue_declaration: | "%skeleton" STRING { char const *skeleton_user = $2; - if (mbschr (skeleton_user, '/')) + if (strchr (skeleton_user, '/')) { size_t dir_length = strlen (current_file); char *skeleton_build; @@ -386,19 +388,17 @@ grammar_declaration: { grammar_start_symbol_set ($2, @2); } -| "%destructor" "{...}" generic_symlist +| code_props_type "{...}" generic_symlist { - symbol_list *list; - for (list = $3; list; list = list->next) - symbol_list_destructor_set (list, $2, @2); - symbol_list_free ($3); - } -| "%printer" "{...}" generic_symlist - { - symbol_list *list; - for (list = $3; list; list = list->next) - symbol_list_printer_set (list, $2, @2); - symbol_list_free ($3); + code_props code; + code_props_symbol_action_init (&code, $2, @2); + code_props_translate_code (&code); + { + symbol_list *list; + for (list = $3; list; list = list->next) + symbol_list_code_props_set (list, $1, &code); + symbol_list_free ($3); + } } | "%default-prec" { @@ -422,6 +422,13 @@ grammar_declaration: } ; +%type code_props_type; +%union {code_props_type code_type;}; +%printer { fprintf (yyo, "%s", code_props_type_string ($$)); } ; +code_props_type: + "%destructor" { $$ = destructor; } +| "%printer" { $$ = printer; } +; /*---------. | %union. | @@ -503,9 +510,9 @@ symbols.prec: ; symbol.prec: - symbol { $$ = $1; } - | symbol INT { $$ = $1; symbol_user_token_number_set ($1, $2, @2); } - ; + symbol { $$ = $1; } +| symbol INT { $$ = $1; symbol_user_token_number_set ($1, $2, @2); } +; /* One or more symbols to be %typed. */ symbols.1: @@ -522,9 +529,13 @@ generic_symlist: generic_symlist_item: symbol { $$ = symbol_list_sym_new ($1, @1); } -| TAG { $$ = symbol_list_type_new ($1, @1); } -| "<*>" { $$ = symbol_list_default_tagged_new (@1); } -| "<>" { $$ = symbol_list_default_tagless_new (@1); } +| tag { $$ = symbol_list_type_new ($1, @1); } +; + +tag: + TAG +| "<*>" { $$ = uniqstr_new ("*"); } +| "<>" { $$ = uniqstr_new (""); } ; /* One token definition. */ @@ -765,15 +776,18 @@ add_param (param_type type, char *decl, location loc) /* Strip the surrounding '{' and '}', and any blanks just inside the braces. */ - while (*--p == ' ' || *p == '\t') - continue; + --p; + while (c_isspace ((unsigned char) *p)) + --p; p[1] = '\0'; - while (*++decl == ' ' || *decl == '\t') - continue; + ++decl; + while (c_isspace ((unsigned char) *decl)) + ++decl; } if (! name_start) - complain_at (loc, _("missing identifier in parameter declaration")); + complain_at (loc, complaint, + _("missing identifier in parameter declaration")); else { char *name = xmemdup0 (name_start, strspn (name_start, alphanum)); @@ -793,7 +807,7 @@ version_check (location const *loc, char const *version) { if (strverscmp (version, PACKAGE_VERSION) > 0) { - complain_at (*loc, "require bison %s, but have %s", + complain_at (*loc, complaint, "require bison %s, but have %s", version, PACKAGE_VERSION); exit (EX_MISMATCH); } @@ -802,7 +816,7 @@ version_check (location const *loc, char const *version) static void gram_error (location const *loc, char const *msg) { - complain_at (*loc, "%s", msg); + complain_at (*loc, complaint, "%s", msg); } char const *