-
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.
Add some high level program states (mostly stubbed)
- Loading branch information
1 parent
2075a36
commit 9f25a89
Showing
11 changed files
with
223 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace EOBot.Interpreter.States | ||
{ | ||
public class AssignmentEvaluator : IScriptEvaluator | ||
{ | ||
private readonly IEnumerable<IScriptEvaluator> _evaluators; | ||
|
||
public AssignmentEvaluator(IEnumerable<IScriptEvaluator> evaluators) | ||
{ | ||
_evaluators = evaluators; | ||
} | ||
|
||
public bool Evaluate(ProgramState input) | ||
{ | ||
// match variable | ||
// match = | ||
// match expr | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
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,19 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace EOBot.Interpreter.States | ||
{ | ||
public class FunctionEvaluator : IScriptEvaluator | ||
{ | ||
private readonly IEnumerable<IScriptEvaluator> _evaluators; | ||
|
||
public FunctionEvaluator(IEnumerable<IScriptEvaluator> evaluators) | ||
{ | ||
_evaluators = evaluators; | ||
} | ||
|
||
public bool Evaluate(ProgramState input) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
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,7 @@ | ||
namespace EOBot.Interpreter.States | ||
{ | ||
public interface IScriptEvaluator | ||
{ | ||
bool Evaluate(ProgramState input); | ||
} | ||
} |
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,22 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace EOBot.Interpreter.States | ||
{ | ||
public class KeywordEvaluator : IScriptEvaluator | ||
{ | ||
private readonly IEnumerable<IScriptEvaluator> _evaluators; | ||
|
||
public KeywordEvaluator(IEnumerable<IScriptEvaluator> evaluators) | ||
{ | ||
_evaluators = evaluators; | ||
} | ||
|
||
public bool Evaluate(ProgramState input) | ||
{ | ||
// evaluate if | ||
// or evaluate while | ||
// or evaluate goto | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
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,11 @@ | ||
namespace EOBot.Interpreter.States | ||
{ | ||
public class LabelEvaluator : IScriptEvaluator | ||
{ | ||
public bool Evaluate(ProgramState input) | ||
{ | ||
return input.Expect(BotTokenType.Label) | ||
&& input.Expect(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using EOBot.Interpreter.Variables; | ||
using System.Collections.Generic; | ||
|
||
namespace EOBot.Interpreter.States | ||
{ | ||
public class ProgramState | ||
{ | ||
public Stack<BotToken> OperationStack { get; } | ||
|
||
public IReadOnlyList<BotToken> Program { get; } | ||
|
||
public Dictionary<string, IIdentifiable> SymbolTable { get; } | ||
|
||
public Dictionary<LabelIdentifier, int> Labels { get; } | ||
|
||
public int ExecutionIndex { get; private set; } | ||
|
||
public ProgramState(IReadOnlyList<BotToken> program) | ||
{ | ||
OperationStack = new Stack<BotToken>(); | ||
Program = program; | ||
SymbolTable = new Dictionary<string, IIdentifiable>(); | ||
Labels = new Dictionary<LabelIdentifier, int>(); | ||
ExecutionIndex = 0; | ||
} | ||
|
||
public bool Expect(BotTokenType tokenType) | ||
{ | ||
if (ExecutionIndex >= Program.Count) | ||
return false; | ||
|
||
return Program[ExecutionIndex].TokenType == tokenType; | ||
} | ||
|
||
public bool Match(BotTokenType tokenType) | ||
{ | ||
if (ExecutionIndex >= Program.Count) | ||
return false; | ||
|
||
if (Program[ExecutionIndex].TokenType == tokenType) | ||
{ | ||
OperationStack.Push(Program[ExecutionIndex]); | ||
ExecutionIndex++; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
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,24 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace EOBot.Interpreter.States | ||
{ | ||
public class ScriptEvaluator : IScriptEvaluator | ||
{ | ||
private readonly IEnumerable<IScriptEvaluator> _evaluators; | ||
|
||
public ScriptEvaluator(IEnumerable<IScriptEvaluator> evaluators) | ||
{ | ||
_evaluators = evaluators; | ||
} | ||
|
||
public bool Evaluate(ProgramState input) | ||
{ | ||
return _evaluators | ||
.OfType<StatementListEvaluator>() | ||
.Single() | ||
.Evaluate(input) | ||
&& input.Expect(BotTokenType.EOF); | ||
} | ||
} | ||
} |
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,32 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace EOBot.Interpreter.States | ||
{ | ||
public class StatementEvaluator : IScriptEvaluator | ||
{ | ||
private readonly IEnumerable<IScriptEvaluator> _evaluators; | ||
|
||
public StatementEvaluator(IEnumerable<IScriptEvaluator> evaluators) | ||
{ | ||
_evaluators = evaluators; | ||
} | ||
|
||
public bool Evaluate(ProgramState input) | ||
{ | ||
return Evaluate<AssignmentEvaluator>(input) | ||
|| Evaluate<KeywordEvaluator>(input) | ||
|| Evaluate<LabelEvaluator>(input) | ||
|| Evaluate<FunctionEvaluator>(input); | ||
} | ||
|
||
private bool Evaluate<T>(ProgramState input) | ||
where T : IScriptEvaluator | ||
{ | ||
return _evaluators | ||
.OfType<T>() | ||
.Single() | ||
.Evaluate(input); | ||
} | ||
} | ||
} |
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,24 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace EOBot.Interpreter.States | ||
{ | ||
public class StatementListEvaluator : IScriptEvaluator | ||
{ | ||
private readonly IEnumerable<IScriptEvaluator> _evaluators; | ||
|
||
public StatementListEvaluator(IEnumerable<IScriptEvaluator> evaluators) | ||
{ | ||
_evaluators = evaluators; | ||
} | ||
|
||
public bool Evaluate(ProgramState input) | ||
{ | ||
return _evaluators | ||
.OfType<StatementEvaluator>() | ||
.Single() | ||
.Evaluate(input) | ||
&& this.Evaluate(input); | ||
} | ||
} | ||
} |