-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexpression.h
110 lines (100 loc) · 4.48 KB
/
expression.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef EXPRESSION_H
#define EXPRESSION_H
#pragma once
#include <vector>
#include <string>
#include <utility>
#include <cctype>
#include <cassert>
#include <iostream>
#include <sstream>
#include <memory>
#include "Parser.h"
#include "interpreter_errors.h"
namespace Battler {
enum class ExpressionType {
// EXPRESSION,
// OPERATAOR,
FACTOR,
ADDITION,
MULTIPLICATION,
DIVISION,
SUBTRACTION,
EQUALITY_TEST, // '=='
// FOREACH,
IDENTIFIER,
// NAME,
// LITERAL,
// GROUPING,
// BINARY,
ASSIGNMENT_TARGET,
ATTR_TYPE_SPECIFIER,
ATTR_NAME_DECLARATION,
ATTR_DECLARATION,
ATTR_ASSIGNMENT,
CARD_NAME_DECLARATION,
GAME_NAME_DECLARATION,
CARD_DECLARATION,
GAME_DECLARATION,
SETUP_DECLARATION,
FOREACHPLAYER_DECLARATION,
FOREACHPLAYER_IDENTIFIER_DECLARATION,
STACK_MOVE,
STACK_MOVE_UNDER,
STACK_MOVE_SOURCE,
STACK_MOVE_RANDOM_SOURCE,
STACK_MOVE_CHOOSE_SOURCE,
STACK_CUT_CHOOSE_SOURCE,
STACK_CUT_SOURCE,
STACK_CUT,
STACK_CUT_UNDER,
STACK_CUT_SOURCE_BOTTOM,
STACK_CUT_SOURCE_TOP,
STACK_SOURCE_BOTTOM,
STACK_SOURCE_TOP,
STACK_SOURCE_CHOOSE,
STACK_POSITION,
PHASE_DECLARATION,
ONPLACE_DECLARATION,
ONPLACE_STACK_DECLARATION,
ONPLACE_IDENTIFIER_DECLARATION,
IF_DECLARATION,
TURN_DECLARATION,
WINER_DECLARATION,
DO_DECLARATION,
PLAYERS_DECLARATION,
UNKNOWN,
};
using std::cout;
using std::endl;
class Expression {
public:
ExpressionType type;
std::vector<Token> tokens;
std::vector<Expression> children;
Expression() {}
Expression(ExpressionType type_in, std::vector<Token> tokens_in) : type( type_in ), tokens(tokens_in) {}
};
ExpressionType GetExpressionTypeFromOperatorTokenType(TokenType type);
std::vector<Token> GetIdentifierTokens(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
std::vector<Expression> GetBlock(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetGameDelcarationExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetAttrDeclarationExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetFactorExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetAssignmentExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end, std::vector<Token>::iterator& leftAccumulationStart);
Expression GetCardDeclarationExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetSetupExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetForEachPlayerExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetStackMoveSourceExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetStackMoveTargetExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetMoveExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end, std::vector<Token>::iterator& leftAccumulationStart, ExpressionType moveType);
Expression GetPhaseDeclarationExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetOnPlaceExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetIfExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetWinnerIsExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetTurnExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetDoExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetPlayersExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
Expression GetExpression(std::vector<Token>::iterator& current, const std::vector<Token>::iterator end);
}
#endif // !EXPRESSION_H