diff options
author | Brad King <brad.king@kitware.com> | 2016-09-05 15:54:51 -0400 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-09-08 09:40:02 -0400 |
commit | 695f0d0d3a2db22d2ee3a426df8a1ec502cd471b (patch) | |
tree | 430d7aafdf9c1f28ffed28d0ed569d842f51695f /Source/cmFortranParser.y | |
parent | 1619fb46a88accd1e6864f0c9de27ae2fd46541a (diff) | |
download | cmake-695f0d0d3a2db22d2ee3a426df8a1ec502cd471b.tar.gz |
cmFortranParser: Parse keywords as lexical tokens
Teach the lexer to match and return specific Fortran keywords as tokens.
Update the parser to use these instead of always using a WORD token and
then checking the text. This avoids extra string comparisons and will
allow more grammar productions to be unambiguously added later for
additional Fortran statements.
Diffstat (limited to 'Source/cmFortranParser.y')
-rw-r--r-- | Source/cmFortranParser.y | 82 |
1 files changed, 38 insertions, 44 deletions
diff --git a/Source/cmFortranParser.y b/Source/cmFortranParser.y index 686d2f4fe7..b856a1a3ad 100644 --- a/Source/cmFortranParser.y +++ b/Source/cmFortranParser.y @@ -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 */ @@ -103,55 +102,45 @@ static bool cmFortranParserIsKeyword(const char* word, code: /* empty */ | code stmt; stmt: - WORD EOSTMT { - if (cmFortranParserIsKeyword($1, "interface")) { - cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); - cmFortranParser_SetInInterface(parser, true); - } - free($1); + INTERFACE EOSTMT { + cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); + cmFortranParser_SetInInterface(parser, true); } -| 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); +| USE WORD other EOSTMT { + cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); + cmFortranParser_RuleUse(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); +| MODULE WORD other EOSTMT { + cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); + cmFortranParser_RuleModule(parser, $2); + free($2); + } +| 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 { @@ -224,6 +213,11 @@ other: /* empty */ | other misc_code ; misc_code: WORD { free ($1); } +| END +| INCLUDE +| INTERFACE +| MODULE +| USE | STRING { free ($1); } | GARBAGE | ASSIGNMENT_OP |