2 /*=========================================================================
4 Program: CMake - Cross-Platform Makefile Generator
5 Module: $RCSfile: cmDependsFortranParser.y,v $
7 Date: $Date: 2009-06-12 14:46:25 $
8 Version: $Revision: 1.22 $
10 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
11 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
18 /*-------------------------------------------------------------------------
19 Portions of this source have been derived from makedepf90 version 2.8.8,
21 Copyright (C) 2000--2006 Erik Edelmann <erik.edelmann@iki.fi>
23 The code was originally distributed under the GPL but permission
24 from the copyright holder has been obtained to distribute this
25 derived work under the CMake license.
26 -------------------------------------------------------------------------*/
30 This file must be translated to C and modified to build everywhere.
34 bison --yacc --name-prefix=cmDependsFortran_yy
35 --defines=cmDependsFortranParserTokens.h
36 -ocmDependsFortranParser.cxx
37 cmDependsFortranParser.y
39 Modify cmDependsFortranParser.cxx:
41 - Remove the yyerrorlab block in range ["goto yyerrlab1", "yyerrlab1:"]
44 /*-------------------------------------------------------------------------*/
45 #define cmDependsFortranParser_cxx
46 #include "cmDependsFortranParser.h" /* Interface to parser object. */
47 #include "cmDependsFortranParserTokens.h" /* Need YYSTYPE for YY_DECL. */
49 #include <cmsys/String.h>
51 /* Configure the parser to use a lexer object. */
52 #define YYPARSE_PARAM yyscanner
53 #define YYLEX_PARAM yyscanner
54 #define YYERROR_VERBOSE 1
55 #define cmDependsFortran_yyerror(x) \
56 cmDependsFortranError
(yyscanner
, x
)
58 /* Forward declare the lexer entry point. */
61 /* Helper function to forward error callback. */
62 static void cmDependsFortranError
(yyscan_t yyscanner
, const char* message
)
64 cmDependsFortranParser
* parser
= cmDependsFortran_yyget_extra
(yyscanner
);
65 cmDependsFortranParser_Error
(parser
, message
);
68 static bool cmDependsFortranParserIsKeyword
(const char* word
,
71 return cmsysString_strcasecmp
(word
, keyword
) == 0;
74 /* Disable some warnings in the generated code. */
76 # pragma warn -8004 /* Variable assigned a value that is not used. */
77 # pragma warn -8008 /* condition always returns true */
78 # pragma warn -8060 /* possibly incorrect assignment */
79 # pragma warn -8066 /* unreachable code */
82 # pragma warning (disable: 4102) /* Unused goto label. */
83 # pragma warning (disable: 4065) /* Switch contains default but no case. */
84 # pragma warning (disable: 4701) /* Local variable may not be initialized. */
85 # pragma warning (disable: 4702) /* Unreachable code. */
86 # pragma warning (disable: 4127) /* Conditional expression is constant. */
87 # pragma warning (disable: 4244) /* Conversion to smaller type, data loss. */
91 /* Generate a reentrant parser object. */
98 /*-------------------------------------------------------------------------*/
100 %token EOSTMT ASSIGNMENT_OP GARBAGE
101 %token CPP_INCLUDE F90PPR_INCLUDE COCO_INCLUDE
102 %token F90PPR_DEFINE CPP_DEFINE F90PPR_UNDEF CPP_UNDEF
103 %token CPP_IFDEF CPP_IFNDEF CPP_IF CPP_ELSE CPP_ELIF CPP_ENDIF
104 %token F90PPR_IFDEF F90PPR_IFNDEF F90PPR_IF
105 %token F90PPR_ELSE F90PPR_ELIF F90PPR_ENDIF
107 %token
<string> CPP_TOENDL
108 %token
<number
> UNTERMINATED_STRING
109 %token
<string> STRING WORD
111 /*-------------------------------------------------------------------------*/
115 code: /* empty */ | code stmt
;
117 stmt: keyword_stmt | assignment_stmt
;
119 assignment_stmt: WORD ASSIGNMENT_OP other EOSTMT
/* Ignore */
127 if
(cmDependsFortranParserIsKeyword
($1, "interface"))
129 cmDependsFortranParser
* parser
=
130 cmDependsFortran_yyget_extra
(yyscanner
);
131 cmDependsFortranParser_SetInInterface
(parser
, true
);
135 | WORD WORD other EOSTMT
137 if
(cmDependsFortranParserIsKeyword
($1, "use"))
139 cmDependsFortranParser
* parser
=
140 cmDependsFortran_yyget_extra
(yyscanner
);
141 cmDependsFortranParser_RuleUse
(parser
, $2);
143 else if
(cmDependsFortranParserIsKeyword
($1, "module"))
145 cmDependsFortranParser
* parser
=
146 cmDependsFortran_yyget_extra
(yyscanner
);
147 cmDependsFortranParser_RuleModule
(parser
, $2);
149 else if
(cmDependsFortranParserIsKeyword
($1, "interface"))
151 cmDependsFortranParser
* parser
=
152 cmDependsFortran_yyget_extra
(yyscanner
);
153 cmDependsFortranParser_SetInInterface
(parser
, true
);
155 else if
(cmDependsFortranParserIsKeyword
($2, "interface") &&
156 cmDependsFortranParserIsKeyword
($1, "end"))
158 cmDependsFortranParser
* parser
=
159 cmDependsFortran_yyget_extra
(yyscanner
);
160 cmDependsFortranParser_SetInInterface
(parser
, false
);
165 | WORD DCOLON WORD other EOSTMT
167 if
(cmDependsFortranParserIsKeyword
($1, "use"))
169 cmDependsFortranParser
* parser
=
170 cmDependsFortran_yyget_extra
(yyscanner
);
171 cmDependsFortranParser_RuleUse
(parser
, $3);
176 | WORD COMMA WORD DCOLON WORD other EOSTMT
178 if
(cmDependsFortranParserIsKeyword
($1, "use") &&
179 cmDependsFortranParserIsKeyword
($3, "non_intrinsic") )
181 cmDependsFortranParser
* parser
=
182 cmDependsFortran_yyget_extra
(yyscanner
);
183 cmDependsFortranParser_RuleUse
(parser
, $5);
189 | WORD STRING other EOSTMT
/* Ignore */
191 if
(cmDependsFortranParserIsKeyword
($1, "include"))
193 cmDependsFortranParser
* parser
=
194 cmDependsFortran_yyget_extra
(yyscanner
);
195 cmDependsFortranParser_RuleInclude
(parser
, $2);
200 | include STRING other EOSTMT
202 cmDependsFortranParser
* parser
=
203 cmDependsFortran_yyget_extra
(yyscanner
);
204 cmDependsFortranParser_RuleInclude
(parser
, $2);
207 | define WORD other EOSTMT
209 cmDependsFortranParser
* parser
= cmDependsFortran_yyget_extra
(yyscanner
);
210 cmDependsFortranParser_RuleDefine
(parser
, $2);
213 | undef WORD other EOSTMT
215 cmDependsFortranParser
* parser
= cmDependsFortran_yyget_extra
(yyscanner
);
216 cmDependsFortranParser_RuleUndef
(parser
, $2);
219 | ifdef WORD other EOSTMT
221 cmDependsFortranParser
* parser
= cmDependsFortran_yyget_extra
(yyscanner
);
222 cmDependsFortranParser_RuleIfdef
(parser
, $2);
225 | ifndef WORD other EOSTMT
227 cmDependsFortranParser
* parser
= cmDependsFortran_yyget_extra
(yyscanner
);
228 cmDependsFortranParser_RuleIfndef
(parser
, $2);
233 cmDependsFortranParser
* parser
= cmDependsFortran_yyget_extra
(yyscanner
);
234 cmDependsFortranParser_RuleIf
(parser
);
238 cmDependsFortranParser
* parser
= cmDependsFortran_yyget_extra
(yyscanner
);
239 cmDependsFortranParser_RuleElif
(parser
);
243 cmDependsFortranParser
* parser
= cmDependsFortran_yyget_extra
(yyscanner
);
244 cmDependsFortranParser_RuleElse
(parser
);
248 cmDependsFortranParser
* parser
= cmDependsFortran_yyget_extra
(yyscanner
);
249 cmDependsFortranParser_RuleEndif
(parser
);
251 | WORD GARBAGE other EOSTMT
/* Ignore */
255 | GARBAGE other EOSTMT
262 include: CPP_INCLUDE | F90PPR_INCLUDE | COCO_INCLUDE
;
263 define: CPP_DEFINE | F90PPR_DEFINE
;
264 undef: CPP_UNDEF | F90PPR_UNDEF
;
265 ifdef: CPP_IFDEF | F90PPR_IFDEF
;
266 ifndef: CPP_IFNDEF | F90PPR_IFNDEF
;
267 if: CPP_IF | F90PPR_IF
;
268 elif: CPP_ELIF | F90PPR_ELIF
;
269 else: CPP_ELSE | F90PPR_ELSE
;
270 endif: CPP_ENDIF | F90PPR_ENDIF
;
271 other: /* empty */ | other misc_code
;
275 | STRING
{ free
($1); }
280 | UNTERMINATED_STRING