diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index afa7f3c6c..d862f4236 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -201,12 +201,13 @@ static int ma_parenthesis_level = 0; %x IFDEF_NAME %x IFNDEF_NAME +%s IFDEF_TRUE +%x IFDEF_FALSE +%x IFDEF_SUPR %x ELSIF_NAME %x ELSIF_SUPR - -%x IFDEF_FALSE -%s IFDEF_TRUE -%x IFDEF_SUPR +%s ELSE_TRUE +%x ELSE_SUPR W [ \t\b\f]+ @@ -214,7 +215,7 @@ W [ \t\b\f]+ * older versions of flex (at least 2.5.31); they are supposed to * be implied, according to the flex manual. */ -keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) +keywords (include|define|undef|ifdef|ifndef|else|elsif|endif) %% @@ -417,16 +418,16 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) yy_push_state(IFNDEF_NAME); } -`ifdef{W} | -`ifndef{W} { ifdef_enter(); yy_push_state(IFDEF_SUPR); } +`ifdef{W} | +`ifndef{W} { ifdef_enter(); yy_push_state(IFDEF_SUPR); } -`elsif{W} { prev_state = YYSTATE; BEGIN(ELSIF_SUPR); } -`elsif{W} { prev_state = YYSTATE; BEGIN(ELSIF_NAME); } +`elsif{W} | `elsif{W} { prev_state = YYSTATE; BEGIN(ELSIF_SUPR); } +`elsif{W} { prev_state = YYSTATE; BEGIN(ELSIF_NAME); } -`else { BEGIN(IFDEF_SUPR); } -`else { BEGIN(IFDEF_TRUE); } -`else {} +`else | +`else { BEGIN(ELSE_SUPR); } +`else { BEGIN(ELSE_TRUE); } [a-zA-Z_][a-zA-Z0-9_$]* { if (is_defined(yytext)) @@ -453,9 +454,9 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) BEGIN(IFDEF_SUPR); } -"//"[^\r\n]* {} +"//"[^\r\n]* {} -"/*" { comment_enter = YY_START; BEGIN(IFCCOMMENT); } +"/*" { comment_enter = YY_START; BEGIN(IFCCOMMENT); } [^\r\n] {} \n\r | @@ -464,13 +465,13 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) \r { istack->lineno += 1; fputc('\n', yyout); } "*/" { BEGIN(comment_enter); } -[^\r\n] { } -\n\r | -\r\n | -\n | -\r { istack->lineno += 1; fputc('\n', yyout); } +[^\r\n] { } +\n\r | +\r\n | +\n | +\r { istack->lineno += 1; fputc('\n', yyout); } -`endif { ifdef_leave(); yy_pop_state(); } +`endif { ifdef_leave(); yy_pop_state(); } (\n|\r) | . | @@ -510,6 +511,20 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) } } +`elsif{W}[a-zA-Z_][a-zA-Z0-9_$]* { + emit_pathline(istack); + fprintf(stderr, "error: `elsif after a matching `else.\n"); + error_count += 1; + BEGIN(ELSE_SUPR); +} + +`else { + emit_pathline(istack); + fprintf(stderr, "error: `else after a matching `else.\n"); + error_count += 1; + BEGIN(ELSE_SUPR); +} + `elsif{W}[a-zA-Z_][a-zA-Z0-9_$]* { emit_pathline(istack); fprintf(stderr, "error: `elsif without a matching `ifdef.\n");