i have shared the header file containing class definition of a Context Free grammar for a parser. Could you comment on the design. this code is for my lab assignment. may be we could get some good programming tips out of this code. is the class heirarchy good or too complicated.
#ifndef CFG_H
#define CFG_H
#include <iostream>
#include <set>
#include <list>
using namespace std;
class Terminal;
class CfgSymbol
{
protected:
char ch;
set<Terminal*> first;
set<Terminal*> follow;
public:
CfgSymbol()
{
ch = '\0';
}
CfgSymbol(char c) : ch(c)
{
}
virtual void computeFirst() = 0;
};
class Terminal: public CfgSymbol
{
private:
public:
Terminal(): CfgSymbol()
{
}
Terminal(char c) : CfgSymbol(c)
{
computeFirst();
}
virtual void computeFirst()
{
first->insert(this);
}
};
class NonTerminal: public CfgSymbol
{
private:
public:
virtual void computeFirst();
virtual void computeFollow();
};
class SymbolString
{
public:
CfgProduction* prd;
list<CfgSymbol*> symstr;
void computeFirst();
void computeFollow();
};
class CfgProduction
{
private:
NonTerminal lhs;
SymbolString rhs;
public:
int add_terminal(char t);
int add_nonterminal(char n);
int set_lhs(char c);
};
class Cfg
{
public:
vector<CfgProduction*> prdList;
void addProduction(const CfgProduction& cfg);
void computeFirst();
void computeFollow();
void computeFirstFollow();
};
#endif