-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyntaxAnalyzer.h
More file actions
103 lines (66 loc) · 3.19 KB
/
SyntaxAnalyzer.h
File metadata and controls
103 lines (66 loc) · 3.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
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
//
// Created by root on 10/31/17.
//
#ifndef DYNAMIC_SYSTEMS_DSL_TRANSLATOR_SYNTAXANALYZER_H
#define DYNAMIC_SYSTEMS_DSL_TRANSLATOR_SYNTAXANALYZER_H
#include <iostream>
#include <utility>
#include <list>
#include <map>
#include "CheckingResult.h"
#include "VariablesContainer.h"
#include "Type.h"
using namespace std;
class SyntaxAnalyzer {
public:
struct Method {
string name;
list<Type> arguments;
Type returnType = Type::VOID;
Method(const string &name, const list<Type> &arguments, Type returnType);
Method();
};
private:
enum State { START, ERROR, FINAL, A, B, C, D, E, F, G };
const list<string> RESERVED_IDENTIFIERS = { "dx", "dy", "dz", "x", "y", "z", "x0", "y0", "z0", "t", "t0", "T" };
const list<string> MATH_FUNCTIONS = { "sin", "cos", "tan", "asin", "acos", "atan", "log", "log10", "sqrt", "cbrt" };
const list<string> METHOD_NAMES = { "eulers", "rungekutta", "print", "println" };
const list<string> MATH_OPERATIONS = { "+", "-", "*", "/", "^" };
const list<string> MATH_CONSTS = { "e" };
list<Method> methods;
VariablesContainer identifiers;
public:
static const char ASSIGNMENT_OPERATOR = '=';
static const char COMMENT_CHAR = '#';
SyntaxAnalyzer();
VariablesContainer &getIdentifiers();
void setIdentifiers(const VariablesContainer &identifiers);
CheckingResult isSign(const string &text, int startingPosition);
CheckingResult isAssignment(const string &text, int startingPosition);
CheckingResult isIdentifier(const string &text, int startingPosition);
CheckingResult isExistingVariable(const string &text, int startingPosition, Type type);
CheckingResult isNumericConstWithSign(const string &text, int startingPosition);
CheckingResult isNumericConst(const string &text, int startingPosition);
CheckingResult isMathFunction(const string &text, int startingPosition);
CheckingResult isMethodName(const string &text, int startingPosition);
CheckingResult isMethodReturningType(const string &text, int startingPosition, Type returnType);
CheckingResult isMethodCall(const string &text, int startingPosition, const Method &method);
CheckingResult isMathOperation(const string &text, int startingPosition);
CheckingResult isMathConst(const string &text, int startingPosition);
CheckingResult isOperand(const string &text, int startingPosition);
CheckingResult isExpression(const string &text, int startingPosition);
CheckingResult isStringExpression(const string &text, int startingPosition);
CheckingResult isFirstDerivativeX(const string &text, int startingPosition);
CheckingResult isFirstDerivativeY(const string &text, int startingPosition);
CheckingResult isFirstDerivativeZ(const string &text, int startingPosition);
CheckingResult isNumIntegrationCall(const string &text, int startingPosition);
/*
* TODO: Support overrided methods
* Recognize method by name in the specified code line @text
* Recognizing of overrided methods is not supported!
*
* Returns NULL if method is not recognized
*/
Method recognizeMethod(const string &text);
};
#endif //DYNAMIC_SYSTEMS_DSL_TRANSLATOR_SYNTAXANALYZER_H