/*
*author: YFL AHU 09级
*time: 2011/10/30
题目:
输入任意的上下文无关文法,输出所输入的上下文无关文法一切非终结符的first集合和follow集合
输入格式:
每行输入一个产生式,左部右部中间的→用空格代替。
非终结符等价于大写字母
^ 表示 空(ε用^代替)
输入到文件结束,或用 0 0 结尾。
Sample Input:
(习题5・3):
S MH
S a
H LSo
H ^
K dML
K ^
L eHf
M K
M bLM
0 0
*/
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
using namespace std;
char l;
string r;
multimap<char, string> sentence; //存储产生式
multimap<string, char> senRever; //产生式逆转
set<char> ter; //非终结符集合
map<char, bool> toEmpty; //非终结符能否推出 空
bool flag;
set<char> fir; // 保存单个元素的first集
set<char> follow; //保存单个元素的follow集
vector<string> rightSide; //右部
char Begin;
bool capL(char c) //字母是否大写
{
if(c<='Z' && c>='A')
return true;
return false;
}
/*
bool lowerL(char c) //小写字母
{
if(c<='z' && c>='a')
- 1
- 2
前往页