Sun, 12 Aug 2012 04:10:25 +0300
Added do-while loop support
main.cxx | file | annotate | diff | comparison | revisions | |
objwriter.h | file | annotate | diff | comparison | revisions | |
parser.cxx | file | annotate | diff | comparison | revisions | |
scriptreader.h | file | annotate | diff | comparison | revisions |
--- a/main.cxx Sun Aug 12 03:23:33 2012 +0300 +++ b/main.cxx Sun Aug 12 04:10:25 2012 +0300 @@ -57,6 +57,7 @@ #include "botcommands.h" const char* g_Keywords[] = { + "do", "event", "for", "goto", @@ -74,7 +75,6 @@ "case", "continue", "default", - "do", "else", "enum", // Would enum actually be useful? I think so. "func", // Would function support need external support from zandronum?
--- a/objwriter.h Sun Aug 12 03:23:33 2012 +0300 +++ b/objwriter.h Sun Aug 12 04:10:25 2012 +0300 @@ -72,6 +72,8 @@ void WriteBuffers (); void WriteStringTable (); void WriteToFile (); + void StartDo (); + void EndDo (); DataBuffer* GetCurrentBuffer (); unsigned int AddMark (int type, str name);
--- a/parser.cxx Sun Aug 12 03:23:33 2012 +0300 +++ b/parser.cxx Sun Aug 12 04:10:25 2012 +0300 @@ -323,6 +323,19 @@ } // ============================================================ + // Do/while loop + if (!token.icompare ("do")) { + MUST_NOT_TOPLEVEL + PushBlockStack (); + MustNext ("{"); + + // Store the marks and incrementor + blockstack[g_BlockStackCursor].mark1 = w->AddMark (MARKTYPE_INTERNAL, ""); + blockstack[g_BlockStackCursor].type = BLOCKTYPE_DO; + continue; + } + + // ============================================================ if (!token.compare ("}")) { // Closing brace @@ -345,6 +358,20 @@ // Move the closing mark here since we're at the end of the while loop w->MoveMark (info->mark2); + break; + case BLOCKTYPE_DO: + MustNext ("while"); + MustNext ("("); + MustNext (); + DataBuffer* expr = ParseExpression (TYPE_INT); + MustNext (")"); + MustNext (";"); + + // If the condition runs true, go back to the start. + w->WriteBuffer (expr); + w->Write<long> (DH_IFGOTO); + w->AddReference (info->mark1); + break; } // Descend down the stack @@ -613,7 +640,7 @@ // If nothing else, check for literal switch (reqtype) { case TYPE_VOID: - ParserError ("bad syntax"); + ParserError ("unknown identifier `%s` (expected keyword, function or variable)", token.chars()); break; case TYPE_INT: { MustNumber (true);