-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive.cpp
More file actions
57 lines (44 loc) · 1.19 KB
/
Copy pathinteractive.cpp
File metadata and controls
57 lines (44 loc) · 1.19 KB
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
55
56
#include "interactive.h"
#include<iostream>
#include<string>
#include<vector>
#include "..\tokenizer\tokenizer.h"
#include "..\parser\parser.h"
using namespace std;
const std::string INPUT_HINT = " >> ";
const std::string STREAM_NAME = "<stdin>";
#define SHOW_INPUT_HINT() std::cout << INPUT_HINT;
Mediator::Mediator():cline(""){}
void Mediator::setinput(std::string input){
cline = input;
called = false;
}
std::string Mediator::callback(){
if(called) return "\0";
called = true;
return cline;
}
int interactive_Main(){
Mediator md;
CTokenizer tokenizer(STREAM_NAME, &md);
std::cout << "-------- INTERACTIVE MODE --------" << std::endl;
std::cout << "Type \"exit()\" or \"quit()\" to exit" << std::endl;
SHOW_INPUT_HINT();
std::string input;
std::getline(std::cin, input);
while(input != "exit()" && input != "quit()"){
if(input == "exit"){
std::cout << "Use exit() or quit() to exit" << std::endl;
}else {
md.setinput(input);
try{
tokenizer.tokenize();
}catch(...){
std::cerr << "Error Occurred!\n" << "Unknown Exception." << std::endl;
}
std::cout << tokenizer.string_list(false) << std::endl;
}
SHOW_INPUT_HINT();
std::getline(std::cin, input);
}
}