⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complexion.h

📁 这是一个下推自动机的模拟程序为完成作业而写
💻 H
字号:
#ifndef COMPLEXION_H
#define COMPLEXION_H

#include<iostream.h>
#include<string.h>
#include"AStack.h"
#include"Function.h"

class Complexion{
	friend Complexion &operator<=(Complexion &com1,Complexion &com2);
	friend ostream &operator<<(ostream &output,Complexion &com2);
public:
	char state;
	char *endState;
	char *inputString;
	int curr;
	AStack *storeStack; 

	Complexion(char s,char *input,char *end)
	{
		state=s;
		inputString=new char[(int)strlen(input)];
		strcpy(inputString,input);
		endState=new char[(int)strlen(end)];
		strcpy(endState,end);

		curr=0;
		storeStack=new AStack(100);
	}

	Complexion(Complexion &c)
	{
		state=c.state;
		inputString=new char[(int)strlen(c.inputString)];
		strcpy(inputString,c.inputString);
		endState=new char[(int)strlen(c.endState)];
		strcpy(endState,c.endState);
		curr=c.curr;
        storeStack=new AStack(100);
		for(int i=0;i<(c.storeStack)->length();i++)
		{
			storeStack->push((c.storeStack)->listArray[i]);
		}
	}

    char topCharOfStack()
	{
		char c;
		storeStack->topValue(c);
		return c;
	}

	char currChar()
	{
		if(curr<(int)strlen(inputString))
		    return inputString[curr];

		return 'e';
	}

	void push(char *s)
	{
		int len=(int)strlen(s);
		for(int i=len-1;i>=0;i--)
			storeStack->push(s[i]);
	}

	bool isInEndState(char c)
	{
		for(int i=0;i<(int)strlen(endState);i++)
			if(endState[i]==c)
				return true;
		return false;
	}
	bool isEnd()
	{
		if(curr==(int)strlen(inputString)&&isInEndState(state)&&storeStack->isEmpty())
			return true;
		return false;
	}

	bool isOver()
	{
		if(curr>(int)strlen(inputString))
			return true;
		return false;
	}

};

Complexion &operator<=(Complexion &com1,Complexion &com2)
{
	com1.state=com2.state;
	com1.inputString=new char[(int)strlen(com2.inputString)];
	strcpy(com1.inputString,com2.inputString);
	com1.curr=com2.curr;
	(com1.storeStack)->clear();
	for(int i=0;i<(com1.storeStack)->length();i++)
	     (com1.storeStack)->push((com1.storeStack)->listArray[i]);
	com1.endState=new char[(int)strlen(com2.endState)];
	strcpy(com1.endState,com2.endState);

	return com2;
}

ostream &operator<<(ostream &output,Complexion &com2)
{
	output<<"state:"<<com2.state<<endl;
	for(int i=com2.curr;i<(int)strlen(com2.inputString);i++)
		output<<com2.inputString[i];
	cout<<endl;
	com2.storeStack->print();
	return output;
}
#endif

⌨️ 快捷键说明

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