具体实现:first集根据第四点会出现递归求first集,当然在求first集时应判断文法是否成环,比如此文法A->A等等;
follow应该注意是否重复求某一非终结符的follow集。
#include<iostream>
#include<string>
using namespace std;
class Node
{
public:
char S;
string P;
Node *next;
Node(char _S, string _P= "\0")
{
S = _S;
P = _P;
next = NULL;
}
~Node(){ }
};
class FF
{
private:
Node **G;
string ss;
int num;
public:
FF();
~FF();
void FIRST(char val , string& firval);
bool FIRST(int index, string& firval);
void FOLLOW(char v ,string &folval,string &over);
void insert(char v , string val);
void quicksort(int left ,int right);
int partition(int left , int right);
void sort();
int find(char val);
bool find(string val,char c);