fixed a problem with #ifdef/#else/#endif

This commit is contained in:
ceriel 1988-03-08 11:42:00 +00:00
parent 1a259744af
commit 4b79636b8f
4 changed files with 14 additions and 10 deletions

View file

@ -32,6 +32,8 @@ PRIVATE char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
/* 1 if a corresponding ELSE has been */
/* encountered. */
int nestlevel = -1;
PRIVATE struct idf *
GetIdentifier()
{
@ -184,7 +186,7 @@ skip_block()
}
break;
case K_ENDIF:
ASSERT(nestlevel >= 0);
ASSERT(nestlevel > nestlow);
if (nestlevel == skiplevel) {
SkipRestOfLine();
nestlevel--;
@ -249,7 +251,7 @@ do_include()
File_Inserted = 1;
FileName = result;
LineNumber = 0;
nestlevel = -1;
nestlow = nestlevel;
}
}
}
@ -314,7 +316,7 @@ push_if()
PRIVATE
do_elif()
{
if (nestlevel < 0 || (ifstack[nestlevel])) {
if (nestlevel <= nestlow || (ifstack[nestlevel])) {
lexerror("#elif without corresponding #if");
SkipRestOfLine();
}
@ -329,7 +331,7 @@ PRIVATE
do_else()
{
SkipRestOfLine();
if (nestlevel < 0 || (ifstack[nestlevel]))
if (nestlevel <= nestlow || (ifstack[nestlevel]))
lexerror("#else without corresponding #if");
else { /* mark this level as else-d */
++(ifstack[nestlevel]);
@ -341,7 +343,7 @@ PRIVATE
do_endif()
{
SkipRestOfLine();
if (nestlevel < 0) {
if (nestlevel <= nestlow) {
lexerror("#endif without corresponding #if");
}
else nestlevel--;

View file

@ -7,12 +7,12 @@
struct file_info {
unsigned int fil_lino;
int fil_nestlevel;
int fil_nestlow;
char *fil_name;
char *fil_wdir;
};
#define nestlevel finfo.fil_nestlevel
#define nestlow finfo.fil_nestlow
#define LineNumber finfo.fil_lino
#define FileName finfo.fil_name
#define WorkingDir finfo.fil_wdir

View file

@ -10,6 +10,7 @@
#define INP_TYPE struct file_info
#define INP_VAR finfo
struct file_info finfo;
extern int nestlevel;
#include "nopp.h"
#include <inp_pkg.body>
@ -44,7 +45,7 @@ int NoUnstack;
AtEoIT()
{
#ifndef NOPP
if (NoUnstack) lexwarning("unexpected EOF");
/* if (NoUnstack) lexwarning("unexpected EOF"); ??? */
DoUnstack();
#endif NOPP
return 0;
@ -54,9 +55,10 @@ AtEoIF()
{
#ifndef NOPP
if (nestlevel != -1) lexwarning("missing #endif");
if (nestlevel != nestlow) lexwarning("missing #endif");
else
#endif NOPP
if (NoUnstack) lexwarning("unexpected EOF");
nestlevel = nestlow;
return 0;
}

View file

@ -171,7 +171,7 @@ compile(argc, argv)
File_Inserted = 1;
init();
LineNumber = 0;
nestlevel = -1;
nestlow = -1;
#ifndef NOPP
WorkingDir = getwdir(source);
#endif NOPP