Wed, 12 Feb 2014 06:50:13 +0200
- extended refactor to EToken (now TokenType)
88 | 1 | /* |
2 | Copyright 2012-2014 Santeri Piippo | |
3 | All rights reserved. | |
4 | ||
5 | Redistribution and use in source and binary forms, with or without | |
6 | modification, are permitted provided that the following conditions | |
7 | are met: | |
8 | ||
9 | 1. Redistributions of source code must retain the above copyright | |
10 | notice, this list of conditions and the following disclaimer. | |
11 | 2. Redistributions in binary form must reproduce the above copyright | |
12 | notice, this list of conditions and the following disclaimer in the | |
13 | documentation and/or other materials provided with the distribution. | |
14 | 3. The name of the author may not be used to endorse or promote products | |
15 | derived from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #ifndef BOTC_PARSER_H | |
30 | #define BOTC_PARSER_H | |
31 | ||
32 | #include <stdio.h> | |
33 | #include "Main.h" | |
34 | #include "Commands.h" | |
35 | #include "LexerScanner.h" | |
36 | #include "Tokens.h" | |
37 | ||
38 | // TODO: get rid of this too? | |
39 | #define MAX_CASE 64 | |
40 | ||
41 | // TODO: get rid of this | |
42 | #define MAX_MARKS 512 | |
43 | ||
44 | class DataBuffer; | |
45 | class Lexer; | |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
46 | class Variable; |
88 | 47 | |
48 | // ============================================================================ | |
49 | // | |
50 | struct UndefinedLabel | |
51 | { | |
52 | String name; | |
53 | ByteMark* target; | |
54 | }; | |
55 | ||
56 | // ============================================================================ | |
57 | // Mark types | |
58 | // | |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
59 | named_enum MarkType |
88 | 60 | { |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
61 | MARK_Label, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
62 | MARK_If, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
63 | MARK_Internal, // internal structures |
88 | 64 | }; |
65 | ||
66 | // ============================================================================ | |
67 | // Scope types | |
68 | // | |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
69 | named_enum ScopeType |
88 | 70 | { |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
71 | SCOPE_Unknown, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
72 | SCOPE_If, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
73 | SCOPE_While, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
74 | SCOPE_For, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
75 | SCOPE_Do, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
76 | SCOPE_Switch, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
77 | SCOPE_Else, |
88 | 78 | }; |
79 | ||
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
80 | named_enum AssignmentOperator |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
81 | { |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
82 | ASSIGNOP_Assign, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
83 | ASSIGNOP_Add, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
84 | ASSIGNOP_Subtract, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
85 | ASSIGNOP_Multiply, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
86 | ASSIGNOP_Divide, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
87 | ASSIGNOP_Modulus, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
88 | ASSIGNOP_Increase, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
89 | ASSIGNOP_Decrease, |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
90 | }; |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
91 | |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
92 | named_enum Writability |
92
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
93 | { |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
94 | WRITE_Mutable, // normal read-many-write-many variable |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
95 | WRITE_Const, // write-once const variable |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
96 | WRITE_Constexpr, // const variable whose value is known to compiler |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
97 | }; |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
98 | |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
99 | // ============================================================================= |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
100 | // |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
101 | // Parser mode: where is the parser at? |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
102 | // |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
103 | named_enum ParserMode |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
104 | { |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
105 | PARSERMODE_TopLevel, // at top level |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
106 | PARSERMODE_Event, // inside event definition |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
107 | PARSERMODE_MainLoop, // inside mainloop |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
108 | PARSERMODE_Onenter, // inside onenter |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
109 | PARSERMODE_Onexit, // inside onexit |
92
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
110 | }; |
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
111 | |
88 | 112 | // ============================================================================ |
97
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
113 | // |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
114 | struct Variable |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
115 | { |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
116 | String name; |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
117 | String statename; |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
118 | DataType type; |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
119 | int index; |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
120 | Writability writelevel; |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
121 | int value; |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
122 | String origin; |
107
55c2bcd8ed5c
- implemented arrays, don't quite work 100% yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
106
diff
changeset
|
123 | bool isarray; |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
124 | |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
125 | inline bool IsGlobal() const |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
126 | { |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
127 | return statename.IsEmpty(); |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
128 | } |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
129 | }; |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
130 | |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
131 | // ============================================================================ |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
132 | // |
97
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
133 | struct CaseInfo |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
134 | { |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
135 | ByteMark* mark; |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
136 | int number; |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
137 | DataBuffer* data; |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
138 | }; |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
139 | |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
140 | // ============================================================================ |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
141 | // |
88 | 142 | // Meta-data about scopes |
143 | // | |
144 | struct ScopeInfo | |
145 | { | |
97
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
146 | ByteMark* mark1; |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
147 | ByteMark* mark2; |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
148 | ScopeType type; |
97
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
149 | DataBuffer* buffer1; |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
150 | int globalVarIndexBase; |
107
55c2bcd8ed5c
- implemented arrays, don't quite work 100% yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
106
diff
changeset
|
151 | int globalArrayIndexBase; |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
152 | int localVarIndexBase; |
88 | 153 | |
154 | // switch-related stuff | |
97
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
155 | List<CaseInfo>::Iterator casecursor; |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
156 | List<CaseInfo> cases; |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
157 | List<Variable*> localVariables; |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
158 | List<Variable*> globalVariables; |
107
55c2bcd8ed5c
- implemented arrays, don't quite work 100% yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
106
diff
changeset
|
159 | List<Variable*> globalArrays; |
88 | 160 | }; |
161 | ||
162 | // ============================================================================ | |
163 | // | |
164 | class BotscriptParser | |
165 | { | |
166 | PROPERTY (public, bool, ReadOnly, BOOL_OPS, STOCK_WRITE) | |
167 | ||
168 | public: | |
97
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
169 | enum EReset |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
170 | { |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
171 | eNoReset, |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
172 | SCOPE_Reset, |
97
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
173 | }; |
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
174 | |
88 | 175 | BotscriptParser(); |
176 | ~BotscriptParser(); | |
92
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
177 | void ParseBotscript (String fileName); |
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
178 | DataBuffer* ParseCommand (CommandInfo* comm); |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
179 | DataBuffer* ParseAssignment (Variable* var); |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
180 | AssignmentOperator ParseAssignmentOperator(); |
92
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
181 | String ParseFloat(); |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
182 | void PushScope (EReset reset = SCOPE_Reset); |
92
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
183 | DataBuffer* ParseStatement(); |
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
184 | void AddSwitchCase (DataBuffer* b); |
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
185 | void CheckToplevel(); |
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
186 | void CheckNotToplevel(); |
110
7a7a53f1d51b
- extended refactor to EToken (now TokenType)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
108
diff
changeset
|
187 | bool TokenIs (TokenType a); |
92
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
188 | String GetTokenString(); |
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
189 | String DescribePosition() const; |
3a00d396bce2
- now compiles again, further work on expressions (proper parsing + assignment operator handling (albeit unrelated) + operator adjusting)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
190 | void WriteToFile (String outfile); |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
191 | Variable* FindVariable (const String& name); |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
192 | bool IsInGlobalState() const; |
106
9174be9ac686
- improved error handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
105
diff
changeset
|
193 | void SuggestHighestVarIndex (bool global, int index); |
9174be9ac686
- improved error handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
105
diff
changeset
|
194 | int GetHighestVarIndex (bool global); |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
195 | |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
196 | inline ScopeInfo& GSCOPE_t (int offset) |
105
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
197 | { |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
198 | return mScopeStack[mScopeCursor - offset]; |
6dbac3305614
- highly reworked variable support, variable declarations now are declared with 'var', uses are prefixed with '$', merged constant handling into variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
199 | } |
88 | 200 | |
201 | inline int GetNumEvents() const | |
202 | { | |
203 | return mNumEvents; | |
204 | } | |
205 | ||
206 | inline int GetNumStates() const | |
207 | { | |
208 | return mNumStates; | |
209 | } | |
210 | ||
211 | private: | |
212 | // The main buffer - the contents of this is what we | |
213 | // write to file after parsing is complete | |
214 | DataBuffer* mMainBuffer; | |
215 | ||
216 | // onenter buffer - the contents of the onenter{} block | |
217 | // is buffered here and is merged further at the end of state | |
218 | DataBuffer* mOnEnterBuffer; | |
219 | ||
220 | // Mainloop buffer - the contents of the mainloop{} block | |
221 | // is buffered here and is merged further at the end of state | |
222 | DataBuffer* mMainLoopBuffer; | |
223 | ||
224 | // Switch buffer - switch case data is recorded to this | |
225 | // buffer initially, instead of into main buffer. | |
226 | DataBuffer* mSwitchBuffer; | |
227 | ||
228 | Lexer* mLexer; | |
229 | int mNumStates; | |
230 | int mNumEvents; | |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
231 | ParserMode mCurrentMode; |
88 | 232 | String mCurrentState; |
233 | bool mStateSpawnDefined; | |
234 | bool mGotMainLoop; | |
235 | int mScopeCursor; | |
236 | bool mCanElse; | |
237 | List<UndefinedLabel> mUndefinedLabels; | |
106
9174be9ac686
- improved error handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
105
diff
changeset
|
238 | int mHighestGlobalVarIndex; |
9174be9ac686
- improved error handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
105
diff
changeset
|
239 | int mHighestStateVarIndex; |
88 | 240 | |
241 | // How many bytes have we written to file? | |
242 | int mNumWrittenBytes; | |
243 | ||
244 | // Scope data | |
97
49e38433b9fd
- worked away some limitations
Teemu Piippo <crimsondusk64@gmail.com>
parents:
92
diff
changeset
|
245 | List<ScopeInfo> mScopeStack; |
88 | 246 | |
247 | DataBuffer* buffer(); | |
248 | void ParseStateBlock(); | |
249 | void ParseEventBlock(); | |
250 | void ParseMainloop(); | |
251 | void ParseOnEnterExit(); | |
101
9ffae10ef76f
- variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
252 | void ParseVar(); |
88 | 253 | void ParseGoto(); |
254 | void ParseIf(); | |
255 | void ParseElse(); | |
256 | void ParseWhileBlock(); | |
257 | void ParseForBlock(); | |
258 | void ParseDoBlock(); | |
259 | void ParseSwitchBlock(); | |
260 | void ParseSwitchCase(); | |
261 | void ParseSwitchDefault(); | |
262 | void ParseBreak(); | |
263 | void ParseContinue(); | |
264 | void ParseBlockEnd(); | |
265 | void ParseLabel(); | |
266 | void ParseEventdef(); | |
267 | void ParseFuncdef(); | |
268 | void writeMemberBuffers(); | |
269 | void WriteStringTable(); | |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
270 | DataBuffer* ParseExpression (DataType reqtype, bool fromhere = false); |
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
107
diff
changeset
|
271 | DataHeader GetAssigmentDataHeader (AssignmentOperator op, Variable* var); |
88 | 272 | }; |
273 | ||
274 | #endif // BOTC_PARSER_H |