Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmDependsFortranParser.y
blob802dacec3a2f74f855072de7012d7e80f4d38ac5
1 %{
2 /*=========================================================================
4 Program: CMake - Cross-Platform Makefile Generator
5 Module: $RCSfile: cmDependsFortranParser.y,v $
6 Language: C++
7 Date: $Date: 2009-02-17 16:53:57 $
8 Version: $Revision: 1.21 $
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.
32 Run bison like this:
34 bison --yacc --name-prefix=cmDependsFortran_yy
35 --defines=cmDependsFortranParserTokens.h
36 -ocmDependsFortranParser.cxx
37 cmDependsFortranParser.y
39 Modify cmDependsFortranParser.cxx:
40 - remove TABs
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 /* Configure the parser to use a lexer object. */
50 #define YYPARSE_PARAM yyscanner
51 #define YYLEX_PARAM yyscanner
52 #define YYERROR_VERBOSE 1
53 #define cmDependsFortran_yyerror(x) \
54 cmDependsFortranError(yyscanner, x)
56 /* Forward declare the lexer entry point. */
57 YY_DECL;
59 /* Helper function to forward error callback. */
60 static void cmDependsFortranError(yyscan_t yyscanner, const char* message)
62 cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
63 cmDependsFortranParser_Error(parser, message);
66 static char charmap[] = {
67 '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
68 '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
69 '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
70 '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
71 '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
72 '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
73 '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
74 '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
75 '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
76 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
77 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
78 '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
79 '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
80 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
81 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
82 '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
83 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
84 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
85 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
86 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
87 '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
88 '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
89 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
90 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
91 '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
92 '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
93 '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
94 '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
95 '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
96 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
97 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
98 '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377'
101 inline int strcasecmpCM(const char *s1, const char *s2)
103 const char *cm = charmap;
104 unsigned char const* us1 = reinterpret_cast<unsigned char const*>(s1);
105 unsigned char const* us2 = reinterpret_cast<unsigned char const*>(s2);
107 while(cm[*us1] == cm[*us2++])
108 if(*us1++ == '\0')
110 return(0);
112 return(cm[*us1] - cm[*--us2]);
115 static bool cmDependsFortranParserIsKeyword(const char* word,
116 const char* keyword)
118 return strcasecmpCM(word, keyword) == 0;
121 /* Disable some warnings in the generated code. */
122 #ifdef __BORLANDC__
123 # pragma warn -8004 /* Variable assigned a value that is not used. */
124 # pragma warn -8008 /* condition always returns true */
125 # pragma warn -8060 /* possibly incorrect assignment */
126 # pragma warn -8066 /* unreachable code */
127 #endif
128 #ifdef _MSC_VER
129 # pragma warning (disable: 4102) /* Unused goto label. */
130 # pragma warning (disable: 4065) /* Switch contains default but no case. */
131 # pragma warning (disable: 4701) /* Local variable may not be initialized. */
132 # pragma warning (disable: 4702) /* Unreachable code. */
133 # pragma warning (disable: 4127) /* Conditional expression is constant. */
134 # pragma warning (disable: 4244) /* Conversion to smaller type, data loss. */
135 #endif
138 /* Generate a reentrant parser object. */
139 %pure-parser
141 %union {
142 char* string;
145 /*-------------------------------------------------------------------------*/
146 /* Tokens */
147 %token EOSTMT ASSIGNMENT_OP GARBAGE
148 %token CPP_INCLUDE F90PPR_INCLUDE COCO_INCLUDE
149 %token F90PPR_DEFINE CPP_DEFINE F90PPR_UNDEF CPP_UNDEF
150 %token CPP_IFDEF CPP_IFNDEF CPP_IF CPP_ELSE CPP_ELIF CPP_ENDIF
151 %token F90PPR_IFDEF F90PPR_IFNDEF F90PPR_IF
152 %token F90PPR_ELSE F90PPR_ELIF F90PPR_ENDIF
153 %token COMMA DCOLON
154 %token <string> CPP_TOENDL
155 %token <number> UNTERMINATED_STRING
156 %token <string> STRING WORD
158 /*-------------------------------------------------------------------------*/
159 /* grammar */
162 code: /* empty */ | code stmt;
164 stmt: keyword_stmt | assignment_stmt;
166 assignment_stmt: WORD ASSIGNMENT_OP other EOSTMT /* Ignore */
168 free($1);
171 keyword_stmt:
172 WORD EOSTMT
174 if (cmDependsFortranParserIsKeyword($1, "interface"))
176 cmDependsFortranParser* parser =
177 cmDependsFortran_yyget_extra(yyscanner);
178 cmDependsFortranParser_SetInInterface(parser, true);
180 free($1);
182 | WORD WORD other EOSTMT
184 if (cmDependsFortranParserIsKeyword($1, "use"))
186 cmDependsFortranParser* parser =
187 cmDependsFortran_yyget_extra(yyscanner);
188 cmDependsFortranParser_RuleUse(parser, $2);
190 else if (cmDependsFortranParserIsKeyword($1, "module"))
192 cmDependsFortranParser* parser =
193 cmDependsFortran_yyget_extra(yyscanner);
194 cmDependsFortranParser_RuleModule(parser, $2);
196 else if (cmDependsFortranParserIsKeyword($1, "interface"))
198 cmDependsFortranParser* parser =
199 cmDependsFortran_yyget_extra(yyscanner);
200 cmDependsFortranParser_SetInInterface(parser, true);
202 else if (cmDependsFortranParserIsKeyword($2, "interface") &&
203 cmDependsFortranParserIsKeyword($1, "end"))
205 cmDependsFortranParser* parser =
206 cmDependsFortran_yyget_extra(yyscanner);
207 cmDependsFortranParser_SetInInterface(parser, false);
209 free($1);
210 free($2);
212 | WORD DCOLON WORD other EOSTMT
214 if (cmDependsFortranParserIsKeyword($1, "use"))
216 cmDependsFortranParser* parser =
217 cmDependsFortran_yyget_extra(yyscanner);
218 cmDependsFortranParser_RuleUse(parser, $3);
220 free($1);
221 free($3);
223 | WORD COMMA WORD DCOLON WORD other EOSTMT
225 if (cmDependsFortranParserIsKeyword($1, "use") &&
226 cmDependsFortranParserIsKeyword($3, "non_intrinsic") )
228 cmDependsFortranParser* parser =
229 cmDependsFortran_yyget_extra(yyscanner);
230 cmDependsFortranParser_RuleUse(parser, $5);
232 free($1);
233 free($3);
234 free($5);
236 | WORD STRING other EOSTMT /* Ignore */
238 if (cmDependsFortranParserIsKeyword($1, "include"))
240 cmDependsFortranParser* parser =
241 cmDependsFortran_yyget_extra(yyscanner);
242 cmDependsFortranParser_RuleInclude(parser, $2);
244 free($1);
245 free($2);
247 | include STRING other EOSTMT
249 cmDependsFortranParser* parser =
250 cmDependsFortran_yyget_extra(yyscanner);
251 cmDependsFortranParser_RuleInclude(parser, $2);
252 free($2);
254 | define WORD other EOSTMT
256 cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
257 cmDependsFortranParser_RuleDefine(parser, $2);
258 free($2);
260 | undef WORD other EOSTMT
262 cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
263 cmDependsFortranParser_RuleUndef(parser, $2);
264 free($2);
266 | ifdef WORD other EOSTMT
268 cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
269 cmDependsFortranParser_RuleIfdef(parser, $2);
270 free($2);
272 | ifndef WORD other EOSTMT
274 cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
275 cmDependsFortranParser_RuleIfndef(parser, $2);
276 free($2);
278 | if other EOSTMT
280 cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
281 cmDependsFortranParser_RuleIf(parser);
283 | elif other EOSTMT
285 cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
286 cmDependsFortranParser_RuleElif(parser);
288 | else other EOSTMT
290 cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
291 cmDependsFortranParser_RuleElse(parser);
293 | endif other EOSTMT
295 cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner);
296 cmDependsFortranParser_RuleEndif(parser);
298 | WORD GARBAGE other EOSTMT /* Ignore */
300 free($1);
302 | GARBAGE other EOSTMT
303 | EOSTMT
304 | error
309 include: CPP_INCLUDE | F90PPR_INCLUDE | COCO_INCLUDE ;
310 define: CPP_DEFINE | F90PPR_DEFINE;
311 undef: CPP_UNDEF | F90PPR_UNDEF ;
312 ifdef: CPP_IFDEF | F90PPR_IFDEF ;
313 ifndef: CPP_IFNDEF | F90PPR_IFNDEF ;
314 if: CPP_IF | F90PPR_IF ;
315 elif: CPP_ELIF | F90PPR_ELIF ;
316 else: CPP_ELSE | F90PPR_ELSE ;
317 endif: CPP_ENDIF | F90PPR_ENDIF ;
318 other: /* empty */ | other misc_code ;
320 misc_code:
321 WORD { free ($1); }
322 | STRING { free ($1); }
323 | GARBAGE
324 | ASSIGNMENT_OP
325 | DCOLON
326 | COMMA
327 | UNTERMINATED_STRING
331 /* End of grammar */