X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/87fbb0bffc4335f246c89e4bef56a908227c3446..b25d88f6d2e2f4b59927aacecdc0a9e44a34b5d9:/src/parse-gram.y?ds=sidebyside diff --git a/src/parse-gram.y b/src/parse-gram.y index aa307881..8af3e885 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -40,7 +40,7 @@ #include "reader.h" #include "conflicts.h" -/* Produce verbose parse errors. */ +/* Produce verbose syntax errors. */ #define YYERROR_VERBOSE 1 #define YYLLOC_DEFAULT(Current, Rhs, N) \ do { \ @@ -64,7 +64,7 @@ do { \ correctly typed access to it. */ #define yycontrol ((gram_control_t *) gram_control) -/* Request detailed parse error messages, and pass them to GRAM_ERROR. +/* Request detailed syntax error messages, and pass them to GRAM_ERROR. FIXME: depends on the undocumented availability of YYLLOC.t */ #undef yyerror #define yyerror(Msg) \ @@ -75,7 +75,7 @@ do { \ static void yyprint (FILE *file, int type, const yystype *value); symbol_class current_class = unknown_sym; -char *current_type = 0; +struniq_t current_type = 0; symbol_t *current_lhs; location_t current_lhs_location; assoc_t current_assoc; @@ -92,6 +92,7 @@ braced_code_t current_braced_code = action_braced_code; int integer; char *string; assoc_t assoc; + struniq_t struniq; }; /* Define the tokens together with their human representation. */ @@ -156,8 +157,10 @@ braced_code_t current_braced_code = action_braced_code; %token BRACED_CODE "{...}" -%type TYPE STRING string_content - BRACED_CODE PROLOGUE EPILOGUE epilogue.opt action +%type STRING string_content + BRACED_CODE code_content action + PROLOGUE EPILOGUE +%type TYPE %type INT %type ID symbol string_as_id %type precedence_declarator @@ -168,7 +171,6 @@ input: declarations "%%" grammar epilogue.opt { yycontrol->errcode = 0; - epilogue_set ($4, @4); } ; @@ -192,14 +194,20 @@ declaration: | "%expect" INT { expected_conflicts = $2; } | "%file-prefix" "=" string_content { spec_file_prefix = $3; } | "%glr-parser" { glr_parser = 1; } -| "%lex-param" string_content "," string_content - { muscle_pair_list_grow ("lex_param", $2, $4); } +| "%lex-param" code_content "," code_content + { + muscle_pair_list_grow ("lex_param", $2, $4); + scanner_last_string_free (); + } | "%locations" { locations_flag = 1; } | "%name-prefix" "=" string_content { spec_name_prefix = $3; } | "%no-lines" { no_lines_flag = 1; } | "%output" "=" string_content { spec_outfile = $3; } -| "%parse-param" string_content "," string_content - { muscle_pair_list_grow ("parse_param", $2, $4); } +| "%parse-param" code_content "," code_content + { + muscle_pair_list_grow ("parse_param", $2, $4); + scanner_last_string_free (); + } | "%pure-parser" { pure_parser = 1; } | "%skeleton" string_content { skeleton = $2; } | "%token-table" { token_table_flag = 1; } @@ -414,14 +422,21 @@ string_content: }; +/* A BRACED_CODE used for its contents. Strip the braces. */ +code_content: + BRACED_CODE + { + $$ = $1 + 1; + $$[strlen ($$) - 1] = '\0'; + }; + + epilogue.opt: /* Nothing. */ - { - $$ = xstrdup (""); - } | "%%" EPILOGUE { - $$ = $2; + epilogue_augment ($2, @2); + scanner_last_string_free (); } ; @@ -454,7 +469,7 @@ yyprint (FILE *file, break; case TYPE: - fprintf (file, " = <%s>", value->string); + fprintf (file, " = <%s>", value->struniq); break; case BRACED_CODE: @@ -462,6 +477,10 @@ yyprint (FILE *file, case EPILOGUE: fprintf (file, " = {{ %s }}", value->string); break; + + default: + fprintf (file, "unknown token type"); + break; } }