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