65 str g_CurState = ""; |
65 str g_CurState = ""; |
66 bool g_stateSpawnDefined = false; |
66 bool g_stateSpawnDefined = false; |
67 bool g_GotMainLoop = false; |
67 bool g_GotMainLoop = false; |
68 unsigned int g_BlockStackCursor = 0; |
68 unsigned int g_BlockStackCursor = 0; |
69 DataBuffer* g_IfExpression = NULL; |
69 DataBuffer* g_IfExpression = NULL; |
|
70 bool g_CanElse = false; |
70 |
71 |
71 // ============================================================================ |
72 // ============================================================================ |
72 // Main parser code. Begins read of the script file, checks the syntax of it |
73 // Main parser code. Begins read of the script file, checks the syntax of it |
73 // and writes the data to the object file via ObjWriter - which also takes care |
74 // and writes the data to the object file via ObjWriter - which also takes care |
74 // of necessary buffering so stuff is written in the correct order. |
75 // of necessary buffering so stuff is written in the correct order. |
76 // Zero the entire block stack first |
77 // Zero the entire block stack first |
77 for (int i = 0; i < MAX_STRUCTSTACK; i++) |
78 for (int i = 0; i < MAX_STRUCTSTACK; i++) |
78 memset (&blockstack[i], 0, sizeof (BlockInformation)); |
79 memset (&blockstack[i], 0, sizeof (BlockInformation)); |
79 |
80 |
80 while (Next()) { |
81 while (Next()) { |
|
82 // Check if else is potentically valid |
|
83 if (!token.compare ("else") && !g_CanElse) |
|
84 ParserError ("else without preceding if"); |
|
85 if (token.compare ("else") != 0) |
|
86 g_CanElse = false; |
|
87 |
81 // ============================================================ |
88 // ============================================================ |
82 if (!token.compare ("state")) { |
89 if (!token.compare ("state")) { |
83 MUST_TOPLEVEL |
90 MUST_TOPLEVEL |
84 |
91 |
85 MustString (); |
92 MustString (); |
486 if (g_BlockStackCursor > 0) { |
493 if (g_BlockStackCursor > 0) { |
487 switch (SCOPE(0).type) { |
494 switch (SCOPE(0).type) { |
488 case BLOCKTYPE_IF: |
495 case BLOCKTYPE_IF: |
489 // Adjust the closing mark. |
496 // Adjust the closing mark. |
490 w->MoveMark (SCOPE(0).mark1); |
497 w->MoveMark (SCOPE(0).mark1); |
|
498 |
|
499 // We're returning from if, thus else can be next |
|
500 g_CanElse = true; |
491 break; |
501 break; |
492 case BLOCKTYPE_ELSE: |
502 case BLOCKTYPE_ELSE: |
493 // else instead uses mark1 for itself (so if expression |
503 // else instead uses mark1 for itself (so if expression |
494 // fails, jump to else), mark2 means end of else |
504 // fails, jump to else), mark2 means end of else |
495 w->MoveMark (SCOPE(0).mark2); |
505 w->MoveMark (SCOPE(0).mark2); |