Private
Public Access
Variables can now be assigned.
Next i need to make it so the variables can be accessed and used by other functions
This commit is contained in:
1 parent
2acb57f229
commit
39489ec824
6 files changed
+42
-10
No files matched your search
@@ -122,7 +122,15 @@ namespace Advanced_Software_Engineering {
|
||||
ProcessCommands(rawCommands, pardonCommands);
|
||||
|
||||
for (; start < commands.Count; start++) {
|
||||
try {
|
||||
commands[start].ExecuteVerb();
|
||||
} catch (Exception e) {
|
||||
IVerb tmp = commands[start];
|
||||
if (!pardonCommands) RemoveAllCommands();
|
||||
else commands.Remove(commands[start]);
|
||||
new ErrorWindow("Runtime Error", "Failed to " + tmp.GetDescription(), "While trying to '" + tmp.GetDescription() + "' an exception occured.\nMessage:\n" + e.Message + "\nStack Trace:\n" + e.StackTrace, ErrorWindow.ERROR_MESSAGE).Show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ namespace Advanced_Software_Engineering {
|
||||
pen = new Pen(defaultColor, defaultWidth);
|
||||
brush = new SolidBrush(defaultColor);
|
||||
fill = false;
|
||||
variables.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+24
-6
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
|
||||
@@ -7,17 +8,34 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
private IValue value;
|
||||
private string name;
|
||||
|
||||
public DeclareVariable(Drawer drawer, string type, string assgnment) {
|
||||
public DeclareVariable(Drawer drawer, string type, string assignment) {
|
||||
this.drawer = drawer;
|
||||
|
||||
value = ValueFactory.CreateValue(type, assgnment);
|
||||
}
|
||||
// get variable name
|
||||
// assignment looks something like this at this point:
|
||||
// i = 20
|
||||
// or
|
||||
// i = 2 == 5
|
||||
|
||||
void IVerb.ExecuteVerb() {
|
||||
}
|
||||
// bools have ==
|
||||
if(!(type == "bool")) {
|
||||
//Seperate the assignment from the variables
|
||||
List<string> assignmentList = SettingsAndHelperFunctions.StripStringArray(assignment.Split("="[0]));
|
||||
name = assignmentList[0];
|
||||
value = ValueFactory.CreateValue(assignmentList[1], type);
|
||||
|
||||
string IVerb.GetDescription() {
|
||||
} else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ExecuteVerb() {
|
||||
drawer.SetVariable(name, value);
|
||||
}
|
||||
|
||||
public string GetDescription() {
|
||||
return "Declares the variable " + name;
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -25,7 +25,7 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
|
||||
//Check for bad input
|
||||
if (operation > 3 && operation < 0) throw new Exception("Bad operation");
|
||||
if(variable1.)
|
||||
|
||||
}
|
||||
|
||||
private IValue Evaluate() {
|
||||
@@ -103,18 +103,22 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
}
|
||||
|
||||
public bool ToBool() {
|
||||
if (!evaluated) Evaluate();
|
||||
return evaluatedValue.ToBool();
|
||||
}
|
||||
|
||||
public Color ToColor() {
|
||||
if (!evaluated) Evaluate();
|
||||
return evaluatedValue.ToColor();
|
||||
}
|
||||
|
||||
public double ToDouble() {
|
||||
if (!evaluated) Evaluate();
|
||||
return evaluatedValue.ToDouble();
|
||||
}
|
||||
|
||||
public int ToInt() {
|
||||
if (!evaluated) Evaluate();
|
||||
return evaluatedValue.ToInt();
|
||||
}
|
||||
}
|
||||
|
||||
-3
@@ -25,9 +25,6 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
case "bool":
|
||||
return new BoolValue(ValueHelper.ConvertToBool(value));
|
||||
|
||||
case "expression":
|
||||
return new Exception(ValueHelper.ConvertToExpression(value));
|
||||
|
||||
default:
|
||||
throw new Exception("Unknown expected type: " + type.ToString());
|
||||
}
|
||||
|
||||
@@ -147,5 +147,9 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
}
|
||||
throw new Exception("Could not convert " + text + " to any type");
|
||||
}
|
||||
|
||||
public static Exception ConvertToExpression(string expression) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user