mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-12 04:29:25 +08:00
重写脚本解释器的实现,提高其可读性。
This commit is contained in:
32
Serein.Script/Node/FlowControl/IfNode.cs
Normal file
32
Serein.Script/Node/FlowControl/IfNode.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Script.Node.FlowControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 条件节点
|
||||
/// </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);
|
||||
}
|
||||
|
||||
}
|
||||
25
Serein.Script/Node/FlowControl/ProgramNode.cs
Normal file
25
Serein.Script/Node/FlowControl/ProgramNode.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Script.Node.FlowControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 程序入口
|
||||
/// </summary>
|
||||
public class ProgramNode : ASTNode
|
||||
{
|
||||
/// <summary>
|
||||
/// 程序可执行的语句
|
||||
/// </summary>
|
||||
public List<ASTNode> Statements { get; }
|
||||
|
||||
public ProgramNode(List<ASTNode> statements)
|
||||
{
|
||||
Statements = statements;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
28
Serein.Script/Node/FlowControl/ReturnNode.cs
Normal file
28
Serein.Script/Node/FlowControl/ReturnNode.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Script.Node.FlowControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回值
|
||||
/// </summary>
|
||||
public class ReturnNode : ASTNode
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回值来源
|
||||
/// </summary>
|
||||
public ASTNode Value { get; }
|
||||
|
||||
public ReturnNode(ASTNode returnNode)
|
||||
{
|
||||
Value = returnNode;
|
||||
}
|
||||
public ReturnNode()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
26
Serein.Script/Node/FlowControl/WhileNode.cs
Normal file
26
Serein.Script/Node/FlowControl/WhileNode.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Script.Node.FlowControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 循环条件节点
|
||||
/// </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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user