scriptreader.h

Wed, 19 Dec 2012 13:44:18 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 19 Dec 2012 13:44:18 +0200
changeset 68
588cc27e84bb
parent 66
4fc1ec88aa41
permissions
-rw-r--r--

Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.

0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * botc source code
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012 Santeri `Dusk` Piippo
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 * All rights reserved.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 *
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 *
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright notice,
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * this list of conditions and the following disclaimer.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * this list of conditions and the following disclaimer in the documentation
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * and/or other materials provided with the distribution.
3
08cab2b67dce oh blerb.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
14 * 3. Neither the name of the developer nor the names of its contributors may
08cab2b67dce oh blerb.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
15 * be used to endorse or promote products derived from this software without
08cab2b67dce oh blerb.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
16 * specific prior written permission.
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 * 4. Redistributions in any form must be accompanied by information on how to
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 * obtain complete source code for the software and any accompanying
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 * software that uses the software. The source code must either be included
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 * in the distribution or be available for no more than the cost of
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 * distribution plus a nominal fee, and must be freely redistributable
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 * under reasonable conditions. For an executable file, complete source
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 * code means the source code for all modules it contains. It does not
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 * include source code for modules or files that typically accompany the
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 * major components of the operating system on which the executable file
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 * runs.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 *
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 * POSSIBILITY OF SUCH DAMAGE.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 */
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 #ifndef __SCRIPTREADER_H__
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 #define __SCRIPTREADER_H__
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 #include <stdio.h>
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 #include "str.h"
68
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
46 #include "commands.h"
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 #include "objwriter.h"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48
33
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
49 #define MAX_FILESTACK 8
59
891b9e6ee139 Added support for continue-statements
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
50 #define MAX_SCOPE 32
48
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
51 #define MAX_CASE 64
33
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
52
36
a8838b5f1213 Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 35
diff changeset
53 class ScriptVar;
a8838b5f1213 Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 35
diff changeset
54
66
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
55 // Operators
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
56 enum operator_e {
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
57 OPER_ADD,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
58 OPER_SUBTRACT,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
59 OPER_MULTIPLY,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
60 OPER_DIVIDE,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
61 OPER_MODULUS,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
62 OPER_ASSIGN,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
63 OPER_ASSIGNADD,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
64 OPER_ASSIGNSUB,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
65 OPER_ASSIGNMUL,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
66 OPER_ASSIGNDIV,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
67 OPER_ASSIGNMOD, // -- 10
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
68 OPER_EQUALS,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
69 OPER_NOTEQUALS,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
70 OPER_LESSTHAN,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
71 OPER_GREATERTHAN,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
72 OPER_LESSTHANEQUALS,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
73 OPER_GREATERTHANEQUALS,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
74 OPER_LEFTSHIFT,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
75 OPER_RIGHTSHIFT,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
76 OPER_ASSIGNLEFTSHIFT,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
77 OPER_ASSIGNRIGHTSHIFT, // -- 20
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
78 OPER_OR,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
79 OPER_AND,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
80 OPER_BITWISEOR,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
81 OPER_BITWISEAND,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
82 OPER_BITWISEEOR,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
83 OPER_TERNARY,
68
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
84 OPER_STRLEN,
66
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
85 };
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
86
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
87 // Mark types
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
88 enum marktype_e {
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
89 MARKTYPE_LABEL,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
90 MARKTYPE_IF,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
91 MARKTYPE_INTERNAL, // internal structures
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
92 };
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
93
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
94 // Block types
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
95 enum scopetype_e {
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
96 SCOPETYPE_UNKNOWN,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
97 SCOPETYPE_IF,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
98 SCOPETYPE_WHILE,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
99 SCOPETYPE_FOR,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
100 SCOPETYPE_DO,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
101 SCOPETYPE_SWITCH,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
102 SCOPETYPE_ELSE,
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
103 };
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
104
41
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
105 // ============================================================================
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
106 // Meta-data about blocks
59
891b9e6ee139 Added support for continue-statements
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
107 struct ScopeInfo {
41
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
108 unsigned int mark1;
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
109 unsigned int mark2;
66
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
110 scopetype_e type;
43
1b35c9985989 Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
111 DataBuffer* buffer1;
48
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
112
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
113 // switch-related stuff
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
114 // Which case are we at?
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
115 short casecursor;
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
116
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
117 // Marks to case-blocks
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
118 int casemarks[MAX_CASE];
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
119
50
2e333a3ca49a Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
120 // Numbers of the case labels
2e333a3ca49a Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
121 int casenumbers[MAX_CASE];
2e333a3ca49a Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
122
48
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
123 // actual case blocks
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
124 DataBuffer* casebuffers[MAX_CASE];
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
125
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
126 // What is the current buffer of the block?
976c57f153b3 Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents: 44
diff changeset
127 DataBuffer* recordbuffer;
41
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
128 };
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
129
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
130 // ============================================================================
68
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
131 typedef struct {
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
132 str name;
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
133 type_e type;
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
134 str val;
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
135 } constinfo_t;
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
136
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
137 // ============================================================================
41
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
138 // The script reader reads the script, parses it and tells the object writer
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
139 // the bytecode it needs to write to file.
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 class ScriptReader {
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 public:
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
142 // ====================================================================
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
143 // MEMBERS
33
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
144 FILE* fp[MAX_FILESTACK];
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
145 char* filepath[MAX_FILESTACK];
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
146 int fc;
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
147
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
148 unsigned int pos[MAX_FILESTACK];
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
149 unsigned int curline[MAX_FILESTACK];
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
150 unsigned int curchar[MAX_FILESTACK];
59
891b9e6ee139 Added support for continue-statements
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
151 ScopeInfo scopestack[MAX_SCOPE];
33
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
152 long savedpos[MAX_FILESTACK]; // filepointer cursor position
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 str token;
28
fb46d3d40064 Added comment support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
154 int commentmode;
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
155 long prevpos;
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
156 str prevtoken;
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
158 // ====================================================================
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
159 // METHODS
9
d279af9afd6d Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
160 // scriptreader.cxx:
7
118d3d5db64f Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents: 3
diff changeset
161 ScriptReader (str path);
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
162 ~ScriptReader ();
33
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
163 void OpenFile (str path);
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
164 void CloseFile (unsigned int u = MAX_FILESTACK);
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 char ReadChar ();
28
fb46d3d40064 Added comment support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
166 char PeekChar (int offset = 0);
33
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
167 bool Next (bool peek = false);
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
168 void Prev ();
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
169 str PeekNext (int offset = 0);
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 void Seek (unsigned int n, int origin);
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 void MustNext (const char* c = "");
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
172 void MustThis (const char* c);
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
173 void MustString (bool gotquote = false);
35
3d3f6ed40171 Negative literal integers work properly now..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
174 void MustNumber (bool fromthis = false);
10
2c0f76090372 Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
175 void MustBool ();
20
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
176 bool BoolValue ();
10
2c0f76090372 Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
177
7
118d3d5db64f Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents: 3
diff changeset
178 void ParserError (const char* message, ...);
118d3d5db64f Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents: 3
diff changeset
179 void ParserWarning (const char* message, ...);
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180
9
d279af9afd6d Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
181 // parser.cxx:
50
2e333a3ca49a Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
182 void ParseBotScript (ObjWriter* w);
34
0a9a5902beaa Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
183 DataBuffer* ParseCommand (CommandDef* comm);
68
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
184 DataBuffer* ParseExpression (type_e reqtype);
36
a8838b5f1213 Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 35
diff changeset
185 DataBuffer* ParseAssignment (ScriptVar* var);
a8838b5f1213 Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 35
diff changeset
186 int ParseOperator (bool peek = false);
68
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
187 DataBuffer* ParseExprValue (type_e reqtype);
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
188 str ParseFloat ();
58
bc9317d1b9c9 Renamed 'block stack' to scope stack for more clarified code..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 56
diff changeset
189 void PushScope ();
10
2c0f76090372 Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
190
33
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
191 // preprocessor.cxx:
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
192 void PreprocessDirectives ();
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
193 void PreprocessMacros ();
43
1b35c9985989 Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 41
diff changeset
194 DataBuffer* ParseStatement (ObjWriter* w);
50
2e333a3ca49a Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
195 void AddSwitchCase (ObjWriter* w, DataBuffer* b);
33
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
196
10
2c0f76090372 Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
197 private:
11
f08abacb46c9 Removed extdelimeters member, said delimeters are always enabled now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
198 bool atnewline;
10
2c0f76090372 Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
199 char c;
2c0f76090372 Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
200 void ParserMessage (const char* header, char* message);
33
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
201
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
202 bool DoDirectivePreprocessing ();
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
203 char PPReadChar ();
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
204 void PPMustChar (char c);
fd35f6cb5f28 Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 28
diff changeset
205 str PPReadWord (char &term);
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 };
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207
68
588cc27e84bb Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 66
diff changeset
208 constinfo_t* FindConstant (str token);
66
4fc1ec88aa41 Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 65
diff changeset
209 extern bool g_Neurosphere;
41
47e686c96d8f Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
210
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 #endif // __SCRIPTREADER_H__

mercurial