-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparseRun.h
62 lines (50 loc) · 1.45 KB
/
parseRun.h
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
57
58
59
60
61
62
/*
* parse.h
*/
#ifndef PARSE_H_
#define PARSE_H_
#include <iostream>
#include <map>
using namespace std;
#include "lex.h"
//using std::map;
map<string, bool> defVar;
namespace Parser {
bool pushed_back = false;
LexItem pushed_token;
static LexItem GetNextToken(istream& in, int& line) {
if( pushed_back ) {
pushed_back = false;
//cout<< "returned token: " << pushed_token.GetLexeme() << endl;
return pushed_token;
}
return getNextToken(in, line);
}
static void PushBackToken(LexItem & t) {
if( pushed_back ) {
//cout<< "Pushed token abort: " << t.GetLexeme() << endl;
abort();
}
pushed_back = true;
pushed_token = t;
//cout<< "Pushed token: " << t.GetLexeme() << endl;
}
}
static int error_count = 0;
void ParseError(int line, string msg)
{
++error_count;
cout << line << ": " << msg << endl;
}
extern bool Prog(istream& in, int& line);
extern bool StmtList(istream& in, int& line);
extern bool Stmt(istream& in, int& line);
extern bool PrintStmt(istream& in, int& line);
extern bool IfStmt(istream& in, int& line);
extern bool Var(istream& in, int& line, LexItem & tok);
extern bool AssignStmt(istream& in, int& line);
extern bool ExprList(istream& in, int& line);
extern bool Expr(istream& in, int& line, Value & retVal);
extern bool Term(istream& in, int& line, Value & retVal);
extern bool Factor(istream& in, int& line, Value & retVal);
#endif /* PARSE_H_ */