arparse.y 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. %{
  2. /* arparse.y - Strange script language parser */
  3. /* Copyright (C) 1992-2022 Free Software Foundation, Inc.
  4. This file is part of GNU Binutils.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. /* Contributed by Steve Chamberlain
  18. sac@cygnus.com
  19. */
  20. #define DONTDECLARE_MALLOC
  21. #include "sysdep.h"
  22. #include "bfd.h"
  23. #include "arsup.h"
  24. extern int verbose;
  25. extern int yylex (void);
  26. static void yyerror (const char *);
  27. %}
  28. %union {
  29. char *name;
  30. struct list *list ;
  31. };
  32. %token NEWLINE
  33. %token VERBOSE
  34. %token <name> FILENAME
  35. %token ADDLIB
  36. %token LIST
  37. %token ADDMOD
  38. %token CLEAR
  39. %token CREATE
  40. %token DELETE
  41. %token DIRECTORY
  42. %token END
  43. %token EXTRACT
  44. %token FULLDIR
  45. %token HELP
  46. %token QUIT
  47. %token REPLACE
  48. %token SAVE
  49. %token OPEN
  50. %type <list> modulelist
  51. %type <list> modulename
  52. %type <name> optional_filename
  53. %%
  54. start:
  55. { prompt(); } session
  56. ;
  57. session:
  58. session command_line
  59. |
  60. ;
  61. command_line:
  62. command NEWLINE { prompt(); }
  63. ;
  64. command:
  65. open_command
  66. | create_command
  67. | verbose_command
  68. | directory_command
  69. | addlib_command
  70. | clear_command
  71. | addmod_command
  72. | save_command
  73. | extract_command
  74. | replace_command
  75. | delete_command
  76. | list_command
  77. | END { ar_end(); return 0; }
  78. | error
  79. | FILENAME { yyerror("foo"); }
  80. |
  81. ;
  82. extract_command:
  83. EXTRACT modulename
  84. { ar_extract($2); }
  85. ;
  86. replace_command:
  87. REPLACE modulename
  88. { ar_replace($2); }
  89. ;
  90. clear_command:
  91. CLEAR
  92. { ar_clear(); }
  93. ;
  94. delete_command:
  95. DELETE modulename
  96. { ar_delete($2); }
  97. ;
  98. addmod_command:
  99. ADDMOD modulename
  100. { ar_addmod($2); }
  101. ;
  102. list_command:
  103. LIST
  104. { ar_list(); }
  105. ;
  106. save_command:
  107. SAVE
  108. { ar_save(); }
  109. ;
  110. open_command:
  111. OPEN FILENAME
  112. { ar_open($2,0); }
  113. ;
  114. create_command:
  115. CREATE FILENAME
  116. { ar_open($2,1); }
  117. ;
  118. addlib_command:
  119. ADDLIB FILENAME modulelist
  120. { ar_addlib($2,$3); }
  121. ;
  122. directory_command:
  123. DIRECTORY FILENAME modulelist optional_filename
  124. { ar_directory($2, $3, $4); }
  125. ;
  126. optional_filename:
  127. FILENAME
  128. { $$ = $1; }
  129. | { $$ = 0; }
  130. ;
  131. modulelist:
  132. '(' modulename ')'
  133. { $$ = $2; }
  134. |
  135. { $$ = 0; }
  136. ;
  137. modulename:
  138. modulename optcomma FILENAME
  139. { struct list *n = (struct list *) malloc(sizeof(struct list));
  140. n->next = $1;
  141. n->name = $3;
  142. $$ = n;
  143. }
  144. | { $$ = 0; }
  145. ;
  146. optcomma:
  147. ','
  148. |
  149. ;
  150. verbose_command:
  151. VERBOSE
  152. { verbose = !verbose; }
  153. ;
  154. %%
  155. static void
  156. yyerror (const char *x ATTRIBUTE_UNUSED)
  157. {
  158. extern int linenumber;
  159. printf (_("Syntax error in archive script, line %d\n"), linenumber + 1);
  160. }