22
33# Language-independent M4 Macros for Bison.
44
5- # Copyright (C) 2002, 2004-2015, 2018 Free Software Foundation, Inc.
5+ # Copyright (C) 2002, 2004-2015, 2018-2019 Free Software Foundation,
6+ # Inc.
67
78# This program is free software: you can redistribute it and/or modify
89# it under the terms of the GNU General Public License as published by
@@ -263,8 +264,8 @@ m4_define([b4_subtract],
263264# -------------------
264265# Join with comma, skipping empty arguments.
265266# b4_join calls itself recursively until it sees the first non-empty
266- # argument, then calls _b4_join which prepends each non-empty argument
267- # with a comma.
267+ # argument, then calls _b4_join (i.e., `_$0`) which prepends each
268+ # non-empty argument with a comma.
268269m4_define ( [ b4_join] ,
269270[ m4_if ( [ $#$1 ] ,
270271 [ 1] , [ ] ,
@@ -374,60 +375,42 @@ b4_define_flag_if([token_table]) # Whether yytoken_table is demanded.
374375b4_define_flag_if([ yacc] ) # Whether POSIX Yacc is emulated.
375376
376377
378+ # b4_glr_cc_if([IF-TRUE], [IF-FALSE])
379+ # -----------------------------------
380+ m4_define ( [ b4_glr_cc_if] ,
381+ [ m4_if ( b4_skeleton , [ "glr.cc"] , $@ ) ] )
382+
383+
377384# # --------- ##
378385# # Symbols. ##
379386# # --------- ##
380387
381- # In order to unify the handling of the various aspects of symbols
382- # (tag, type_name, whether terminal, etc.), bison.exe defines one
383- # macro per (token, field), where field can has_id, id, etc.: see
384- # src/output.c:prepare_symbols_definitions().
385- #
386- # The various FIELDS are:
388+ # For a description of the Symbol handling, see README.
387389#
388- # - has_id: 0 or 1.
389- # Whether the symbol has an id.
390- # - id: string
391- # If has_id, the id. Guaranteed to be usable as a C identifier.
392- # Prefixed by api.token.prefix if defined.
393- # - tag: string.
394- # A representat of the symbol. Can be 'foo', 'foo.id', '"foo"' etc.
395- # - user_number: integer
396- # The assigned (external) number as used by yylex.
397- # - is_token: 0 or 1
398- # Whether this is a terminal symbol.
399- # - number: integer
400- # The internalized number (used after yytranslate).
401- # - has_type: 0, 1
402- # Whether has a semantic value.
403- # - type_tag: string
404- # When api.value.type=union, the generated name for the union member.
405- # yytype_INT etc. for symbols that has_id, otherwise yytype_1 etc.
406- # - type
407- # If it has a semantic value, its type tag, or, if variant are used,
408- # its type.
409- # In the case of api.value.type=union, type is the real type (e.g. int).
410- # - has_printer: 0, 1
411- # - printer: string
412- # - printer_file: string
413- # - printer_line: integer
414- # If the symbol has a printer, everything about it.
415- # - has_destructor, destructor, destructor_file, destructor_line
416- # Likewise.
417- #
418- # The following macros provide access to these values.
390+ # The following macros provide access to symbol related values.
391+
392+ # __b4_symbol(NUM, FIELD)
393+ # -----------------------
394+ # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
395+ # undefined.
396+ m4_define ( [ __b4_symbol] ,
397+ [ m4_indir ( [ b4_symbol($1 , $2 )] ) ] )
398+
419399
420400# _b4_symbol(NUM, FIELD)
421401# ----------------------
422- # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
402+ # Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if
423403# undefined.
424404m4_define ( [ _b4_symbol] ,
425- [ m4_indir ( [ b4_symbol($1 , $2 )] ) ] )
405+ [ m4_ifdef ( [ b4_symbol($1 , number)] ,
406+ [ __b4_symbol(m4_indir ( [ b4_symbol($1 , number)] ) , $2 )] ,
407+ [ __b4_symbol([ $1 ] , [ $2 ] )] ) ] )
408+
426409
427410
428411# b4_symbol(NUM, FIELD)
429412# ---------------------
430- # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
413+ # Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if
431414# undefined. If FIELD = id, prepend the token prefix.
432415m4_define ( [ b4_symbol] ,
433416[ m4_case ( [ $2 ] ,
@@ -468,8 +451,8 @@ m4_define([b4_symbol_action_location],
468451m4_define ( [ b4_symbol_action] ,
469452[ b4_symbol_if([ $1 ] , [ has_$2 ] ,
470453[ b4_dollar_pushdef([ (*yyvaluep)] ,
471- b4_symbol_if( [ $1 ] , [ has_type ] ,
472- [ m4_dquote ( b4_symbol ( [ $1 ] , [ type ] )) ] ) ,
454+ [ $1 ] ,
455+ [ ] ,
473456 [ (*yylocationp)] )dnl
474457 _b4_symbol_case([ $1 ] )[ ] dnl
475458b4_syncline([ b4_symbol([ $1 ] , [ $2 _line] )] , [ b4_symbol([ $1 ] , [ $2 _file] )] )
@@ -497,7 +480,7 @@ m4_define([b4_symbol_actions],
497480m4_ifval ( m4_defn ( [ b4_actions_] ) ,
498481[ switch (m4_default ( [ $2 ] , [ yytype] ) )
499482 {
500- m4_defn ( [ b4_actions_] )
483+ m4_defn ( [ b4_actions_] ) [ ] dnl
501484 default:
502485 break;
503486 }dnl
@@ -508,7 +491,9 @@ m4_popdef([b4_actions_])dnl
508491
509492# _b4_symbol_case(SYMBOL-NUM)
510493# ---------------------------
511- # Issue a "case NUM" for SYMBOL-NUM.
494+ # Issue a "case NUM" for SYMBOL-NUM. Ends with its EOL to make it
495+ # easier to use with m4_map, but then, use []dnl to suppress the last
496+ # one.
512497m4_define ( [ _b4_symbol_case] ,
513498[ case b4_symbol([ $1 ] , [ number] ): b4_symbol_tag_comment([ $1 ] )] )
514499])
@@ -569,7 +554,7 @@ m4_define([b4_token_format],
569554# Run actions for the symbol NUMS that all have the same type-name.
570555# Skip NUMS that have no type-name.
571556#
572- # To specify the action to run, define b4_dollar_dollar(NUMBER ,
557+ # To specify the action to run, define b4_dollar_dollar(SYMBOL-NUM ,
573558# TAG, TYPE).
574559m4_define ( [ _b4_type_action] ,
575560[ b4_symbol_if([ $1 ] , [ has_type] ,
0 commit comments