32 lines
575 B
C#
32 lines
575 B
C#
|
namespace CanonSharp.Pascal.SyntaxTree;
|
|||
|
|
|||
|
public enum SyntaxNodeType
|
|||
|
{
|
|||
|
BinaryOperator,
|
|||
|
UnaryOperator,
|
|||
|
IntegerValue,
|
|||
|
FloatValue,
|
|||
|
BooleanValue,
|
|||
|
Variable,
|
|||
|
Assign,
|
|||
|
Block,
|
|||
|
ProgramBody,
|
|||
|
ProgramHead,
|
|||
|
Program
|
|||
|
}
|
|||
|
|
|||
|
public abstract class SyntaxNodeBase
|
|||
|
{
|
|||
|
public abstract SyntaxNodeType NodeType { get; }
|
|||
|
|
|||
|
public T Convert<T>() where T : SyntaxNodeBase
|
|||
|
{
|
|||
|
if (this is not T result)
|
|||
|
{
|
|||
|
throw new InvalidCastException($"Can't convert {NodeType} to target node.");
|
|||
|
}
|
|||
|
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|