Sun, 09 Feb 2014 04:13:15 +0200
- loop structures now work again
src/LexerScanner.cc | file | annotate | diff | comparison | revisions | |
src/Parser.cc | file | annotate | diff | comparison | revisions | |
src/Parser.h | file | annotate | diff | comparison | revisions | |
src/Tokens.h | file | annotate | diff | comparison | revisions |
--- a/src/LexerScanner.cc Tue Feb 04 22:00:43 2014 +0200 +++ b/src/LexerScanner.cc Sun Feb 09 04:13:15 2014 +0200 @@ -52,6 +52,8 @@ "<=", "&&", "||", + "++", + "--", "'", "$", "(",
--- a/src/Parser.cc Tue Feb 04 22:00:43 2014 +0200 +++ b/src/Parser.cc Sun Feb 09 04:13:15 2014 +0200 @@ -1077,7 +1077,9 @@ tkSubAssign, tkMultiplyAssign, tkDivideAssign, - tkModulusAssign + tkModulusAssign, + tkDoublePlus, + tkDoubleMinus, }; mLexer->MustGetAnyOf (tokens); @@ -1090,6 +1092,8 @@ case tkMultiplyAssign: return EAssignMul; case tkDivideAssign: return EAssignDiv; case tkModulusAssign: return EAssignMod; + case tkDoublePlus: return EAssignIncrement; + case tkDoubleMinus: return EAssignDecrement; default: break; } @@ -1105,23 +1109,27 @@ { switch (op) { - case EAssign: return dhAssignGlobalVar; - case EAssignAdd: return dhAddGlobalVar; - case EAssignSub: return dhSubtractGlobalVar; - case EAssignMul: return dhMultiplyGlobalVar; - case EAssignDiv: return dhDivideGlobalVar; - case EAssignMod: return dhModGlobalVar; + case EAssign: return dhAssignGlobalVar; + case EAssignAdd: return dhAddGlobalVar; + case EAssignSub: return dhSubtractGlobalVar; + case EAssignMul: return dhMultiplyGlobalVar; + case EAssignDiv: return dhDivideGlobalVar; + case EAssignMod: return dhModGlobalVar; + case EAssignIncrement: return dhIncreaseGlobalVar; + case EAssignDecrement: return dhDecreaseGlobalVar; } } switch (op) { - case EAssign: return dhAssignLocalVar; - case EAssignAdd: return dhAddLocalVar; - case EAssignSub: return dhSubtractLocalVar; - case EAssignMul: return dhMultiplyLocalVar; - case EAssignDiv: return dhDivideLocalVar; - case EAssignMod: return dhModLocalVar; + case EAssign: return dhAssignLocalVar; + case EAssignAdd: return dhAddLocalVar; + case EAssignSub: return dhSubtractLocalVar; + case EAssignMul: return dhMultiplyLocalVar; + case EAssignDiv: return dhDivideLocalVar; + case EAssignMod: return dhModLocalVar; + case EAssignIncrement: return dhIncreaseLocalVar; + case EAssignDecrement: return dhDecreaseLocalVar; } assert (false); @@ -1138,38 +1146,33 @@ { // Get an operator EAssignmentOperator oper = ParseAssignmentOperator(); + DataBuffer* retbuf = new DataBuffer; if (mCurrentMode == ETopLevelMode) Error ("can't alter variables at top level"); // Parse the right operand - DataBuffer* retbuf = new DataBuffer; - DataBuffer* expr = ParseExpression (var->type); + if (oper != EAssignIncrement && oper != EAssignDecrement) + { + DataBuffer* expr = ParseExpression (var->type); + retbuf->MergeAndDestroy (expr); + } #if 0 // <<= and >>= do not have data headers. Solution: expand them. // a <<= b -> a = a << b // a >>= b -> a = a >> b - if (oper == OPER_ASSIGNLEFTSHIFT || oper == OPER_ASSIGNRIGHTSHIFT) - { - retbuf->WriteDWord (var->IsGlobal() ? dhPushGlobalVar : dhPushLocalVar); - retbuf->WriteDWord (var->index); - retbuf->MergeAndDestroy (expr); - retbuf->WriteDWord ((oper == OPER_ASSIGNLEFTSHIFT) ? dhLeftShift : dhRightShift); - retbuf->WriteDWord (var->IsGlobal() ? dhAssignGlobalVar : dhAssignLocalVar); - retbuf->WriteDWord (var->index); - } - else - { -#endif - retbuf->MergeAndDestroy (expr); - EDataHeader dh = GetAssigmentDataHeader (oper, var); - retbuf->WriteDWord (dh); - retbuf->WriteDWord (var->index); -#if 0 - } + retbuf->WriteDWord (var->IsGlobal() ? dhPushGlobalVar : dhPushLocalVar); + retbuf->WriteDWord (var->index); + retbuf->MergeAndDestroy (expr); + retbuf->WriteDWord ((oper == OPER_ASSIGNLEFTSHIFT) ? dhLeftShift : dhRightShift); + retbuf->WriteDWord (var->IsGlobal() ? dhAssignGlobalVar : dhAssignLocalVar); + retbuf->WriteDWord (var->index); #endif + EDataHeader dh = GetAssigmentDataHeader (oper, var); + retbuf->WriteDWord (dh); + retbuf->WriteDWord (var->index); return retbuf; } @@ -1367,7 +1370,7 @@ for (int i = 0; i < 4; ++i) mMainBuffer->GetBuffer()[ref->pos + i] = (ref->target->pos >> (8 * i)) & 0xFF; - Print ("reference at %1 resolved to mark at %2\n", ref->pos, ref->target->pos); + // Print ("reference at %1 resolved to mark at %2\n", ref->pos, ref->target->pos); } // Then, dump the main buffer to the file
--- a/src/Parser.h Tue Feb 04 22:00:43 2014 +0200 +++ b/src/Parser.h Sun Feb 09 04:13:15 2014 +0200 @@ -85,6 +85,8 @@ EAssignMul, EAssignDiv, EAssignMod, + EAssignIncrement, + EAssignDecrement, }; // ============================================================================
--- a/src/Tokens.h Tue Feb 04 22:00:43 2014 +0200 +++ b/src/Tokens.h Sun Feb 09 04:13:15 2014 +0200 @@ -35,89 +35,91 @@ enum EToken { // Non-word tokens - tkLeftShiftAssign, // - tkRightShiftAssign, // - tkEquals, // ----- 0 + tkLeftShiftAssign, + tkRightShiftAssign, + tkEquals, tkNotEquals, - tkBrackets, // - 1 - tkAddAssign, // - 2 - tkSubAssign, // - 3 - tkMultiplyAssign, // - 4 - tkDivideAssign, // ----- 5 - tkModulusAssign, // - 6 - tkLeftShift, - tkRightShift, + tkBrackets, + tkAddAssign, + tkSubAssign, + tkMultiplyAssign, + tkDivideAssign, + tkModulusAssign, + tkLeftShift, + tkRightShift, tkAtLeast, tkAtMost, tkDoubleAmperstand, tkDoubleBar, - tkSingleQuote, // - 7 - tkDollarSign, // - 8 - tkParenStart, // - 9 - tkParenEnd, // ----- 10 - tkBracketStart, // - 11 - tkBracketEnd, // - 12 - tkBraceStart, // - 13 - tkBraceEnd, // - 14 - tkAssign, // ----- 15 - tkPlus, // - 16 - tkMinus, // - 17 - tkMultiply, // - 18 - tkDivide, // - 19 - tkModulus, // ----- 20 - tkComma, // - 21 - tkLesser, // - 22 - tkGreater, // - 23 - tkDot, // - 24 - tkColon, // ----- 25 - tkSemicolon, // - 26 - tkHash, // - 27 - tkExclamationMark, // - 28 + tkDoublePlus, + tkDoubleMinus, + tkSingleQuote, + tkDollarSign, + tkParenStart, + tkParenEnd, + tkBracketStart, + tkBracketEnd, + tkBraceStart, + tkBraceEnd, + tkAssign, + tkPlus, + tkMinus, + tkMultiply, + tkDivide, + tkModulus, + tkComma, + tkLesser, + tkGreater, + tkDot, + tkColon, + tkSemicolon, + tkHash, + tkExclamationMark, tkAmperstand, tkBar, tkCaret, tkQuestionMark, - tkArrow, // - 29 + tkArrow, // -------------- // Named tokens - tkBool, // ----- 30 - tkBreak, // - 31 - tkCase, // - 32 - tkContinue, // - 33 - tkConst, // - 34 - tkDefault, // ----- 35 - tkDo, // - 36 - tkElse, // - 37 - tkEvent, // - 38 - tkEventdef, // - 39 - tkFor, // ----- 40 - tkFuncdef, // - 41 - tkGoto, // - 42 - tkIf, // - 43 - tkInt, // - 44 - tkMainloop, // ----- 45 - tkOnenter, // - 46 - tkOnexit, // - 47 - tkState, // - 48 - tkSwitch, // - 49 - tkStr, // ----- 50 - tkVoid, // - 51 - tkWhile, // - 52 + tkBool, + tkBreak, + tkCase, + tkContinue, + tkConst, + tkDefault, + tkDo, + tkElse, + tkEvent, + tkEventdef, + tkFor, + tkFuncdef, + tkGoto, + tkIf, + tkInt, + tkMainloop, + tkOnenter, + tkOnexit, + tkState, + tkSwitch, + tkStr, + tkVoid, + tkWhile, tkTrue, tkFalse, // These ones aren't implemented yet but I plan to do so, thus they are // reserved. Also serves as a to-do list of sorts for me. >:F - tkEnum, // - 53 - tkFunc, // - 54 - tkReturn, // ----- 55 + tkEnum, + tkFunc, + tkReturn, // -------------- // Generic tokens - tkSymbol, // - 56 - tkNumber, // - 57 - tkString, // - 58 + tkSymbol, + tkNumber, + tkString, tkFirstNamedToken = tkBool, tkLastNamedToken = (int) tkSymbol - 1,