stack.h

来自「输入一个DO-WHILE的语句,进行词法分析,词法分析器利用超前搜索,状态转换等」· C头文件 代码 · 共 80 行

H
80
字号


#ifndef STACK_H
#define STACK_H

#include "Global.h"

/*
	Stack operates			*/
void InitStack();
bool Push(const char*);
bool Pop(char*);
bool TopValue(char*);
void PrintStack();

/*
	Stack attributes		*/
char TheStack[STACKSIZE];
int  StackTop;

/*
	Implement stack operates	*/
void InitStack()
{
	char c = '#';
	StackTop = 0;
	Push(&c);
}

bool Push(const char* c)
{
    if (StackTop < STACKSIZE)
    {
        TheStack[StackTop++] = *c;
        return true;
    }
    else
    {
        return false;
    }
}

bool Pop(char* c)
{
    if (StackTop >= 0)
    {
        *c = TheStack[--StackTop];
        return true;
    }
    else
    {
        return false;
    }
}

bool TopValue(char* c)
{
	if (StackTop > 0)	/* not null */
	{
		*c = TheStack[StackTop-1];
		return true;
	}
	else
	{
		return false;
	}
}

void PrintStack()
{
	int i;
	for (i=0;  i<StackTop; i++)
	{
		printf("%c", TheStack[i]);
	}
	printf("\n");
}

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?