?? parsingstack.cpp
字號:
#include "stdafx.h"
using namespace std;
ParsingStack::ParsingStack()
{}
void ParsingStack::initialize()
{
currentPosition=-1;
head=0;
count=0;
current=0;
popHead=0;
popCurrent=0;
head=push("dl");
push("P");
}
stackEntry* ParsingStack::push(string entry)
{
if(current==0)
{
current=new stackEntry;
current->entry=entry;
count++;
return current;
}
else
{
stackEntry* temp;
temp=new stackEntry;
temp->entry=entry;
temp->lower=current;
current=temp;
count++;
return temp;
}
}
stackEntry* ParsingStack::pop()
{
stackEntry* temp;
temp=current;
current=current->lower;
if(popHead==0)
{
popHead=popCurrent=temp;
}
else
{
popCurrent->lower=temp;
popCurrent=popCurrent->lower;
}
count--;
return temp;
}
string ParsingStack::getEntry(string tableEntry)
//divide the string of the production into several entries.
{
if(currentPosition<0)
{
currentPosition=tableEntry.length()-1;
}
string temp="";
while(currentPosition>=0&&tableEntry[currentPosition]!=' ')
{
temp=tableEntry.substr(currentPosition,1)+temp;
currentPosition--;
}
if(currentPosition>=0)
{
currentPosition--;
}
return temp;
}
stackEntry* ParsingStack::replace(string tableEntry)
//replace the top entry of parsing stack with the entries returned by getEntry(string);
{
pop();
push(getEntry(tableEntry));
while(currentPosition>=0)
{
push(getEntry(tableEntry));
}
return current;
}
stackEntry* ParsingStack::getTop()
{
return current;
}
bool ParsingStack::isEmpty()
{
if(count==0)
{
return true;
}
else return false;
}
ParsingStack::~ParsingStack()
{
stackEntry* temp;
while(popHead!=popCurrent&&popHead!=0)
{
temp=popHead;
popHead=popHead->lower;
delete temp;
}
delete popHead;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -