56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ShintenScript
|
|
{
|
|
public struct Token
|
|
{
|
|
public enum Type
|
|
{
|
|
NULL,
|
|
EOF,
|
|
IDENTIFIER,
|
|
NUMBER,
|
|
|
|
LPAREN, RPAREN, LBRACE, RBRACE,
|
|
PLUS, MINUS, ASTERISK, SLASH,
|
|
GT, LT, EQ, GE, LE, NE,
|
|
ASSIGN,
|
|
PLUSASSIGN, MINUSASSIGN, ASTERISKASSIGN, SLASHASSIGN,
|
|
|
|
IF, WHILE, FN
|
|
}
|
|
|
|
public Type type;
|
|
public object data;
|
|
|
|
public bool Null()
|
|
{
|
|
return type == Type.NULL;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return (int)type;
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj is Token other)
|
|
{
|
|
return type == other.type && ((data == null && other.data == null) || (data != null && other.data != null && data.Equals(other.data)));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{type} {data?.ToString() ?? "null"}";
|
|
}
|
|
}
|
|
}
|