grammarapptest.cpp
来自「compiler principle how to ananilyze」· C++ 代码 · 共 87 行
CPP
87 行
// GrammarAppTest.cpp: implementation of the GrammarAppTest class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "GrammarAppTest.h"
#include "Parser.h"
#include "SymbolTable.h"
#include <iostream>
#include <fstream>
#include <string>
#include <assert.h>
using namespace std;
extern SymbolTable symbol_table;
GrammarAppTest::GrammarAppTest()
{
}
void GrammarAppTest::test_display() {
cout << "please enter the file path (include name) of a grammar G[S]" << endl;
string str;
cin >> str;
ifstream file;
try {
file.open(str.c_str());
assert(file);
Parser p;
p.parse(&file);
cout << p.grammar_display() << endl;
cout << symbol_table.toStr() << endl;
}
catch(GException& ge) {
cout << ge.toStr() << endl;
}
cout << "...close file... " << endl;
file.close();
}
void GrammarAppTest::test_grammarType() {
cout << "please enter the file path (include name) of a grammar G[S]" << endl;
string str;
cin >> str;
ifstream file;
try {
file.open(str.c_str());
assert(file);
Parser p;
p.parse(&file);
cout << p.grammar_type() << endl;
cout << p.grammar_display() << endl;
cout << symbol_table.toStr() << endl;
}
catch(GException& ge) {
cout << ge.toStr() << endl;
}
cout << "...close file... " << endl;
file.close();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?