Private
Public Access
Correctly implemented methods
This commit is contained in:
1 parent
6724e8a3e7
commit
f39a3d3ca2
9 files changed
+187
-16
No files matched your search
+3
@@ -92,7 +92,10 @@
|
|||||||
<Compile Include="Verbs\DrawingVerbs\Actions\ResetPen.cs" />
|
<Compile Include="Verbs\DrawingVerbs\Actions\ResetPen.cs" />
|
||||||
<Compile Include="Verbs\DrawingVerbs\Shape\Square.cs" />
|
<Compile Include="Verbs\DrawingVerbs\Shape\Square.cs" />
|
||||||
<Compile Include="Verbs\DrawingVerbs\Shape\Triangle.cs" />
|
<Compile Include="Verbs\DrawingVerbs\Shape\Triangle.cs" />
|
||||||
|
<Compile Include="Verbs\Flow\DeclareMethod.cs" />
|
||||||
<Compile Include="Verbs\Flow\IfChunk.cs" />
|
<Compile Include="Verbs\Flow\IfChunk.cs" />
|
||||||
|
<Compile Include="Verbs\Flow\IncreaseStack.cs" />
|
||||||
|
<Compile Include="Verbs\Flow\IVerbChunk.cs" />
|
||||||
<Compile Include="Verbs\Flow\MethodChunk.cs" />
|
<Compile Include="Verbs\Flow\MethodChunk.cs" />
|
||||||
<Compile Include="Verbs\Value\ValueObjects\PointValue.cs" />
|
<Compile Include="Verbs\Value\ValueObjects\PointValue.cs" />
|
||||||
<Compile Include="Verbs\Value\ValueStorage.cs" />
|
<Compile Include="Verbs\Value\ValueStorage.cs" />
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ namespace Advanced_Software_Engineering {
|
|||||||
public class Drawer {
|
public class Drawer {
|
||||||
|
|
||||||
private ValueStorage valueStorage = new ValueStorage();
|
private ValueStorage valueStorage = new ValueStorage();
|
||||||
private ValueStorage verbFactoryVariables = new ValueStorage();
|
public List<IVerbChunk> verbChunks = new List<IVerbChunk>();
|
||||||
public List<VerbChunk> verbChunks = new List<VerbChunk>();
|
public bool verbChunkGeneratingMethod = false;
|
||||||
|
public Dictionary<string, MethodChunk> Methods = new Dictionary<string, MethodChunk>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The starting color of the pen / brush
|
/// The starting color of the pen / brush
|
||||||
@@ -71,7 +72,8 @@ namespace Advanced_Software_Engineering {
|
|||||||
brush = new SolidBrush(defaultColor);
|
brush = new SolidBrush(defaultColor);
|
||||||
fill = false;
|
fill = false;
|
||||||
valueStorage.Reset();
|
valueStorage.Reset();
|
||||||
verbChunks = new List<VerbChunk>();
|
verbChunks = new List<IVerbChunk>();
|
||||||
|
Methods = new Dictionary<string, MethodChunk>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -201,9 +203,5 @@ namespace Advanced_Software_Engineering {
|
|||||||
return valueStorage;
|
return valueStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueStorage GetVerbFactoryVariables() {
|
|
||||||
return verbFactoryVariables;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
using Advanced_Software_Engineering.Verbs.Value;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
|
class DeclareMethod : IVerb, IVerbChunk {
|
||||||
|
|
||||||
|
MethodChunk methodChunk;
|
||||||
|
|
||||||
|
|
||||||
|
public DeclareMethod(MethodChunk methodChunk) {
|
||||||
|
this.methodChunk = methodChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddVerb(IVerb verb) {
|
||||||
|
methodChunk.AddVerb(verb);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ExecuteVerb() {
|
||||||
|
//Declaration of method happens at parse time
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetDescription() {
|
||||||
|
return "Declares a method";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
|
public interface IVerbChunk : IVerb {
|
||||||
|
void AddVerb(IVerb verb);
|
||||||
|
|
||||||
|
void ExecuteVerb();
|
||||||
|
|
||||||
|
string GetDescription();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
public class IfChunk : VerbChunk, IVerb {
|
public class IfChunk : VerbChunk, IVerbChunk, IVerb {
|
||||||
|
|
||||||
IValue conditional;
|
IValue conditional;
|
||||||
ValueStorage valueStorage;
|
ValueStorage valueStorage;
|
||||||
|
|||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
using Advanced_Software_Engineering.Verbs.Value;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
|
public class IncreaseStack : IVerb {
|
||||||
|
|
||||||
|
ValueStorage valueStorage;
|
||||||
|
|
||||||
|
public IncreaseStack(ValueStorage valueStorage) {
|
||||||
|
valueStorage.IncreaseStack();
|
||||||
|
this.valueStorage = valueStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ExecuteVerb() {
|
||||||
|
valueStorage.IncreaseStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetDescription() {
|
||||||
|
return "Increase the stack";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
-4
@@ -1,26 +1,48 @@
|
|||||||
using Advanced_Software_Engineering.Verbs.Value;
|
using Advanced_Software_Engineering.Verbs.Value;
|
||||||
using Advanced_Software_Engineering.Verbs.Value.ValueTypes;
|
using Advanced_Software_Engineering.Verbs.Value.ValueTypes;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
public class MethodChunk : VerbChunk, IVerb, IValue {
|
public class MethodChunk : VerbChunk, IVerb, IValue {
|
||||||
|
|
||||||
ValueStorage valueStorage;
|
ValueStorage valueStorage;
|
||||||
|
DeclareVariable[] variables;
|
||||||
bool init = false;
|
bool init = false;
|
||||||
|
IValue result;
|
||||||
|
|
||||||
public MethodChunk(ValueStorage valueStorage) : base() {
|
public MethodChunk(ValueStorage valueStorage, DeclareVariable[] variables) : base() {
|
||||||
this.valueStorage = valueStorage;
|
this.valueStorage = valueStorage;
|
||||||
|
this.variables = variables;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<string> GetVariableNames() {
|
||||||
|
List<string> VariableNames = new List<string>();
|
||||||
|
foreach (DeclareVariable variable in variables) VariableNames.Add(variable.GetName());
|
||||||
|
return VariableNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeclareVariable[] GetVariables() {
|
||||||
|
return variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
public new void ExecuteVerb() {
|
public new void ExecuteVerb() {
|
||||||
valueStorage.IncreaseStack();
|
init = false;
|
||||||
|
result = null;
|
||||||
|
// The stack increased artificially
|
||||||
|
//valueStorage.IncreaseStack();
|
||||||
|
|
||||||
base.ExecuteVerb();
|
base.ExecuteVerb();
|
||||||
valueStorage.DecreaseStack();
|
if (valueStorage.CheckVariableExists("ret")) {
|
||||||
|
result = valueStorage.GetVariable("ret");
|
||||||
init = true;
|
init = true;
|
||||||
}
|
}
|
||||||
|
valueStorage.DecreaseStack();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public IValue GetResult() {
|
public IValue GetResult() {
|
||||||
return valueStorage.GetVariable("res");
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IValue Clone() {
|
public IValue Clone() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
|
|
||||||
public class VerbChunk : IVerb {
|
public class VerbChunk : IVerbChunk, IVerb {
|
||||||
private readonly List<IVerb> verbs;
|
private readonly List<IVerb> verbs;
|
||||||
|
|
||||||
public VerbChunk(List<IVerb> verbs) {
|
public VerbChunk(List<IVerb> verbs) {
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ namespace Advanced_Software_Engineering {
|
|||||||
ValueStorage rootValueStorage = drawer.GetValueStorage();
|
ValueStorage rootValueStorage = drawer.GetValueStorage();
|
||||||
|
|
||||||
|
|
||||||
List<VerbChunk> verbChunks = drawer.verbChunks;
|
List<IVerbChunk> verbChunks = drawer.verbChunks;
|
||||||
if (verbChunks.Count == 0) verbChunks.Add(null);
|
if (verbChunks.Count == 0) verbChunks.Add(null);
|
||||||
|
|
||||||
int chunkDepth = verbChunks.Count - 1;
|
int chunkDepth = verbChunks.Count - 1;
|
||||||
VerbChunk currentChunk = verbChunks[chunkDepth];
|
IVerbChunk currentChunk = verbChunks[chunkDepth];
|
||||||
|
|
||||||
CommandAndParameterParserResult result = HelperFunctions.CommandAndParameterParser(fullCommand);
|
CommandAndParameterParserResult result = HelperFunctions.CommandAndParameterParser(fullCommand);
|
||||||
|
|
||||||
@@ -96,6 +96,36 @@ namespace Advanced_Software_Engineering {
|
|||||||
parsed = true;
|
parsed = true;
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "def":
|
||||||
|
if (drawer.verbChunkGeneratingMethod) throw new Exception("Cannot declare a method while declaring method");
|
||||||
|
else if (chunkDepth != 0) throw new Exception("Cannot declare a method above root chunk"); //TODO, explain better
|
||||||
|
else if (commandParameters.Length >= 1) {
|
||||||
|
rootValueStorage.IncreaseStack();
|
||||||
|
//All parameters
|
||||||
|
DeclareVariable[] methodParameters = new DeclareVariable[] { };
|
||||||
|
|
||||||
|
//if assignments exist, make them
|
||||||
|
if(commandParameters.Length > 1) {
|
||||||
|
List<DeclareVariable> methodParameterList = new List<DeclareVariable>();
|
||||||
|
for (int index = 1; index < commandParameters.Length; index++) {
|
||||||
|
methodParameterList.Add(new DeclareVariable(rootValueStorage, commandParameters[index]));
|
||||||
|
}
|
||||||
|
methodParameters = methodParameterList.ToArray();
|
||||||
|
}
|
||||||
|
string methodName = commandParameters[0];
|
||||||
|
|
||||||
|
MethodChunk methodChunk = new MethodChunk(rootValueStorage, methodParameters);
|
||||||
|
DeclareMethod declareMethod = new DeclareMethod(methodChunk);
|
||||||
|
|
||||||
|
drawer.Methods.Add(methodName, methodChunk);
|
||||||
|
verbChunks.Add(declareMethod);
|
||||||
|
chunkDepth = verbChunks.Count - 1;
|
||||||
|
currentChunk = verbChunks[chunkDepth];
|
||||||
|
parsed = true;
|
||||||
|
tmpVerb = new NoOp();
|
||||||
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
@@ -103,10 +133,57 @@ namespace Advanced_Software_Engineering {
|
|||||||
if (!(commandParameters == null)) foreach (string parameter in commandParameters) {
|
if (!(commandParameters == null)) foreach (string parameter in commandParameters) {
|
||||||
parameters.Add(ValueFactory.CreateValue(rootValueStorage, parameter));
|
parameters.Add(ValueFactory.CreateValue(rootValueStorage, parameter));
|
||||||
}
|
}
|
||||||
|
|
||||||
int parameterLength = parameters.Count;
|
int parameterLength = parameters.Count;
|
||||||
|
|
||||||
|
//Check if method
|
||||||
|
if(drawer.Methods.ContainsKey(command)) {
|
||||||
|
MethodChunk methodChunk = drawer.Methods[command];
|
||||||
|
string[] methodVariableNames = methodChunk.GetVariableNames().ToArray();
|
||||||
|
|
||||||
|
//Handle errors
|
||||||
|
if (methodVariableNames.Length != parameterLength) throw new Exception("Method " + command + "Has an incorrect number of parameters");
|
||||||
|
|
||||||
|
|
||||||
|
/* So something like this:
|
||||||
|
* def abc d
|
||||||
|
* circle d
|
||||||
|
*
|
||||||
|
* abc 5
|
||||||
|
*
|
||||||
|
* would have to be translated into something like this
|
||||||
|
* @increase stack
|
||||||
|
* var d = 5 (of course in a higher stack)
|
||||||
|
*
|
||||||
|
* @run abc (abc doesn't increase it's own stack)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
VerbChunk localChunk = new VerbChunk();
|
||||||
|
localChunk.AddVerb(new IncreaseStack(rootValueStorage));
|
||||||
|
|
||||||
|
// Declare all of the variables first
|
||||||
|
foreach (DeclareVariable variable in methodChunk.GetVariables()) localChunk.AddVerb(variable);
|
||||||
|
|
||||||
|
// Update the values of the variables
|
||||||
|
for (int variableIndex = 0; variableIndex < methodVariableNames.Length; variableIndex++) {
|
||||||
|
UpdateVariable variableDeclaration = new UpdateVariable(rootValueStorage, methodVariableNames[variableIndex], parameters[variableIndex]);
|
||||||
|
localChunk.AddVerb(variableDeclaration);
|
||||||
|
}
|
||||||
|
|
||||||
|
// localChunk.AddVerb(methodChunk);
|
||||||
|
|
||||||
|
//Add chunk to chunk stack
|
||||||
|
localChunk.AddVerb(methodChunk);
|
||||||
|
//verbChunks.Add(localChunk);
|
||||||
|
|
||||||
|
//chunkDepth = verbChunks.Count - 1;
|
||||||
|
//currentChunk = verbChunks[chunkDepth];
|
||||||
|
tmpVerb = localChunk;
|
||||||
|
}
|
||||||
|
|
||||||
//process drawing commands and extras
|
//process drawing commands and extras
|
||||||
switch (command) {
|
else switch (command) {
|
||||||
//Drawing commands
|
//Drawing commands
|
||||||
case "move":
|
case "move":
|
||||||
case "moveto":
|
case "moveto":
|
||||||
|
|||||||
Reference in new issue
Block a user