src/parser.h

Mon, 21 Jul 2014 17:14:42 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 21 Jul 2014 17:14:42 +0300
changeset 135
8b9132fea327
parent 134
eca2fc0acaa2
child 138
a426c1039655
permissions
-rw-r--r--

- massive refactoring continues (doesn't compile yet)

119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
133
dbbdb870c835 - changed all source files to use my correct legal name instead of my calling name
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
2 Copyright 2012-2014 Teemu Piippo
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 are met:
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 1. Redistributions of source code must retain the above copyright
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 3. The name of the author may not be used to endorse or promote products
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 derived from this software without specific prior written permission.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 */
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #ifndef BOTC_PARSER_H
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #define BOTC_PARSER_H
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include <stdio.h>
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 #include "main.h"
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 #include "commands.h"
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 #include "lexerScanner.h"
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 #include "tokens.h"
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 class DataBuffer;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 class Lexer;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 class Variable;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 // ============================================================================
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 // Mark types
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 //
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
45 named_enum MarkType : char
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 MARK_Label,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 MARK_If,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 MARK_Internal, // internal structures
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 // ============================================================================
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 // Scope types
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 //
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
55 named_enum ScopeType : char
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 SCOPE_Unknown,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 SCOPE_If,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 SCOPE_While,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 SCOPE_For,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 SCOPE_Do,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 SCOPE_Switch,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 SCOPE_Else,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
66 named_enum AssignmentOperator : char
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 ASSIGNOP_Assign,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 ASSIGNOP_Add,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 ASSIGNOP_Subtract,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 ASSIGNOP_Multiply,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 ASSIGNOP_Divide,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 ASSIGNOP_Modulus,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 ASSIGNOP_Increase,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 ASSIGNOP_Decrease,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
78 named_enum Writability : char
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 WRITE_Mutable, // normal read-many-write-many variable
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 WRITE_Const, // write-once const variable
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 WRITE_Constexpr, // const variable whose value is known to compiler
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 // =============================================================================
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 // Parser mode: where is the parser at?
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 //
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
89 named_enum class ParserMode
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 {
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
91 TopLevel, // at top level
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
92 Event, // inside event definition
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
93 MainLoop, // inside mainloop
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
94 Onenter, // inside onenter
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
95 Onexit, // inside onexit
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 // ============================================================================
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 struct Variable
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 String name;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 String statename;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 DataType type;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 int index;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 Writability writelevel;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 int value;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 String origin;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 bool isarray;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
111 inline bool isGlobal() const
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 return statename.isEmpty();
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 // ============================================================================
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 struct CaseInfo
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 ByteMark* mark;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 int number;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 DataBuffer* data;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 // ============================================================================
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 // Meta-data about scopes
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 struct ScopeInfo
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 ByteMark* mark1;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 ByteMark* mark2;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 ScopeType type;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 DataBuffer* buffer1;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 int globalVarIndexBase;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 int globalArrayIndexBase;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 int localVarIndexBase;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 // switch-related stuff
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 List<CaseInfo>::Iterator casecursor;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 List<CaseInfo> cases;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 List<Variable*> localVariables;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 List<Variable*> globalVariables;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 List<Variable*> globalArrays;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 // ============================================================================
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 class BotscriptParser
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 PROPERTY (public, bool, isReadOnly, setReadOnly, STOCK_WRITE)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
154 public:
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
155 BotscriptParser();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
156 ~BotscriptParser();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
157 void parseBotscript (String fileName);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
158 DataBuffer* parseCommand (CommandInfo* comm);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
159 DataBuffer* parseAssignment (Variable* var);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
160 AssignmentOperator parseAssignmentOperator();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
161 String parseFloat();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
162 void pushScope (bool noreset = false);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
163 DataBuffer* parseStatement();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
164 void addSwitchCase (DataBuffer* b);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
165 void checkToplevel();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
166 void checkNotToplevel();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
167 bool tokenIs (Token a);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
168 String getTokenString();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
169 String describePosition() const;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
170 void writeToFile (String outfile);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
171 Variable* findVariable (const String& name);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
172 bool isInGlobalState() const;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
173 void suggestHighestVarIndex (bool global, int index);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
174 int getHighestVarIndex (bool global);
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
176 inline ScopeInfo& scope (int offset)
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
177 {
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
178 return m_scopeStack[m_scopeCursor - offset];
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
179 }
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
180
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
181 inline int numEvents() const
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
182 {
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
183 return m_numEvents;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
184 }
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
186 inline int numStates() const
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
187 {
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
188 return m_numStates;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
189 }
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
191 private:
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
192 // The main buffer - the contents of this is what we
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
193 // write to file after parsing is complete
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
194 DataBuffer* m_mainBuffer;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
196 // onenter buffer - the contents of the onenter {} block
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
197 // is buffered here and is merged further at the end of state
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
198 DataBuffer* m_onenterBuffer;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
200 // Mainloop buffer - the contents of the mainloop {} block
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
201 // is buffered here and is merged further at the end of state
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
202 DataBuffer* m_mainLoopBuffer;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
203
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
204 // Switch buffer - switch case data is recorded to this
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
205 // buffer initially, instead of into main buffer.
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
206 DataBuffer* m_switchBuffer;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
208 Lexer* m_lexer;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
209 int m_numStates;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
210 int m_numEvents;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
211 ParserMode m_currentMode;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
212 String m_currentState;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
213 bool m_isStateSpawnDefined;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
214 bool m_gotMainLoop;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
215 int m_scopeCursor;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
216 bool m_isElseAllowed;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
217 int m_highestGlobalVarIndex;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
218 int m_highestStateVarIndex;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
219 int m_numWrittenBytes;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
220 List<ScopeInfo> m_scopeStack;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
221 int m_zandronumVersion;
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
222 bool m_defaultZandronumVersion;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
224 DataBuffer* currentBuffer();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
225 void parseStateBlock();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
226 void parseEventBlock();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
227 void parseMainloop();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
228 void parseOnEnterExit();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
229 void parseVar();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
230 void parseGoto();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
231 void parseIf();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
232 void parseElse();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
233 void parseWhileBlock();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
234 void parseForBlock();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
235 void parseDoBlock();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
236 void parseSwitchBlock();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
237 void parseSwitchCase();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
238 void parseSwitchDefault();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
239 void parseBreak();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
240 void parseContinue();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
241 void parseBlockEnd();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
242 void parseLabel();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
243 void parseEventdef();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
244 void parseFuncdef();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
245 void parseUsing();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
246 void writeMemberBuffers();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
247 void writeStringTable();
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
248 DataBuffer* parseExpression (DataType reqtype, bool fromhere = false);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
249 DataHeader getAssigmentDataHeader (AssignmentOperator op, Variable* var);
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 #endif // BOTC_PARSER_H

mercurial