X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/50a339934c5e471f02a1d28171b14e2875a05cf0..31c10e38dbf21a29af558c6f5144acd22dbc956e:/src/parse-gram.y diff --git a/src/parse-gram.y b/src/parse-gram.y index bc012637..956ddd36 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -83,6 +83,7 @@ static int current_prec = 0; %error-verbose %defines %name-prefix="gram_" +%expect 0 %initial-action { @@ -115,6 +116,8 @@ static int current_prec = 0; %token PERCENT_TYPE "%type" %token PERCENT_DESTRUCTOR "%destructor" %token PERCENT_PRINTER "%printer" +%token PERCENT_SYMBOL_DEFAULT + "%symbol-default" %token PERCENT_LEFT "%left" %token PERCENT_RIGHT "%right" @@ -153,6 +156,7 @@ static int current_prec = 0; PERCENT_OUTPUT "%output" PERCENT_PARSE_PARAM "%parse-param" PERCENT_PURE_PARSER "%pure-parser" + PERCENT_PUSH_PARSER "%push-parser" PERCENT_REQUIRE "%require" PERCENT_SKELETON "%skeleton" PERCENT_START "%start" @@ -198,7 +202,7 @@ static int current_prec = 0; %printer { fprintf (stderr, "%s:", $$->tag); } id_colon %type precedence_declarator -%type symbols.1 +%type symbols.1 generic_symlist generic_symlist_item %% input: @@ -245,6 +249,7 @@ prologue_declaration: | "%output" "=" STRING { spec_outfile = $3; } | "%parse-param" "{...}" { add_param ("parse_param", $2, @2); } | "%pure-parser" { pure_parser = true; } +| "%push-parser" { push_parser = true; } | "%require" STRING { version_check (&@2, $2); } | "%skeleton" STRING { skeleton = $2; } | "%start-header" braceless { muscle_code_grow ("start_header", $2, @2); } @@ -261,20 +266,20 @@ grammar_declaration: { grammar_start_symbol_set ($2, @2); } -| "%destructor" "{...}" symbols.1 +| "%destructor" "{...}" generic_symlist { symbol_list *list; const char *action = translate_symbol_action ($2, @2); for (list = $3; list; list = list->next) - symbol_destructor_set (list->sym, action, @2); + symbol_list_destructor_set (list, action, @2); symbol_list_free ($3); } -| "%printer" "{...}" symbols.1 +| "%printer" "{...}" generic_symlist { symbol_list *list; const char *action = translate_symbol_action ($2, @2); for (list = $3; list; list = list->next) - symbol_printer_set (list->sym, action, @2); + symbol_list_printer_set (list, action, @2); symbol_list_free ($3); } | "%default-prec" @@ -343,7 +348,7 @@ symbol_declaration: tag_seen = true; symbol_list *list; for (list = $3; list; list = list->next) - symbol_type_set (list->sym, $2, @2); + symbol_type_set (list->content.sym, $2, @2); symbol_list_free ($3); } ; @@ -355,8 +360,8 @@ precedence_declaration: ++current_prec; for (list = $3; list; list = list->next) { - symbol_type_set (list->sym, current_type, @2); - symbol_precedence_set (list->sym, current_prec, $1, @1); + symbol_type_set (list->content.sym, current_type, @2); + symbol_precedence_set (list->content.sym, current_prec, $1, @1); } symbol_list_free ($3); current_type = NULL; @@ -374,10 +379,23 @@ type.opt: | TYPE { current_type = $1; tag_seen = true; } ; -/* One or more nonterminals to be %typed. */ +/* One or more symbols to be %typed. */ symbols.1: - symbol { $$ = symbol_list_new ($1, @1); } -| symbols.1 symbol { $$ = symbol_list_prepend ($1, $2, @2); } + symbol + { $$ = symbol_list_sym_new ($1, @1); } +| symbols.1 symbol + { $$ = symbol_list_prepend ($1, symbol_list_sym_new ($2, @2)); } +; + +generic_symlist: + generic_symlist_item { $$ = $1; } +| generic_symlist generic_symlist_item { $$ = symbol_list_prepend ($1, $2); } +; + +generic_symlist_item: + symbol { $$ = symbol_list_sym_new ($1, @1); } +| TYPE { $$ = symbol_list_type_new ($1, @1); } +| "%symbol-default" { $$ = symbol_list_default_new (@1); } ; /* One token definition. */