输入输出文法1

Input

 8
E E+T
T T*F
E T
T F
F (E)
F i
E E-T
T T/F

Output

G[E]:
E::=E+T | T | E-T
T::=T*F | F | T/F
F::=(E) | i

 

#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
int main(int argc, char const *argv[])
{
	struct  { int Nv;string VN[10];} Vns={3,"E","T","F"};
	struct  { int Nt;string VT[10];} Vts={7,"+","-","*","/","(",")","i"};
	struct  { int Np;string PL[20],PR[20];} ps={0};
	string S="E"; 
	int N;
	cin >> N;
	std::map<string, vector<string> > m;
	while(N--){
		string a;
		string b;
		cin >> a >> b;
		m[a].push_back(b);
	}

	// print
	cout << "G[" << S << "]:" << endl;
	for (int i = 0; i < Vns.Nv; ++i)
	{
		cout << Vns.VN[i] << "::=";
		for(int j = 0; j < m[Vns.VN[i]].size(); j++){
			if(j < m[Vns.VN[i]].size()-1)
				cout << m[Vns.VN[i]][j] << " | ";
			else
				cout << m[Vns.VN[i]][j];
		}
		cout << endl;
	}
	return 0;
}

 

相关文章:

  • 2022-02-02
  • 2021-04-30
  • 2021-06-25
  • 2021-10-11
  • 2021-04-16
  • 2021-04-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-06
  • 2021-04-29
  • 2021-11-12
  • 2021-11-19
相关资源
相似解决方案