Files
MicroST-Compiler/STCompiler.Common/VarType.cs

42 lines
1.5 KiB
C#

namespace STCompiler.Common;
// Gemeinsame Variable types für Compiler, Disassembler und Simulator
public enum VarType {
// Boolean
BOOL = 1,
// Unsigned integers
BYTE = 2, WORD = 3, DWORD = 4, LWORD = 5,
// Signed integers
SINT = 6, INT = 7, DINT = 8, LINT = 9,
// Unsigned integers (alternative names)
USINT = 10, UINT = 11, UDINT = 12, ULINT = 13,
// Floating point
REAL = 14, LREAL = 15,
// Date/time types
TIME = 16, // Zeitdauer -> TimeSpan
DATE = 17, // Datum -> DateTime
TIME_OF_DAY = 18, // Tageszeit (TOD) -> TimeSpan / DateTime
TOD = TIME_OF_DAY,
DATE_AND_TIME = 19,// Datum + Uhrzeit (DT) -> DateTime
DT = DATE_AND_TIME,
// Array marker - actual array types use ArrayType class
ARRAY = 20
}
// Represents an array type in structured text
public class ArrayType {
public VarType ElementType { get; set; } // Type of array elements
public int Start { get; set; } // Start index
public int End { get; set; } // End index
public int Length => End - Start + 1; // Number of elements
public ArrayType(VarType elementType, int start, int end) {
ElementType = elementType;
Start = start;
End = end;
if (end < start) throw new System.ArgumentException("Array end index must be greater than or equal to start index");
}
public override string ToString() => $"ARRAY [{Start}..{End}] OF {ElementType}";
}