+/EE312

software design

git clone https://git.julia.blue/+/EE312

Joseph RyanAdd functions to blip5dbb718

master
1.1 KiB57 linesraw
1#ifndef PARSE_H
2#define PARSE_H
3#include "lex.h"
4#include <map>
5#include <vector>
6
7class Statement;
8
9struct Scope {
10    std::map<std::string, int> vars;
11    std::map<std::string, Statement*> funcs;
12    Scope* outer;
13    Scope(Scope* s) { outer = s; }
14};
15
16class Expression {
17    Token tok;
18    Expression *lhs, *rhs;
19
20public:
21    Expression();
22    Expression(Token); // Doesn't parse input
23    ~Expression();
24    int evaluate();
25    void debugPrint();
26};
27
28enum StatementType { TEXT = 0, OUTPUT, VAR, SET, IF, DO, FUNC, RETURN };
29
30class Statement {
31    StatementType type;
32    Token tok;
33    Expression* exp;
34    std::vector<Statement*> elseContents;
35    void parseText();
36    void parseOutput();
37    void parseVar();
38    void parseSet();
39    void parseDo();
40    void parseIf();
41    void parseFunc();
42    void parseReturn();
43
44public:
45    // These could be private if it weren't for the disgusting hack that is
46    // function calls
47    Scope* local;
48    std::vector<Token> args;
49    std::vector<Statement*> contents;
50
51    Statement();
52    ~Statement();
53    void execute();
54    void debugPrint();
55};
56
57#endif