?? rule.h
字號:
#include <iostream>
#include <cctype>
using namespace std;
#include <string.h>
#include<windows.h>
int table[26];
int table2[26];
int islid=1;
char iden;
int del1;
struct Rright
{
public:
char letter;//右部規則的一個字符
char id;//該符號是否被標記
Rright* nextletter;//指向下個字符
Rright(){nextletter=NULL;letter='\0';}
};
class Rule
{
public:
Rright* right;
Rright* tempr;
Rright* pre;
char temp;
char trule[255];
Rright* head;
char left;//規則左部
int a;//表示是幾型正則文法.
int lid;//左部是否被標記 0為沒標記,1為標記
int lid2;
int lid3;
int spilth;//標記規則是否多余 0為不多余,1為多余
Rule();
void inputr();
void outputr();
void isspilth();//設置該規則是否多余
void isspilth2();
void isspilth3();
void sign(char idn);
void sign21();
void sign22();
void dgz();
bool isrg();//是否是正則文法
};
Rule::Rule()
{
left='\0';lid=0;spilth=0;right=new(Rright);
head=right;tempr=head;lid2=0;lid3=1;del1=0;
}
void Rule::inputr()
{
cout<<"-----------------------------------------------"<<endl;
lab1:cout<<"請輸入規則的左部:";
cin>>left;
while (cin.get()!='\n')
continue;
if (isalpha(left)!=1)
{cout<<"輸入非大寫字母,請重新輸入!\n";
goto lab1;}
cout<<"請輸入規則的右部:";
while (((right->letter=cin.get())!='\n'))
{
{right->nextletter=new(Rright);
pre=right;
right=right->nextletter;}
}
pre->nextletter=NULL;
cout<<"-----------------------------------------------"<<endl;
}
void Rule::outputr()
{
cout<<" "<<left<<"::=";
tempr=head;
do
{
cout<<tempr->letter;
}while ((tempr=tempr->nextletter)!=NULL);
cout<<endl;
tempr=head;
}
void Rule::isspilth()
{
if (lid==0&&spilth==0)
{spilth=1;del1+=1;}
}
void Rule::isspilth2()
{
if (lid2==0&&spilth==0)
{spilth=1;del1+=1;}
}
void Rule::isspilth3()
{
if (lid3==0&&spilth==0)
{spilth=1;del1+=1;}
}
void Rule::sign(char idn)
{
if (table[left-65]==1)
{lid=1;}
else if (left==idn)
{lid=1;}
if (lid==1)
{
while (tempr!=NULL)
{
if (tempr->letter>=65&&tempr->letter<=90)
{
table[tempr->letter-65]=1;
islid=1;
}
tempr=tempr->nextletter;
}
}
}
void Rule::sign21()
{
tempr=head;
if ((tempr->letter<65||tempr->letter>90)&&tempr->nextletter==NULL)
{
lid2=1;table2[left-65]=1;islid=1;
}
}
void Rule::sign22()
{
int t=1;
tempr=head;
while (tempr!=NULL)
{
if ((tempr->letter>=65&&tempr->letter<=90)&&table2[tempr->letter-65]!=1)
t=0;
tempr=tempr->nextletter;
}
if (t==1)
{lid2=1;table2[left-65]=1;islid=1;}
}
void Rule::dgz()
{
int t=1;
tempr=head;
while (tempr!=NULL)
{
if (tempr->letter!=left)
t=0;
tempr=tempr->nextletter;
}
tempr=head;
if (t==1)
lid3=0;
}
bool Rule::isrg()
{
tempr=head;
if ((head->letter<'A'||head->letter>'Z')&&head->nextletter==NULL)
{
return true;
}//U::=u的情況.
else
{
if (tempr->letter>='A'&&tempr->letter<='Z')
if (tempr->nextletter!=NULL)
{
if((tempr->nextletter->letter<'A'||tempr->nextletter->letter>'Z')&&tempr->nextletter->nextletter==NULL)
{return true;}
else return false;
}
else return false;
}
return false;
//U::=Uu的情況.
}
void SetColor()
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon,FOREGROUND_RED);
};
void SetColor2()
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon,FOREGROUND_GREEN);
}
void SetColorde()
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon,FOREGROUND_INTENSITY);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -