-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
54 lines (46 loc) · 1.25 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <parsererrorlistener.h>
#include <visitormath.h>
#include <MathLexer.h>
#include <MathParser.h>
#include <QFile>
#include <Exceptions.h>
using namespace antlrtest;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_parse_clicked()
{
antlr4::ANTLRInputStream input(ui->textEdit_inputmath->toPlainText ().toUtf8 ().constData ());
antlrtest::MathLexer lexer(&input);
antlr4::CommonTokenStream tokens(&lexer);
antlrtest::MathParser parser(&tokens);
ParserErrorListener pel;
parser.addErrorListener(&pel);
try {
parser.setBuildParseTree(true);
tokens.fill();
antlr4::tree::ParseTree *tree = parser.prog();
VisitorMath v;
v.setWidgetDebug (ui->textEdit_outputmath);
v.visit(tree);
} catch (std::exception &e) {
ui->textEdit_outputmath->append ("\nerror: "+QString::fromStdString (e.what()));
}
}
void MainWindow::on_pushButton_inputclear_clicked()
{
ui->textEdit_inputmath->clear ();
}
void MainWindow::on_pushButton_clearoutput_clicked()
{
ui->textEdit_outputmath->clear ();
}