1
0
Fork 0
mirror of https://github.com/wagesj45/cs-mic.git synced 2025-06-30 20:40:27 -05:00
This commit is contained in:
Jordan Wages 2025-06-12 04:32:18 -05:00
parent 5066257912
commit eb3bbcb69e
6 changed files with 134 additions and 21 deletions

View file

@ -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;
}
}
}

View file

@ -11,6 +11,7 @@ namespace csmic
#region Properties
IEnumerable<FunctionArgument> ExpectedArguments { get; }
FunctionValue ReturnValue { get; }
#endregion

View file

@ -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
}
}

31
src/core/Variable.cs Normal file
View file

@ -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
}
}

18
src/core/VariableType.cs Normal file
View file

@ -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,
}
}

View file

@ -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<out success> (. this.calcValue = (success == true) ? 1 : 0; .)
Comparison<out success> (. this.functionValue = (success == true) ? FunctionValue.TRUE : FunctionValue.FALSE; .)
|
IF(IsAssignment())
Assignment<out r>