Commit c5802271 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'fortran-parser-keywords'

695f0d0d cmFortranParser: Parse keywords as lexical tokens
1619fb46 cmFortranParser: Simplify grammar by skipping unknown statements
parents 46cf4151 695f0d0d
This diff is collapsed.
......@@ -337,7 +337,7 @@ extern int cmFortran_yylex (yyscan_t yyscanner);
#undef YY_DECL
#endif
#line 176 "cmFortranLexer.in.l"
#line 182 "cmFortranLexer.in.l"
#line 344 "cmFortranLexer.h"
......
......@@ -151,6 +151,12 @@ $[ \t]*endif { return F90PPR_ENDIF; }
=|=> { return ASSIGNMENT_OP; }
[Ee][Nn][Dd] { return END; }
[Ii][Nn][Cc][Ll][Uu][Dd][Ee] { return INCLUDE; }
[Ii][Nn][Tt][Ee][Rr][Ff][Aa][Cc][Ee] { return INTERFACE; }
[Mm][Oo][Dd][Uu][Ll][Ee] { return MODULE; }
[Uu][Ss][Ee] { return USE; }
[a-zA-Z_][a-zA-Z_0-9]* {
yylvalp->string = strdup(yytext);
return WORD;
......
This diff is collapsed.
......@@ -52,12 +52,6 @@ static void cmFortran_yyerror(yyscan_t yyscanner, const char* message)
cmFortranParser_Error(parser, message);
}
static bool cmFortranParserIsKeyword(const char* word,
const char* keyword)
{
return cmsysString_strcasecmp(word, keyword) == 0;
}
/* Disable some warnings in the generated code. */
#ifdef _MSC_VER
# pragma warning (disable: 4102) /* Unused goto label. */
......@@ -95,6 +89,11 @@ static bool cmFortranParserIsKeyword(const char* word,
%token <number> UNTERMINATED_STRING
%token <string> STRING WORD
%token <string> CPP_INCLUDE_ANGLE
%token END
%token INCLUDE
%token INTERFACE
%token MODULE
%token USE
/*-------------------------------------------------------------------------*/
/* grammar */
......@@ -102,63 +101,46 @@ static bool cmFortranParserIsKeyword(const char* word,
code: /* empty */ | code stmt;
stmt: keyword_stmt | assignment_stmt;
assignment_stmt:
WORD ASSIGNMENT_OP other EOSTMT {
free($1);
stmt:
INTERFACE EOSTMT {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_SetInInterface(parser, true);
}
keyword_stmt:
WORD EOSTMT {
if (cmFortranParserIsKeyword($1, "interface")) {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_SetInInterface(parser, true);
}
free($1);
| USE WORD other EOSTMT {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleUse(parser, $2);
free($2);
}
| WORD WORD other EOSTMT {
if (cmFortranParserIsKeyword($1, "use")) {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleUse(parser, $2);
} else if (cmFortranParserIsKeyword($1, "module")) {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleModule(parser, $2);
} else if (cmFortranParserIsKeyword($1, "interface")) {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_SetInInterface(parser, true);
} else if (cmFortranParserIsKeyword($2, "interface") &&
cmFortranParserIsKeyword($1, "end")) {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_SetInInterface(parser, false);
}
free($1);
| MODULE WORD other EOSTMT {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleModule(parser, $2);
free($2);
}
| WORD DCOLON WORD other EOSTMT {
if (cmFortranParserIsKeyword($1, "use")) {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleUse(parser, $3);
}
free($1);
| INTERFACE WORD other EOSTMT {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_SetInInterface(parser, true);
free($2);
}
| END INTERFACE other EOSTMT {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_SetInInterface(parser, false);
}
| USE DCOLON WORD other EOSTMT {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleUse(parser, $3);
free($3);
}
| WORD COMMA WORD DCOLON WORD other EOSTMT {
if (cmFortranParserIsKeyword($1, "use") &&
cmFortranParserIsKeyword($3, "non_intrinsic") ) {
| USE COMMA WORD DCOLON WORD other EOSTMT {
if (cmsysString_strcasecmp($3, "non_intrinsic") == 0) {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleUse(parser, $5);
}
free($1);
free($3);
free($5);
}
| WORD STRING other EOSTMT {
if (cmFortranParserIsKeyword($1, "include")) {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleInclude(parser, $2);
}
free($1);
| INCLUDE STRING other EOSTMT {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleInclude(parser, $2);
free($2);
}
| CPP_LINE_DIRECTIVE STRING other EOSTMT {
......@@ -212,12 +194,8 @@ keyword_stmt:
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleEndif(parser);
}
| WORD GARBAGE other EOSTMT {
free($1);
}
| GARBAGE other EOSTMT
| EOSTMT
| error
| error EOSTMT /* tolerate unknown statements until their end */
;
......@@ -235,6 +213,11 @@ other: /* empty */ | other misc_code ;
misc_code:
WORD { free ($1); }
| END
| INCLUDE
| INTERFACE
| MODULE
| USE
| STRING { free ($1); }
| GARBAGE
| ASSIGNMENT_OP
......
......@@ -73,7 +73,12 @@ extern int cmFortran_yydebug;
UNTERMINATED_STRING = 283,
STRING = 284,
WORD = 285,
CPP_INCLUDE_ANGLE = 286
CPP_INCLUDE_ANGLE = 286,
END = 287,
INCLUDE = 288,
INTERFACE = 289,
MODULE = 290,
USE = 291
};
#endif
/* Tokens. */
......@@ -106,17 +111,22 @@ extern int cmFortran_yydebug;
#define STRING 284
#define WORD 285
#define CPP_INCLUDE_ANGLE 286
#define END 287
#define INCLUDE 288
#define INTERFACE 289
#define MODULE 290
#define USE 291
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 81 "cmFortranParser.y" /* yacc.c:1909 */
#line 75 "cmFortranParser.y" /* yacc.c:1909 */
char* string;
#line 120 "cmFortranParserTokens.h" /* yacc.c:1909 */
#line 130 "cmFortranParserTokens.h" /* yacc.c:1909 */
};
typedef union YYSTYPE YYSTYPE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment