cmDependsFortranParser.y 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. %{
  2. /*============================================================================
  3. CMake - Cross Platform Makefile Generator
  4. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  5. Distributed under the OSI-approved BSD License (the "License");
  6. see accompanying file Copyright.txt for details.
  7. This software is distributed WITHOUT ANY WARRANTY; without even the
  8. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. See the License for more information.
  10. ============================================================================*/
  11. /*-------------------------------------------------------------------------
  12. Portions of this source have been derived from makedepf90 version 2.8.8,
  13. Copyright (C) 2000--2006 Erik Edelmann <[email protected]>
  14. The code was originally distributed under the GPL but permission
  15. from the copyright holder has been obtained to distribute this
  16. derived work under the CMake license.
  17. -------------------------------------------------------------------------*/
  18. /*
  19. This file must be translated to C and modified to build everywhere.
  20. Run bison like this:
  21. bison --yacc --name-prefix=cmDependsFortran_yy
  22. --defines=cmDependsFortranParserTokens.h
  23. -ocmDependsFortranParser.cxx
  24. cmDependsFortranParser.y
  25. Modify cmDependsFortranParser.cxx:
  26. - remove TABs
  27. - Remove the yyerrorlab block in range ["goto yyerrlab1", "yyerrlab1:"]
  28. */
  29. /*-------------------------------------------------------------------------*/
  30. #define cmDependsFortranParser_cxx
  31. #include "cmDependsFortranParser.h" /* Interface to parser object. */
  32. #include "cmDependsFortranParserTokens.h" /* Need YYSTYPE for YY_DECL. */
  33. #include <cmsys/String.h>
  34. /* Configure the parser to use a lexer object. */
  35. #define YYPARSE_PARAM yyscanner
  36. #define YYLEX_PARAM yyscanner
  37. #define YYERROR_VERBOSE 1
  38. #define cmDependsFortran_yyerror(x) \
  39. cmDependsFortranError(yyscanner, x)
  40. /* Forward declare the lexer entry point. */
  41. YY_DECL;
  42. /* Helper function to forward error callback. */
  43. static void cmDependsFortranError(yyscan_t yyscanner, const char* message)
  44. {
  45. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  46. cmDependsFortranParser_Error(parser, message);
  47. }
  48. static bool cmDependsFortranParserIsKeyword(const char* word,
  49. const char* keyword)
  50. {
  51. return cmsysString_strcasecmp(word, keyword) == 0;
  52. }
  53. /* Disable some warnings in the generated code. */
  54. #ifdef __BORLANDC__
  55. # pragma warn -8004 /* Variable assigned a value that is not used. */
  56. # pragma warn -8008 /* condition always returns true */
  57. # pragma warn -8060 /* possibly incorrect assignment */
  58. # pragma warn -8066 /* unreachable code */
  59. #endif
  60. #ifdef _MSC_VER
  61. # pragma warning (disable: 4102) /* Unused goto label. */
  62. # pragma warning (disable: 4065) /* Switch contains default but no case. */
  63. # pragma warning (disable: 4701) /* Local variable may not be initialized. */
  64. # pragma warning (disable: 4702) /* Unreachable code. */
  65. # pragma warning (disable: 4127) /* Conditional expression is constant. */
  66. # pragma warning (disable: 4244) /* Conversion to smaller type, data loss. */
  67. #endif
  68. %}
  69. /* Generate a reentrant parser object. */
  70. %pure-parser
  71. %union {
  72. char* string;
  73. }
  74. /*-------------------------------------------------------------------------*/
  75. /* Tokens */
  76. %token EOSTMT ASSIGNMENT_OP GARBAGE
  77. %token CPP_INCLUDE F90PPR_INCLUDE COCO_INCLUDE
  78. %token F90PPR_DEFINE CPP_DEFINE F90PPR_UNDEF CPP_UNDEF
  79. %token CPP_IFDEF CPP_IFNDEF CPP_IF CPP_ELSE CPP_ELIF CPP_ENDIF
  80. %token F90PPR_IFDEF F90PPR_IFNDEF F90PPR_IF
  81. %token F90PPR_ELSE F90PPR_ELIF F90PPR_ENDIF
  82. %token COMMA DCOLON
  83. %token <string> CPP_TOENDL
  84. %token <number> UNTERMINATED_STRING
  85. %token <string> STRING WORD
  86. /*-------------------------------------------------------------------------*/
  87. /* grammar */
  88. %%
  89. code: /* empty */ | code stmt;
  90. stmt: keyword_stmt | assignment_stmt;
  91. assignment_stmt: WORD ASSIGNMENT_OP other EOSTMT /* Ignore */
  92. {
  93. free($1);
  94. }
  95. keyword_stmt:
  96. WORD EOSTMT
  97. {
  98. if (cmDependsFortranParserIsKeyword($1, "interface"))
  99. {
  100. cmDependsFortranParser* parser =
  101. cmDependsFortran_yyget_extra(yyscanner);
  102. cmDependsFortranParser_SetInInterface(parser, true);
  103. }
  104. free($1);
  105. }
  106. | WORD WORD other EOSTMT
  107. {
  108. if (cmDependsFortranParserIsKeyword($1, "use"))
  109. {
  110. cmDependsFortranParser* parser =
  111. cmDependsFortran_yyget_extra(yyscanner);
  112. cmDependsFortranParser_RuleUse(parser, $2);
  113. }
  114. else if (cmDependsFortranParserIsKeyword($1, "module"))
  115. {
  116. cmDependsFortranParser* parser =
  117. cmDependsFortran_yyget_extra(yyscanner);
  118. cmDependsFortranParser_RuleModule(parser, $2);
  119. }
  120. else if (cmDependsFortranParserIsKeyword($1, "interface"))
  121. {
  122. cmDependsFortranParser* parser =
  123. cmDependsFortran_yyget_extra(yyscanner);
  124. cmDependsFortranParser_SetInInterface(parser, true);
  125. }
  126. else if (cmDependsFortranParserIsKeyword($2, "interface") &&
  127. cmDependsFortranParserIsKeyword($1, "end"))
  128. {
  129. cmDependsFortranParser* parser =
  130. cmDependsFortran_yyget_extra(yyscanner);
  131. cmDependsFortranParser_SetInInterface(parser, false);
  132. }
  133. free($1);
  134. free($2);
  135. }
  136. | WORD DCOLON WORD other EOSTMT
  137. {
  138. if (cmDependsFortranParserIsKeyword($1, "use"))
  139. {
  140. cmDependsFortranParser* parser =
  141. cmDependsFortran_yyget_extra(yyscanner);
  142. cmDependsFortranParser_RuleUse(parser, $3);
  143. }
  144. free($1);
  145. free($3);
  146. }
  147. | WORD COMMA WORD DCOLON WORD other EOSTMT
  148. {
  149. if (cmDependsFortranParserIsKeyword($1, "use") &&
  150. cmDependsFortranParserIsKeyword($3, "non_intrinsic") )
  151. {
  152. cmDependsFortranParser* parser =
  153. cmDependsFortran_yyget_extra(yyscanner);
  154. cmDependsFortranParser_RuleUse(parser, $5);
  155. }
  156. free($1);
  157. free($3);
  158. free($5);
  159. }
  160. | WORD STRING other EOSTMT /* Ignore */
  161. {
  162. if (cmDependsFortranParserIsKeyword($1, "include"))
  163. {
  164. cmDependsFortranParser* parser =
  165. cmDependsFortran_yyget_extra(yyscanner);
  166. cmDependsFortranParser_RuleInclude(parser, $2);
  167. }
  168. free($1);
  169. free($2);
  170. }
  171. | include STRING other EOSTMT
  172. {
  173. cmDependsFortranParser* parser =
  174. cmDependsFortran_yyget_extra(yyscanner);
  175. cmDependsFortranParser_RuleInclude(parser, $2);
  176. free($2);
  177. }
  178. | define WORD other EOSTMT
  179. {
  180. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  181. cmDependsFortranParser_RuleDefine(parser, $2);
  182. free($2);
  183. }
  184. | undef WORD other EOSTMT
  185. {
  186. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  187. cmDependsFortranParser_RuleUndef(parser, $2);
  188. free($2);
  189. }
  190. | ifdef WORD other EOSTMT
  191. {
  192. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  193. cmDependsFortranParser_RuleIfdef(parser, $2);
  194. free($2);
  195. }
  196. | ifndef WORD other EOSTMT
  197. {
  198. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  199. cmDependsFortranParser_RuleIfndef(parser, $2);
  200. free($2);
  201. }
  202. | if other EOSTMT
  203. {
  204. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  205. cmDependsFortranParser_RuleIf(parser);
  206. }
  207. | elif other EOSTMT
  208. {
  209. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  210. cmDependsFortranParser_RuleElif(parser);
  211. }
  212. | else other EOSTMT
  213. {
  214. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  215. cmDependsFortranParser_RuleElse(parser);
  216. }
  217. | endif other EOSTMT
  218. {
  219. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  220. cmDependsFortranParser_RuleEndif(parser);
  221. }
  222. | WORD GARBAGE other EOSTMT /* Ignore */
  223. {
  224. free($1);
  225. }
  226. | GARBAGE other EOSTMT
  227. | EOSTMT
  228. | error
  229. ;
  230. include: CPP_INCLUDE | F90PPR_INCLUDE | COCO_INCLUDE ;
  231. define: CPP_DEFINE | F90PPR_DEFINE;
  232. undef: CPP_UNDEF | F90PPR_UNDEF ;
  233. ifdef: CPP_IFDEF | F90PPR_IFDEF ;
  234. ifndef: CPP_IFNDEF | F90PPR_IFNDEF ;
  235. if: CPP_IF | F90PPR_IF ;
  236. elif: CPP_ELIF | F90PPR_ELIF ;
  237. else: CPP_ELSE | F90PPR_ELSE ;
  238. endif: CPP_ENDIF | F90PPR_ENDIF ;
  239. other: /* empty */ | other misc_code ;
  240. misc_code:
  241. WORD { free ($1); }
  242. | STRING { free ($1); }
  243. | GARBAGE
  244. | ASSIGNMENT_OP
  245. | DCOLON
  246. | COMMA
  247. | UNTERMINATED_STRING
  248. ;
  249. %%
  250. /* End of grammar */