cmDependsFortranParser.y 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. %{
  2. /*=========================================================================
  3. Program: CMake - Cross-Platform Makefile Generator
  4. Module: $RCSfile$
  5. Language: C++
  6. Date: $Date$
  7. Version: $Revision$
  8. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  9. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  10. This software is distributed WITHOUT ANY WARRANTY; without even
  11. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12. PURPOSE. See the above copyright notices for more information.
  13. =========================================================================*/
  14. /*-------------------------------------------------------------------------
  15. Portions of this source have been derived from makefdep90 version 2.6.2,
  16. Copyright (C) 2000,2001 Erik Edelmann <[email protected]>.
  17. The code was originally distributed under the GPL but permission
  18. from the copyright holder has been obtained to distribute this
  19. derived work under the CMake license.
  20. -------------------------------------------------------------------------*/
  21. /*
  22. This file must be translated to C and modified to build everywhere.
  23. Run bison like this:
  24. bison --yacc --name-prefix=cmDependsFortran_yy --defines=cmDependsFortranParserTokens.h -ocmDependsFortranParser.cxx cmDependsFortranParser.y
  25. Modify cmDependsFortranParser.cxx:
  26. - remove TABs
  27. - add __HP_aCC to the #if test for yyerrorlab warning suppression
  28. - add __INTEL_COMPILER to the #if test for yyerrorlab warning suppression
  29. */
  30. /*-------------------------------------------------------------------------*/
  31. #define cmDependsFortranParser_cxx
  32. #include "cmDependsFortranParser.h" /* Interface to parser object. */
  33. #include "cmDependsFortranParserTokens.h" /* Need YYSTYPE for YY_DECL. */
  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 char charmap[] = {
  49. '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  50. '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  51. '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  52. '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  53. '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  54. '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  55. '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  56. '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  57. '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  58. '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  59. '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  60. '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  61. '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  62. '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  63. '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  64. '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  65. '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  66. '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  67. '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  68. '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  69. '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  70. '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  71. '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  72. '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  73. '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
  74. '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
  75. '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
  76. '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
  77. '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  78. '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  79. '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  80. '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377'
  81. };
  82. inline int strcasecmpCM(const char *s1, const char *s2)
  83. {
  84. const char *cm = charmap;
  85. const char* us1 = s1;
  86. const char* us2 = s2;
  87. while(cm[*us1] == cm[*us2++])
  88. if(*us1++ == '\0')
  89. {
  90. return(0);
  91. }
  92. return(cm[*us1] - cm[*--us2]);
  93. }
  94. static bool cmDependsFortranParserIsKeyword(const char* word,
  95. const char* keyword)
  96. {
  97. return strcasecmpCM(word, keyword) == 0;
  98. }
  99. /* Disable some warnings in the generated code. */
  100. #ifdef __BORLANDC__
  101. # pragma warn -8004 /* Variable assigned a value that is not used. */
  102. # pragma warn -8008 /* condition always returns true */
  103. # pragma warn -8060 /* possibly incorrect assignment */
  104. # pragma warn -8066 /* unreachable code */
  105. #endif
  106. #ifdef _MSC_VER
  107. # pragma warning (disable: 4102) /* Unused goto label. */
  108. # pragma warning (disable: 4065) /* Switch contains default but no case. */
  109. #endif
  110. %}
  111. /* Generate a reentrant parser object. */
  112. %pure-parser
  113. %union {
  114. char* string;
  115. }
  116. /*-------------------------------------------------------------------------*/
  117. /* Tokens */
  118. %token EOSTMT ASSIGNMENT_OP GARBAGE
  119. %token CPP_INCLUDE F90PPR_INCLUDE COCO_INCLUDE
  120. %token F90PPR_DEFINE CPP_DEFINE F90PPR_UNDEF CPP_UNDEF
  121. %token CPP_IFDEF CPP_IFNDEF CPP_IF CPP_ELSE CPP_ELIF CPP_ENDIF
  122. %token F90PPR_IFDEF F90PPR_IFNDEF F90PPR_IF F90PPR_ELSE F90PPR_ELIF F90PPR_ENDIF
  123. %token <string> CPP_TOENDL
  124. %token <number> UNTERMINATED_STRING
  125. %token <string> STRING WORD
  126. /*-------------------------------------------------------------------------*/
  127. /* grammar */
  128. %%
  129. code: /* empty */ | code stmt;
  130. stmt: keyword_stmt | assignment_stmt;
  131. assignment_stmt: WORD ASSIGNMENT_OP other EOSTMT /* Ignore */
  132. keyword_stmt:
  133. WORD EOSTMT
  134. {
  135. if (cmDependsFortranParserIsKeyword($1, "interface"))
  136. {
  137. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  138. cmDependsFortranParser_SetInInterface(parser, true);
  139. }
  140. free($1);
  141. }
  142. | WORD WORD other EOSTMT
  143. {
  144. if (cmDependsFortranParserIsKeyword($1, "use"))
  145. {
  146. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  147. cmDependsFortranParser_RuleUse(parser, $2);
  148. free($2);
  149. }
  150. else if (cmDependsFortranParserIsKeyword($1, "module"))
  151. {
  152. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  153. cmDependsFortranParser_RuleModule(parser, $2);
  154. free($2);
  155. }
  156. else if (cmDependsFortranParserIsKeyword($1, "interface"))
  157. {
  158. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  159. cmDependsFortranParser_SetInInterface(parser, true);
  160. free($2);
  161. }
  162. else if (cmDependsFortranParserIsKeyword($2, "interface") &&
  163. cmDependsFortranParserIsKeyword($1, "end"))
  164. {
  165. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  166. cmDependsFortranParser_SetInInterface(parser, false);
  167. free($2);
  168. }
  169. free($1);
  170. }
  171. | WORD STRING other EOSTMT
  172. {
  173. if (cmDependsFortranParserIsKeyword($1, "include"))
  174. {
  175. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  176. cmDependsFortranParser_RuleInclude(parser, $2);
  177. }
  178. free($1);
  179. free($2);
  180. }
  181. | CPP_INCLUDE WORD other EOSTMT /* Ignore */
  182. | define WORD other EOSTMT
  183. {
  184. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  185. cmDependsFortranParser_RuleDefine(parser, $2);
  186. free($2);
  187. }
  188. | undef WORD other EOSTMT
  189. {
  190. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  191. cmDependsFortranParser_RuleUndef(parser, $2);
  192. free($2);
  193. }
  194. | ifdef WORD other EOSTMT
  195. {
  196. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  197. cmDependsFortranParser_RuleIfdef(parser, $2);
  198. free($2);
  199. }
  200. | ifndef WORD other EOSTMT
  201. {
  202. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  203. cmDependsFortranParser_RuleIfndef(parser, $2);
  204. free($2);
  205. }
  206. | if other EOSTMT
  207. {
  208. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  209. cmDependsFortranParser_RuleIf(parser);
  210. }
  211. | elif other EOSTMT
  212. {
  213. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  214. cmDependsFortranParser_RuleElif(parser);
  215. }
  216. | else other EOSTMT
  217. {
  218. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  219. cmDependsFortranParser_RuleElse(parser);
  220. }
  221. | endif other EOSTMT
  222. {
  223. cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
  224. cmDependsFortranParser_RuleEndif(parser);
  225. }
  226. | WORD GARBAGE other EOSTMT /* Ignore */
  227. | GARBAGE other EOSTMT
  228. | EOSTMT
  229. | error
  230. ;
  231. include: CPP_INCLUDE | F90PPR_INCLUDE | COCO_INCLUDE ;
  232. define: CPP_DEFINE | F90PPR_DEFINE;
  233. undef: CPP_UNDEF | F90PPR_UNDEF ;
  234. ifdef: CPP_IFDEF | F90PPR_IFDEF ;
  235. ifndef: CPP_IFNDEF | F90PPR_IFNDEF ;
  236. if: CPP_IF | F90PPR_IF ;
  237. elif: CPP_ELIF | F90PPR_ELIF ;
  238. else: CPP_ELSE | F90PPR_ELSE ;
  239. endif: CPP_ENDIF | F90PPR_ENDIF ;
  240. other: /* empty */ | other misc_code ;
  241. misc_code:
  242. WORD { free ($1); }
  243. | STRING { free ($1); }
  244. | GARBAGE
  245. | ASSIGNMENT_OP
  246. | UNTERMINATED_STRING
  247. ;
  248. %%
  249. /* End of grammar */