-
Notifications
You must be signed in to change notification settings - Fork 0
/
CParser.h
50 lines (41 loc) · 1.1 KB
/
CParser.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
/*
* Kainoa Seto
* The Parser and interpreter for the code but since this class mainly holds Parser calls
* I named it after those. The custom stack defined below allows for data to be moved
* between the functions in an easier to understand way then passing by variables. However
* it may be more efficient to eventually implement variable passing and do away with the
* custom stack.
* 11-29-16
*/
#ifndef __CPARSER_H__
#define __CPARSER_H__
#include "pch.h"
#include "CScanner.h"
class CParser
{
public:
CParser(CScanner* scanner);
~CParser() {};
void Parse();
private:
void match(int expectedToken);
// Recursive grammar calls
void program();
void stmt_list();
void stmt();
void expr();
void term_tail();
void term();
void factor_tail();
void factor();
// Custom 'stack'
double stack[100];
int top;
void stackinit() { top = 0; }
double pop() { return stack[top--]; }
void push(double v) { stack[++top] = v; }
int token;
CScanner* scanner;
map<string, double> symbolTable;
};
#endif //__CPARSER_H__