diff --git a/src/core/FunctionValue.cs b/src/core/FunctionValue.cs index 4b9d991..418dd29 100644 --- a/src/core/FunctionValue.cs +++ b/src/core/FunctionValue.cs @@ -9,7 +9,22 @@ namespace csmic { public class FunctionValue { - public required csmic.ValueType Type { get; set; } + public ValueType Type { get; set; } public object? Value { get; set; } + + public static readonly FunctionValue TRUE = new FunctionValue(ValueType.Numeric, 1); + public static readonly FunctionValue FALSE = new FunctionValue(ValueType.Numeric, 0); + + public FunctionValue() + { + this.Type = ValueType.None; + this.Value = null; + } + + public FunctionValue(ValueType type, object? value) + { + this.Type = type; + this.Value = value; + } } } diff --git a/src/core/ICodedFunction.cs b/src/core/ICodedFunction.cs index 140ce6a..4baf142 100644 --- a/src/core/ICodedFunction.cs +++ b/src/core/ICodedFunction.cs @@ -11,6 +11,7 @@ namespace csmic #region Properties IEnumerable ExpectedArguments { get; } + FunctionValue ReturnValue { get; } #endregion diff --git a/src/core/InputInterpreter.cs b/src/core/InputInterpreter.cs index 3d0ca37..cae5446 100644 --- a/src/core/InputInterpreter.cs +++ b/src/core/InputInterpreter.cs @@ -1,7 +1,69 @@ -namespace csmic +using System.Runtime.CompilerServices; + +namespace csmic { public class InputInterpreter { + #region Members + private decimal numericValue = 0; + private string stringValue = string.Empty; + + #endregion + + #region Properties + + public decimal NumericValue + { + get + { + return numericValue; + } + } + + public string StringValue + { + get + { + return stringValue; + } + } + + #endregion + + #region Methods + + internal void ProduceOutput(decimal numericValue, string stringValue) + { + this.numericValue = numericValue; + this.stringValue = stringValue; + } + + internal void ProduceOutput(FunctionValue functionValue) + { + switch (functionValue.Type) + { + case ValueType.Numeric: + decimal numericValue = Convert.ToDecimal(functionValue.Value); + ProduceOutput(numericValue, string.Empty); + break; + case ValueType.String: + if (functionValue.Value != null && functionValue.Value is string) + { + ProduceOutput(0, functionValue.Value!.ToString()); + } + else + { + ProduceOutput(0, string.Empty); + } + break; + case ValueType.None: + default: + ProduceOutput(0, string.Empty); + break; + } + } + + #endregion } } diff --git a/src/core/Variable.cs b/src/core/Variable.cs new file mode 100644 index 0000000..166d4fb --- /dev/null +++ b/src/core/Variable.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace cs_mic.core +{ + public class Variable + { + #region Members + + private VariableType type; + + private string name; + + private object value; + + #endregion + + #region Constructor + + public Variable() + { + this.type = VariableType.None; + this.value = string.Empty; + } + + #endregion + } +} diff --git a/src/core/VariableType.cs b/src/core/VariableType.cs new file mode 100644 index 0000000..2c4bc76 --- /dev/null +++ b/src/core/VariableType.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace cs_mic.core +{ + public enum VariableType + { + None, + Numeric, + NumericArray, + String, + StringArray, + Expression, + } +} diff --git a/src/core/cocor/Interpreter.atg b/src/core/cocor/Interpreter.atg index 6a2ea0f..6932af5 100644 --- a/src/core/cocor/Interpreter.atg +++ b/src/core/cocor/Interpreter.atg @@ -10,30 +10,17 @@ COMPILER INTERPRETER * */ -private decimal calcValue = 0; -private string stringValue = string.Empty; +private FunctionValue value = new FunctionValue(); public decimal CalculatedValue { get { - return this.calcValue; + return this.value; } set { - this.calcValue = value; - } -} - -public string StringValue -{ - get - { - return this.stringValue - } - set - { - this.stringValue = value + this.value = value; } } @@ -126,8 +113,7 @@ IGNORE cr + tab PRODUCTIONS INTERPRETER (. - decimal decimalValue = 0; - string stringValue = string.Empty; + FunctionValue functionValue = new FunctionValue(); bool success = true; if(this.interpreter == null) { @@ -137,7 +123,7 @@ IGNORE cr + tab = IF(IsCompare()) - Comparison (. this.calcValue = (success == true) ? 1 : 0; .) + Comparison (. this.functionValue = (success == true) ? FunctionValue.TRUE : FunctionValue.FALSE; .) | IF(IsAssignment()) Assignment \ No newline at end of file