为Serein.Script增加类型分析,增加了更加详细的Number类型节点,优化了对象节点的链式表达式,修复了Lexer分析词法时,部分Token代码属性错误的问题。

This commit is contained in:
fengjiayi
2025-07-11 20:52:21 +08:00
parent 70f674ca1b
commit ec764c5675
27 changed files with 1724 additions and 334 deletions

View File

@@ -15,13 +15,14 @@ namespace Serein.Script.Node
/// <summary>
/// 变量名称
/// </summary>
public string Variable { get; }
//public string Variable { get; }
public ASTNode Target { get; }
/// <summary>
/// 对应的节点
/// </summary>
public ASTNode Value { get; }
public AssignmentNode(string variable, ASTNode value) => (Variable, Value) = (variable, value);
public AssignmentNode(ASTNode targetObject, ASTNode value) => (Target, Value) = (targetObject, value);
}

View File

@@ -12,8 +12,19 @@ namespace Serein.Script.Node
public class BinaryOperationNode : ASTNode
{
/// <summary>
/// 左元
/// </summary>
public ASTNode Left { get; }
/// <summary>
/// 操作符(布尔运算符 > 比较运算符 > 加减乘除
/// </summary>
public string Operator { get; }
/// <summary>
/// 右元
/// </summary>
public ASTNode Right { get; }
public BinaryOperationNode(ASTNode left, string op, ASTNode right)

View File

@@ -11,8 +11,17 @@ namespace Serein.Script.Node
/// </summary>
public class ClassTypeDefinitionNode : ASTNode
{
[Obsolete("此属性已经过时,可能在下一个版本中移除", false)]
public bool IsOverlay { get; set; }
/// <summary>
/// 类名称
/// </summary>
public string ClassName { get; }
/// <summary>
/// 字段名称及字段类型
/// </summary>
public Dictionary<string, Type> Fields { get; }
public ClassTypeDefinitionNode(Dictionary<string, Type> fields, string className, bool isOverlay)

View File

@@ -11,12 +11,19 @@ namespace Serein.Script.Node
/// </summary>
public class CollectionIndexNode : ASTNode
{
public ASTNode TargetValue { get; }
public ASTNode IndexValue { get; }
public CollectionIndexNode(ASTNode collectionValue,ASTNode indexValue)
/// <summary>
/// 集合来源
/// </summary>
public ASTNode Collection { get; }
/// <summary>
/// 索引来源
/// </summary>
public ASTNode Index { get; }
public CollectionIndexNode(ASTNode TargetValue,ASTNode indexValue)
{
this.TargetValue = collectionValue;
this.IndexValue = indexValue;
this.Collection = TargetValue;
this.Index = indexValue;
}
}
}

View File

@@ -11,7 +11,14 @@ namespace Serein.Script.Node
/// </summary>
public class FunctionCallNode : ASTNode
{
/// <summary>
/// 方法名称
/// </summary>
public string FunctionName { get; }
/// <summary>
/// 参数来源
/// </summary>
public List<ASTNode> Arguments { get; }
public FunctionCallNode(string functionName, List<ASTNode> arguments)

View File

@@ -11,6 +11,9 @@ namespace Serein.Script.Node
/// </summary>
public class IdentifierNode : ASTNode
{
/// <summary>
/// 定义的名称
/// </summary>
public string Name { get; }
public IdentifierNode(string name) => Name = name;
}

View File

@@ -11,8 +11,19 @@ namespace Serein.Script.Node
/// </summary>
public class IfNode : ASTNode
{
/// <summary>
/// 条件来源
/// </summary>
public ASTNode Condition { get; }
/// <summary>
/// 条件为 true 时所执行的语句
/// </summary>
public List<ASTNode> TrueBranch { get; }
/// <summary>
/// 条件为 false 时所执行的语句
/// </summary>
public List<ASTNode> FalseBranch { get; }
public IfNode(ASTNode condition, List<ASTNode> trueBranch, List<ASTNode> falseBranch)
=> (Condition, TrueBranch, FalseBranch) = (condition, trueBranch, falseBranch);

View File

@@ -12,12 +12,12 @@ namespace Serein.Script.Node
public class MemberAccessNode : ASTNode
{
/// <summary>
/// 对象token
/// 对象来源
/// </summary>
public ASTNode Object { get; }
/// <summary>
/// 成员名称
/// 对象中要获取的成员名称
/// </summary>
public string MemberName { get; }

View File

@@ -12,11 +12,12 @@ namespace Serein.Script.Node
public class MemberAssignmentNode : ASTNode
{
/// <summary>
/// 作用的对象
/// 对象来源
/// </summary>
public ASTNode Object { get; }
/// <summary>
/// 赋值的成员(属性/字段)名称
/// 对象中要赋值的成员名称
/// </summary>
public string MemberName { get; }
/// <summary>

View File

@@ -12,17 +12,17 @@ namespace Serein.Script.Node
public class MemberFunctionCallNode : ASTNode
{
/// <summary>
/// 需要被调用的对象
/// 对象来源
/// </summary>
public ASTNode Object { get; }
/// <summary>
/// 调用的方法名称
/// 对象中要调用的方法名称
/// </summary>
public string FunctionName { get; }
/// <summary>
/// 方法参数
/// 方法参数来源
/// </summary>
public List<ASTNode> Arguments { get; }

View File

@@ -11,7 +11,14 @@ namespace Serein.Script.Node
/// </summary>
public class ObjectInstantiationNode : ASTNode
{
/// <summary>
/// 类型名称
/// </summary>
public string TypeName { get; }
/// <summary>
/// 构造方法的参数来源
/// </summary>
public List<ASTNode> Arguments { get; }
public ObjectInstantiationNode(string typeName, List<ASTNode> arguments)
{

View File

@@ -0,0 +1,15 @@
namespace Serein.Script.Node
{
public class ObjectMemberExpressionNode : ASTNode
{
/// <summary>
/// 对象成员(嵌套获取)
/// </summary>
public ASTNode Value { get; }
public ObjectMemberExpressionNode(ASTNode value)
{
this.Value = value;
}
}
}

View File

@@ -11,6 +11,9 @@ namespace Serein.Script.Node
/// </summary>
public class ProgramNode : ASTNode
{
/// <summary>
/// 程序可执行的语句
/// </summary>
public List<ASTNode> Statements { get; }
public ProgramNode(List<ASTNode> statements)

View File

@@ -11,6 +11,9 @@ namespace Serein.Script.Node
/// </summary>
public class ReturnNode : ASTNode
{
/// <summary>
/// 返回值来源
/// </summary>
public ASTNode Value { get; }
public ReturnNode(ASTNode returnNode)

View File

@@ -11,7 +11,14 @@ namespace Serein.Script.Node
/// </summary>
public class WhileNode : ASTNode
{
/// <summary>
/// 循环条件值来源
/// </summary>
public ASTNode Condition { get; }
/// <summary>
/// 循环中语句块
/// </summary>
public List<ASTNode> Body { get; }
public WhileNode(ASTNode condition, List<ASTNode> body) => (Condition, Body) = (condition, body);
}