FusionCalculator/src/Token.fu

33 lines
1.0 KiB
Plaintext

class Token {
string Str;
int StartIndex;
int Length;
// It is not a enum because there is no way to convert enum value to int in Fusion.
// The Type is also the priority of the token in calculation (see Parser).
int Type;
public const int Type_Literal=11;
public const int Type_OperatorPow=10;
public const int Type_OperatorMul=9;
public const int Type_OperatorMod=8;
public const int Type_OperatorDiv=7;
public const int Type_OperatorAdd=6;
public const int Type_OperatorSub=5;
public const int Type_BracketOpen=3;
public const int Type_BracketClose=2;
public const int Type_Number=1;
internal static Token() Create(string str, int startIndex, int length, int type){
Token() tok = {
Str = str,
StartIndex = startIndex,
Length = length,
Type = type
};
return tok;
}
internal string() GetStr() => Str.Substring(StartIndex, Length);
internal int GetTokType() => Type;
}