Sun, 09 Feb 2014 14:30:18 +0200
- changed the syntax of funcdef to something sane
botc_defs.bts | file | annotate | diff | comparison | revisions | |
src/Commands.cc | file | annotate | diff | comparison | revisions | |
src/Commands.h | file | annotate | diff | comparison | revisions | |
src/Lexer.cc | file | annotate | diff | comparison | revisions | |
src/Lexer.h | file | annotate | diff | comparison | revisions | |
src/Parser.cc | file | annotate | diff | comparison | revisions |
--- a/botc_defs.bts Sun Feb 09 04:13:15 2014 +0200 +++ b/botc_defs.bts Sun Feb 09 14:30:18 2014 +0200 @@ -6,101 +6,101 @@ // ============================================================================= // // Function definitions -// Syntax: number:name:returntype:numargs:maxargs[:argumentlist] +// Syntax: funcdef <return> <num>:<name> (<args>) // -funcdef 0:changestate:void:1:1:int(newstate); -funcdef 1:delay:void:1:1:int(tics); -funcdef 2:rand:int:2:2:int(a):int(b); -funcdef 3:StringsAreEqual:bool:2:2:str(string1):str(string2); -funcdef 4:LookForPowerups:int:2:2:int(start):bool(visibilitycheck); -funcdef 5:LookForWeapons:int:2:2:int(start):bool(visibilitycheck); -funcdef 6:LookForAmmo:int:2:2:int(start):bool(visibilitycheck); -funcdef 7:LookForBaseHealth:int:2:2:int(start):bool(visibilitycheck); -funcdef 8:LookForBaseArmor:int:2:2:int(start):bool(visibilitycheck); -funcdef 9:LookForSuperHealth:int:2:2:int(start):bool(visibilitycheck); -funcdef 10:LookForSuperArmor:int:2:2:int(start):bool(visibilitycheck); -funcdef 11:LookForPlayerEnemies:int:1:1:int(start); -funcdef 12:GetClosestPlayerEnemy:int:0:0; -funcdef 13:MoveLeft:void:1:1:int(speed); -funcdef 14:MoveRight:void:1:1:int(speed); -funcdef 15:MoveForward:void:1:1:int(speed); -funcdef 16:MoveBackwards:void:1:1:int(speed); -funcdef 17:StopMovement:void:0:0; -funcdef 18:StopForwardMovement:void:0:0; -funcdef 19:StopSidewaysMovement:void:0:0; -funcdef 20:CheckTerrain:int:2:2:int(distance):int(angle); -funcdef 21:PathToGoal:int:1:1:int(speed); -funcdef 22:PathToLastKnownEnemyPosition:int:1:1:int(speed); -funcdef 23:PathToLastHeardSound:int:1:1:int(speed); -funcdef 24:Roam:int:1:1:int(speed); -funcdef 25:GetPathingCostToItem:int:1:1:int(item); -funcdef 26:GetDistanceToItem:int:1:1:int(item); -funcdef 27:GetItemName:str:1:1:int(item); -funcdef 28:IsItemVisible:bool:1:1:int(item); -funcdef 29:SetGoal:void:1:1:int(item); -funcdef 30:BeginAimingAtEnemy:void:0:0; -funcdef 31:StopAimingAtEnemy:void:0:0; -funcdef 32:Turn:void:1:1:int(turnangle); -funcdef 33:GetCurrentAngle:int:0:0; -funcdef 34:SetEnemy:void:1:1:int(player); -funcdef 35:ClearEnemy:void:0:0; -funcdef 36:IsEnemyAlive:bool:0:0; -funcdef 37:IsEnemyVisible:bool:0:0; -funcdef 38:GetDistanceToEnemy:int:0:0; -funcdef 39:GetPlayerDamagedBy:int:0:0; -funcdef 40:GetEnemyInvulnerabilityTicks:int:0:0; -funcdef 41:FireWeapon:void:0:0; -funcdef 42:BeginFiringWeapon:void:0:0; -funcdef 43:StopFiringWeapon:void:0:0; -funcdef 44:GetCurrentWeapon:str:0:0; -funcdef 45:ChangeWeapon:void:1:1:str(weapon); -funcdef 46:GetWeaponFromItem:str:1:1:int(item); -funcdef 47:IsWeaponOwned:bool:1:1:int(item); -funcdef 48:IsFavoriteWeapon:bool:1:1:str(weapon); -funcdef 49:Say:void:1:1:str(message); -funcdef 50:SayFromFile:void:2:2:str(filename):str(section); -funcdef 51:SayFromChatFile:void:1:1:str(section); -funcdef 52:BeginChatting:void:0:0; -funcdef 53:StopChatting:void:0:0; -funcdef 54:ChatSectionExists:bool:1:1:str(section); -funcdef 55:ChatSectionExistsInFile:bool:2:2:str(filename):str(section); -funcdef 56:GetLastChatString:str:0:0; -funcdef 57:GetLastChatPlayer:str:0:0; -funcdef 58:GetChatFrequency:int:0:0; -funcdef 59:Jump:void:0:0; -funcdef 60:BeginJumping:void:0:0; -funcdef 61:StopJumping:void:0:0; -funcdef 62:Taunt:void:0:0; -funcdef 63:Respawn:void:0:0; -funcdef 64:TryToJoinGame:void:0:0; -funcdef 65:IsDead:bool:0:0; -funcdef 66:IsSpectating:bool:0:0; -funcdef 67:GetHealth:int:0:0; -funcdef 68:GetArmor:int:0:0; -funcdef 69:GetBaseHealth:int:0:0; -funcdef 70:GetBaseArmor:int:0:0; -funcdef 71:GetBotskill:int:0:0; -funcdef 72:GetAccuracy:int:0:0; -funcdef 73:GetIntellect:int:0:0; -funcdef 74:GetAnticipation:int:0:0; -funcdef 75:GetEvade:int:0:0; -funcdef 76:GetReactionTime:int:0:0; -funcdef 77:GetPerception:int:0:0; -funcdef 78:SetSkillIncrease:void:1:1:bool(increase); -funcdef 79:IsSkillIncreased:bool:0:0; -funcdef 80:SetSkillDecrease:void:1:1:bool(decrease); -funcdef 81:IsSkillDecreased:bool:0:0; -funcdef 82:GetGameMode:int:0:0; -funcdef 83:GetSpread:int:0:0; -funcdef 84:GetLastJoinedPlayer:str:0:0; -funcdef 85:GetPlayerName:str:1:1:int(player); -funcdef 86:GetReceivedMedal:int:0:0; -funcdef 87:ACS_Execute:void:1:5:int(script):int(map=0):int(arg0=0):int(arg1=0):int(arg2=0); -funcdef 88:GetFavoriteWeapon:str:0:0; -funcdef 89:SayFromLump:void:2:2:str(lump):str(section); -funcdef 90:SayFromChatLump:void:1:1:str(section); -funcdef 91:ChatSectionExistsInLump:bool:2:2:str(lump):str(section); -funcdef 92:ChatSectionExistsInChatLump:bool:1:1:str(section); +funcdef void 0:changestate (int newstate); +funcdef void 1:delay (int tics); +funcdef int 2:rand (int a, int b); +funcdef bool 3:StringsAreEqual (str string1, str string2); +funcdef int 4:LookForPowerups (int start, bool visibilitycheck); +funcdef int 5:LookForWeapons (int start, bool visibilitycheck); +funcdef int 6:LookForAmmo (int start, bool visibilitycheck); +funcdef int 7:LookForBaseHealth (int start, bool visibilitycheck); +funcdef int 8:LookForBaseArmor (int start, bool visibilitycheck); +funcdef int 9:LookForSuperHealth (int start, bool visibilitycheck); +funcdef int 10:LookForSuperArmor (int start, bool visibilitycheck); +funcdef int 11:LookForPlayerEnemies (int start); +funcdef int 12:GetClosestPlayerEnemy(); +funcdef void 13:MoveLeft (int speed); +funcdef void 14:MoveRight (int speed); +funcdef void 15:MoveForward (int speed); +funcdef void 16:MoveBackwards (int speed); +funcdef void 17:StopMovement(); +funcdef void 18:StopForwardMovement(); +funcdef void 19:StopSidewaysMovement(); +funcdef int 20:CheckTerrain (int distance, int angle); +funcdef int 21:PathToGoal (int speed); +funcdef int 22:PathToLastKnownEnemyPosition (int speed); +funcdef int 23:PathToLastHeardSound (int speed); +funcdef int 24:Roam (int speed); +funcdef int 25:GetPathingCostToItem (int item); +funcdef int 26:GetDistanceToItem (int item); +funcdef str 27:GetItemName (int item); +funcdef bool 28:IsItemVisible (int item); +funcdef void 29:SetGoal (int item); +funcdef void 30:BeginAimingAtEnemy(); +funcdef void 31:StopAimingAtEnemy(); +funcdef void 32:Turn (int turnangle); +funcdef int 33:GetCurrentAngle(); +funcdef void 34:SetEnemy (int player); +funcdef void 35:ClearEnemy(); +funcdef bool 36:IsEnemyAlive(); +funcdef bool 37:IsEnemyVisible(); +funcdef int 38:GetDistanceToEnemy(); +funcdef int 39:GetPlayerDamagedBy(); +funcdef int 40:GetEnemyInvulnerabilityTicks(); +funcdef void 41:FireWeapon(); +funcdef void 42:BeginFiringWeapon(); +funcdef void 43:StopFiringWeapon(); +funcdef str 44:GetCurrentWeapon(); +funcdef void 45:ChangeWeapon (str weapon); +funcdef str 46:GetWeaponFromItem (int item); +funcdef bool 47:IsWeaponOwned (int item); +funcdef bool 48:IsFavoriteWeapon (str weapon); +funcdef void 49:Say (str message); +funcdef void 50:SayFromFile (str filename, str section); +funcdef void 51:SayFromChatFile (str section); +funcdef void 52:BeginChatting(); +funcdef void 53:StopChatting(); +funcdef bool 54:ChatSectionExists (str section); +funcdef bool 55:ChatSectionExistsInFile (str filename, str section); +funcdef str 56:GetLastChatString(); +funcdef str 57:GetLastChatPlayer(); +funcdef int 58:GetChatFrequency(); +funcdef void 59:Jump(); +funcdef void 60:BeginJumping(); +funcdef void 61:StopJumping(); +funcdef void 62:Taunt(); +funcdef void 63:Respawn(); +funcdef void 64:TryToJoinGame(); +funcdef bool 65:IsDead(); +funcdef bool 66:IsSpectating(); +funcdef int 67:GetHealth(); +funcdef int 68:GetArmor(); +funcdef int 69:GetBaseHealth(); +funcdef int 70:GetBaseArmor(); +funcdef int 71:GetBotskill(); +funcdef int 72:GetAccuracy(); +funcdef int 73:GetIntellect(); +funcdef int 74:GetAnticipation(); +funcdef int 75:GetEvade(); +funcdef int 76:GetReactionTime(); +funcdef int 77:GetPerception(); +funcdef void 78:SetSkillIncrease (bool increase); +funcdef bool 79:IsSkillIncreased(); +funcdef void 80:SetSkillDecrease (bool decrease); +funcdef bool 81:IsSkillDecreased(); +funcdef int 82:GetGameMode(); +funcdef int 83:GetSpread(); +funcdef str 84:GetLastJoinedPlayer(); +funcdef str 85:GetPlayerName (int player); +funcdef int 86:GetReceivedMedal(); +funcdef void 87:ACS_Execute (int script, int map = 0, int arg0 = 0, int arg1 = 0, int arg2 = 0); +funcdef str 88:GetFavoriteWeapon(); +funcdef void 89:SayFromLump (str lump, str section); +funcdef void 90:SayFromChatLump (str section); +funcdef bool 91:ChatSectionExistsInLump (str lump, str section); +funcdef bool 92:ChatSectionExistsInChatLump (str section); // ============================================================================= //
--- a/src/Commands.cc Sun Feb 09 04:13:15 2014 +0200 +++ b/src/Commands.cc Sun Feb 09 14:30:18 2014 +0200 @@ -73,16 +73,16 @@ text += ' '; text += name; - if (maxargs != 0) + if (args.IsEmpty() == false) text += ' '; text += '('; bool hasoptionals = false; - for (int i = 0; i < maxargs; i++) + for (int i = 0; i < args.Size(); i++) { - if (i == numargs) + if (i == minargs) { hasoptionals = true; text += '['; @@ -95,7 +95,7 @@ text += ' '; text += args[i].name; - if (i >= numargs) + if (i >= minargs) { text += " = ";
--- a/src/Commands.h Sun Feb 09 04:13:15 2014 +0200 +++ b/src/Commands.h Sun Feb 09 14:30:18 2014 +0200 @@ -43,8 +43,7 @@ { String name; int number; - int numargs; - int maxargs; + int minargs; EType returnvalue; List<CommandArgument> args;
--- a/src/Lexer.cc Sun Feb 09 04:13:15 2014 +0200 +++ b/src/Lexer.cc Sun Feb 09 14:30:18 2014 +0200 @@ -286,6 +286,20 @@ // ============================================================================= // +bool Lexer::PeekNextType (EToken req) +{ + Iterator pos = mTokenPosition; + bool result = false; + + if (GetNext() && GetTokenType() == req) + result = true; + + mTokenPosition = pos; + return result; +} + +// ============================================================================= +// Lexer* Lexer::GetCurrentLexer() { return gMainLexer;
--- a/src/Lexer.h Sun Feb 09 04:13:15 2014 +0200 +++ b/src/Lexer.h Sun Feb 09 14:30:18 2014 +0200 @@ -58,6 +58,7 @@ int GetOneSymbol (const StringList& syms); void TokenMustBe (EToken tok); bool PeekNext (Token* tk = null); + bool PeekNextType (EToken req); String PeekNextString (int a = 1); String DescribePosition();
--- a/src/Parser.cc Sun Feb 09 04:13:15 2014 +0200 +++ b/src/Parser.cc Sun Feb 09 14:30:18 2014 +0200 @@ -899,6 +899,11 @@ { CommandInfo* comm = new CommandInfo; + // Return value + mLexer->MustGetAnyOf ({tkInt, tkVoid, tkBool, tkStr}); + comm->returnvalue = GetTypeByName (mLexer->GetToken()->text); // TODO + assert (comm->returnvalue != -1); + // Number mLexer->MustGetNext (tkNumber); comm->number = mLexer->GetToken()->text.ToLong(); @@ -907,41 +912,27 @@ // Name mLexer->MustGetNext (tkSymbol); comm->name = mLexer->GetToken()->text; - mLexer->MustGetNext (tkColon); - // Return value - mLexer->MustGetAnyOf ({tkInt, tkVoid, tkBool, tkStr}); - comm->returnvalue = GetTypeByName (mLexer->GetToken()->text); // TODO - assert (comm->returnvalue != -1); - mLexer->MustGetNext (tkColon); - - // Num args - mLexer->MustGetNext (tkNumber); - comm->numargs = mLexer->GetToken()->text.ToLong(); - mLexer->MustGetNext (tkColon); + // Arguments + mLexer->MustGetNext (tkParenStart); + comm->minargs = 0; - // Max args - mLexer->MustGetNext (tkNumber); - comm->maxargs = mLexer->GetToken()->text.ToLong(); - - // Argument types - int curarg = 0; + while (mLexer->PeekNextType (tkParenEnd) == false) + { + if (comm->args.IsEmpty() == false) + mLexer->MustGetNext (tkComma); - while (curarg < comm->maxargs) - { CommandArgument arg; - mLexer->MustGetNext (tkColon); mLexer->MustGetAnyOf ({tkInt, tkBool, tkStr}); - EType type = GetTypeByName (mLexer->GetToken()->text); + EType type = GetTypeByName (mLexer->GetToken()->text); // TODO assert (type != -1 && type != EVoidType); arg.type = type; - mLexer->MustGetNext (tkParenStart); mLexer->MustGetNext (tkSymbol); arg.name = mLexer->GetToken()->text; // If this is an optional parameter, we need the default value. - if (curarg >= comm->numargs) + if (comm->minargs < comm->args.Size() || mLexer->PeekNextType (tkAssign)) { mLexer->MustGetNext (tkAssign); @@ -953,8 +944,7 @@ break; case EStringType: - mLexer->MustGetNext (tkString); - break; + Error ("string arguments cannot have default values"); case EUnknownType: case EVoidType: @@ -963,12 +953,13 @@ arg.defvalue = mLexer->GetToken()->text.ToLong(); } + else + comm->minargs++; - mLexer->MustGetNext (tkParenEnd); comm->args << arg; - curarg++; } + mLexer->MustGetNext (tkParenEnd); mLexer->MustGetNext (tkSemicolon); AddCommandDefinition (comm); } @@ -987,11 +978,11 @@ int curarg = 0; - while (1) + for (;;) { if (TokenIs (tkParenEnd)) { - if (curarg < comm->numargs) + if (curarg < comm->minargs) Error ("too few arguments passed to %1\n\tusage is: %2", comm->name, comm->GetSignature()); @@ -999,19 +990,19 @@ curarg++; } - if (curarg >= comm->maxargs) + if (curarg >= comm->args.Size()) Error ("too many arguments passed to %1\n\tusage is: %2", comm->name, comm->GetSignature()); r->MergeAndDestroy (ParseExpression (comm->args[curarg].type, true)); mLexer->MustGetNext(); - if (curarg < comm->numargs - 1) + if (curarg < comm->minargs - 1) { mLexer->TokenMustBe (tkComma); mLexer->MustGetNext(); } - else if (curarg < comm->maxargs - 1) + else if (curarg < comm->args.Size() - 1) { // Can continue, but can terminate as well. if (TokenIs (tkParenEnd)) @@ -1030,7 +1021,7 @@ } // If the script skipped any optional arguments, fill in defaults. - while (curarg < comm->maxargs) + while (curarg < comm->args.Size()) { r->WriteDWord (dhPushNumber); r->WriteDWord (comm->args[curarg].defvalue); @@ -1039,7 +1030,7 @@ r->WriteDWord (dhCommand); r->WriteDWord (comm->number); - r->WriteDWord (comm->maxargs); + r->WriteDWord (comm->args.Size()); return r; }