CanonSharp/CanonSharp.Pascal/SyntaxTree/SyntaxNodeBase.cs
jackfiled cf19f8197e feat: Grammar Parser (#3)
Reviewed-on: https://git.bupt-hpc.cn/jackfiled/CanonSharp/pulls/3
Co-authored-by: jackfiled <xcrenchangjun@outlook.com>
Co-committed-by: jackfiled <xcrenchangjun@outlook.com>
2024-08-18 12:01:27 +08:00

44 lines
757 B
C#

namespace CanonSharp.Pascal.SyntaxTree;
public enum SyntaxNodeType
{
BinaryOperator,
UnaryOperator,
IntegerValue,
FloatValue,
BooleanValue,
CharValue,
Variable,
Type,
Assign,
Block,
Constant,
VariableDeclaration,
If,
While,
For,
ProcedureCall,
Parameter,
SubprogramHead,
SubprogramBody,
SubProgram,
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;
}
}