-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement handling of goto. Allow functions to be part of an expressi…
…on (e.g. function call in if() statement)
- Loading branch information
1 parent
81a0279
commit 4421603
Showing
10 changed files
with
91 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using EOBot.Interpreter.Extensions; | ||
|
||
namespace EOBot.Interpreter.States | ||
{ | ||
public class GotoEvaluator : IScriptEvaluator | ||
{ | ||
public bool Evaluate(ProgramState input) | ||
{ | ||
// ensure we have the right keyword before advancing the program | ||
var current = input.Current(); | ||
if (current.TokenType != BotTokenType.Keyword || current.TokenValue != "goto") | ||
return false; | ||
|
||
input.Expect(BotTokenType.Keyword); | ||
|
||
if (!input.Match(BotTokenType.Identifier)) | ||
return false; | ||
|
||
var label = input.OperationStack.Pop().TokenValue; | ||
return input.Goto(input.Labels[label]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,10 @@ | ||
using EOBot.Interpreter.Variables; | ||
|
||
namespace EOBot.Interpreter.States | ||
namespace EOBot.Interpreter.States | ||
{ | ||
public class LabelEvaluator : IScriptEvaluator | ||
{ | ||
public bool Evaluate(ProgramState input) | ||
{ | ||
if (!input.MatchPair(BotTokenType.Identifier, BotTokenType.Colon)) | ||
return false; | ||
|
||
if (input.OperationStack.Count < 2) | ||
return false; | ||
|
||
// pop the colon | ||
input.OperationStack.Pop(); | ||
|
||
var labelToken = input.OperationStack.Pop(); | ||
if (labelToken.TokenType != BotTokenType.Identifier) | ||
return false; | ||
|
||
input.Labels.Add(new LabelIdentifier(labelToken.TokenValue), input.ExecutionIndex); | ||
|
||
return true; | ||
return input.ExpectPair(BotTokenType.Identifier, BotTokenType.Colon); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.