main.cxx

changeset 42
5cd91fd1526c
parent 41
47e686c96d8f
child 43
1b35c9985989
equal deleted inserted replaced
41:47e686c96d8f 42:5cd91fd1526c
54 #include "variables.h" 54 #include "variables.h"
55 55
56 #include "bots.h" 56 #include "bots.h"
57 #include "botcommands.h" 57 #include "botcommands.h"
58 58
59 const char* g_Keywords[NUM_KEYWORDS] = { 59 const char* g_Keywords[] = {
60 "state", 60 "state",
61 "event", 61 "event",
62 "mainloop", 62 "mainloop",
63 "onenter", 63 "onenter",
64 "onexit", 64 "onexit",
65 "var", 65 "var",
66 "goto", 66 "goto",
67 "if", 67 "if",
68 "while",
68 69
69 // These ones aren't implemented yet but I plan to do so, thus they are 70 // These ones aren't implemented yet but I plan to do so, thus they are
70 // reserved. Also serves as a to-do list of sorts for me. >:F 71 // reserved. Also serves as a to-do list of sorts for me. >:F
71 "break", 72 "break",
72 "case", 73 "case",
77 "enum", // Would enum actually be useful? I think so. 78 "enum", // Would enum actually be useful? I think so.
78 "for", 79 "for",
79 "func", // Would function support need external support from zandronum? 80 "func", // Would function support need external support from zandronum?
80 "return", 81 "return",
81 "switch", 82 "switch",
82 "while"
83 }; 83 };
84 84
85 int main (int argc, char** argv) { 85 int main (int argc, char** argv) {
86 // Intepret command-line parameters: 86 // Intepret command-line parameters:
87 // -l: list commands 87 // -l: list commands
114 } 114 }
115 115
116 // A word should always be exactly 4 bytes. The above list command 116 // A word should always be exactly 4 bytes. The above list command
117 // doesn't need it, but the rest of the program does. 117 // doesn't need it, but the rest of the program does.
118 if (sizeof (word) != 4) 118 if (sizeof (word) != 4)
119 error ("%s expects a word (unsigned long int) to be 4 bytes in size, is %d\n", 119 error ("%s expects a word (uint32_t) to be 4 bytes in size, is %d\n",
120 APPNAME, sizeof (word)); 120 APPNAME, sizeof (word));
121 121
122 str outfile; 122 str outfile;
123 if (argc < 3) 123 if (argc < 3)
124 outfile = ObjectFileName (argv[1]); 124 outfile = ObjectFileName (argv[1]);
216 } 216 }
217 217
218 // ============================================================================ 218 // ============================================================================
219 // Is the given argument a reserved keyword? 219 // Is the given argument a reserved keyword?
220 bool IsKeyword (str s) { 220 bool IsKeyword (str s) {
221 for (unsigned int u = 0; u < NUM_KEYWORDS; u++) 221 for (unsigned int u = 0; u < NumKeywords (); u++)
222 if (!s.icompare (g_Keywords[u])) 222 if (!s.icompare (g_Keywords[u]))
223 return true; 223 return true;
224 return false; 224 return false;
225 } 225 }
226
227 unsigned int NumKeywords () {
228 return sizeof (g_Keywords) / sizeof (const char*);
229 }

mercurial