From 3f16d3402aff70ae8e39753d32a30bdaedf036aa Mon Sep 17 00:00:00 2001 From: Cary R Date: Fri, 28 Dec 2007 20:22:42 -0800 Subject: [PATCH] V0.8: add `elsif add some conditional directive syntax checks. This is a direct back port from the development branch. It adds the `elsif directive and adds check that the conditional directives are used correctly. --- ivlpp/lexor.lex | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index c09c76112..bc3205540 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -310,6 +310,23 @@ W [ \t\b\f]+ yy_push_state(IFDEF_SUPR); } +`elsif{W}[a-zA-Z_][a-zA-Z0-9_$]* { + BEGIN(IFDEF_SUPR); + } +`elsif{W}[a-zA-Z_][a-zA-Z0-9_$]* { + char*name = strchr(yytext, '`'); + assert(name); + name += 6; + name += strspn(name, " \t\b\f"); + + if (is_defined(name)) { + BEGIN(IFDEF_TRUE); + } else { + BEGIN(IFDEF_FALSE); + } + } +`elsif{W}[a-zA-Z_][a-zA-Z0-9_$]* { } + `else { BEGIN(IFDEF_FALSE); } `else { BEGIN(IFDEF_TRUE); } `else { } @@ -332,6 +349,42 @@ W [ \t\b\f]+ `endif { ifdef_leave(); yy_pop_state(); } +`ifdef { + fprintf(stderr, "%s:%u: `ifdef without a macro name - ignored.\n", + istack->path, istack->lineno+1); + error_count += 1; + } + +`ifndef { + fprintf(stderr, "%s:%u: `ifndef without a macro name - ignored.\n", + istack->path, istack->lineno+1); + error_count += 1; + } + +`elsif { + fprintf(stderr, "%s:%u: `elsif without a macro name - ignored.\n", + istack->path, istack->lineno+1); + error_count += 1; + } + +`elsif{W}[a-zA-Z_][a-zA-Z0-9_$]* { + fprintf(stderr, "%s:%u: `elsif without a matching `ifdef - ignored.\n", + istack->path, istack->lineno+1); + error_count += 1; + } + +`else { + fprintf(stderr, "%s:%u: `else without a matching `ifdef - ignored.\n", + istack->path, istack->lineno+1); + error_count += 1; + } + +`endif { + fprintf(stderr, "%s:%u: `endif without a matching `ifdef - ignored.\n", + istack->path, istack->lineno+1); + error_count += 1; + } + /* This pattern notices macros and arranges for them to be replaced. */ `[a-zA-Z_][a-zA-Z0-9_$]* { def_match(); }