| 34 #include "Lexer.h" |
34 #include "Lexer.h" |
| 35 #include "DataBuffer.h" |
35 #include "DataBuffer.h" |
| 36 #include "Expression.h" |
36 #include "Expression.h" |
| 37 |
37 |
| 38 #define SCOPE(n) (m_scopeStack[m_scopeCursor - n]) |
38 #define SCOPE(n) (m_scopeStack[m_scopeCursor - n]) |
| |
39 |
| |
40 static const StringList g_validZandronumVersions = {"1.2", "1.3", "2.0"}; |
| 39 |
41 |
| 40 // ============================================================================ |
42 // ============================================================================ |
| 41 // |
43 // |
| 42 BotscriptParser::BotscriptParser() : |
44 BotscriptParser::BotscriptParser() : |
| 43 m_isReadOnly (false), |
45 m_isReadOnly (false), |
| 51 m_isStateSpawnDefined (false), |
53 m_isStateSpawnDefined (false), |
| 52 m_gotMainLoop (false), |
54 m_gotMainLoop (false), |
| 53 m_scopeCursor (-1), |
55 m_scopeCursor (-1), |
| 54 m_isElseAllowed (false), |
56 m_isElseAllowed (false), |
| 55 m_highestGlobalVarIndex (0), |
57 m_highestGlobalVarIndex (0), |
| 56 m_highestStateVarIndex (0) {} |
58 m_highestStateVarIndex (0), |
| |
59 m_zandronumVersion (10200), // 1.2 |
| |
60 m_defaultZandronumVersion (true) {} |
| 57 |
61 |
| 58 // ============================================================================ |
62 // ============================================================================ |
| 59 // |
63 // |
| 60 BotscriptParser::~BotscriptParser() |
64 BotscriptParser::~BotscriptParser() |
| 61 { |
65 { |
| 214 if (isReadOnly() == false) |
222 if (isReadOnly() == false) |
| 215 { |
223 { |
| 216 // stateSpawn must be defined! |
224 // stateSpawn must be defined! |
| 217 if (m_isStateSpawnDefined == false) |
225 if (m_isStateSpawnDefined == false) |
| 218 error ("script must have a state named `stateSpawn`!"); |
226 error ("script must have a state named `stateSpawn`!"); |
| |
227 |
| |
228 if (m_defaultZandronumVersion) |
| |
229 { |
| |
230 print ("\n"); |
| |
231 print ("note: use the 'using' directive to define a target Zandronum version\n"); |
| |
232 print ("usage: using zandronum <version>, possible versions: %1\n", g_validZandronumVersions); |
| |
233 print ("\n"); |
| |
234 } |
| 219 |
235 |
| 220 // Dump the last state's onenter and mainloop |
236 // Dump the last state's onenter and mainloop |
| 221 writeMemberBuffers(); |
237 writeMemberBuffers(); |
| 222 |
238 |
| 223 // String table |
239 // String table |
| 899 m_lexer->mustGetNext (TK_Semicolon); |
915 m_lexer->mustGetNext (TK_Semicolon); |
| 900 addCommandDefinition (comm); |
916 addCommandDefinition (comm); |
| 901 } |
917 } |
| 902 |
918 |
| 903 // ============================================================================ |
919 // ============================================================================ |
| |
920 // |
| |
921 // Parses a using statement |
| |
922 // |
| |
923 void BotscriptParser::parseUsing() |
| |
924 { |
| |
925 checkToplevel(); |
| |
926 m_lexer->mustGetSymbol ("zandronum"); |
| |
927 String versionText; |
| |
928 |
| |
929 while (m_lexer->next() && (m_lexer->tokenType() == TK_Number || m_lexer->tokenType() == TK_Dot)) |
| |
930 versionText += getTokenString(); |
| |
931 |
| |
932 // Note: at this point the lexer's pointing at the token after the version. |
| |
933 if (versionText.isEmpty()) |
| |
934 error ("expected version string, got `%1`", getTokenString()); |
| |
935 if (g_validZandronumVersions.contains (versionText) == false) |
| |
936 error ("unknown version string `%2`: valid versions: `%1`\n", g_validZandronumVersions, versionText); |
| |
937 |
| |
938 StringList versionTokens = versionText.split ("."); |
| |
939 m_zandronumVersion = versionTokens[0].toLong() * 10000 + versionTokens[1].toLong() * 100; |
| |
940 m_defaultZandronumVersion = false; |
| |
941 m_lexer->tokenMustBe (TK_Semicolon); |
| |
942 } |
| |
943 |
| |
944 // ============================================================================/ |
| |
945 // |
| 904 // Parses a command call |
946 // Parses a command call |
| |
947 // |
| 905 DataBuffer* BotscriptParser::parseCommand (CommandInfo* comm) |
948 DataBuffer* BotscriptParser::parseCommand (CommandInfo* comm) |
| 906 { |
949 { |
| 907 DataBuffer* r = new DataBuffer (64); |
950 DataBuffer* r = new DataBuffer (64); |
| 908 |
951 |
| 909 if (m_currentMode == PARSERMODE_TopLevel && comm->returnvalue == TYPE_Void) |
952 if (m_currentMode == PARSERMODE_TopLevel && comm->returnvalue == TYPE_Void) |