2024-04-26 10:18:49 +08:00
|
|
|
|
using Canon.Core.Abstractions;
|
2024-04-21 22:24:35 +08:00
|
|
|
|
using Canon.Core.Enums;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Canon.Core.SyntaxNodes;
|
|
|
|
|
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public class FactorGeneratorEventArgs : EventArgs
|
2024-04-26 10:18:49 +08:00
|
|
|
|
{
|
|
|
|
|
public required Factor Factor { get; init; }
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public class MultiplyGeneratorEventArgs : EventArgs
|
2024-04-26 10:18:49 +08:00
|
|
|
|
{
|
|
|
|
|
public required Term Left { get; init; }
|
|
|
|
|
|
|
|
|
|
public required MultiplyOperator Operator { get; init; }
|
|
|
|
|
|
|
|
|
|
public required Factor Right { get; init; }
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 16:47:28 +08:00
|
|
|
|
public class Term : NonTerminatedSyntaxNode
|
|
|
|
|
{
|
|
|
|
|
public override NonTerminatorType Type => NonTerminatorType.Term;
|
|
|
|
|
|
2024-05-10 16:45:21 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否为条件判断语句
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsCondition { get; set; }
|
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
public override void PreVisit(SyntaxNodeVisitor visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor.PreVisit(this);
|
|
|
|
|
RaiseEvent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PostVisit(SyntaxNodeVisitor visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor.PostVisit(this);
|
|
|
|
|
RaiseEvent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 直接赋值产生式的事件
|
|
|
|
|
/// </summary>
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public event EventHandler<FactorGeneratorEventArgs>? OnFactorGenerator;
|
2024-04-26 10:18:49 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 乘法产生式的事件
|
|
|
|
|
/// </summary>
|
2024-05-01 21:06:27 +08:00
|
|
|
|
public event EventHandler<MultiplyGeneratorEventArgs>? OnMultiplyGenerator;
|
2024-04-26 10:18:49 +08:00
|
|
|
|
|
2024-04-07 16:47:28 +08:00
|
|
|
|
public static Term Create(List<SyntaxNodeBase> children)
|
|
|
|
|
{
|
|
|
|
|
return new Term { Children = children };
|
|
|
|
|
}
|
2024-04-21 22:24:35 +08:00
|
|
|
|
|
2024-04-26 10:18:49 +08:00
|
|
|
|
private void RaiseEvent()
|
|
|
|
|
{
|
|
|
|
|
if (Children.Count == 1)
|
|
|
|
|
{
|
2024-05-10 16:45:21 +08:00
|
|
|
|
OnFactorGenerator?.Invoke(this, new FactorGeneratorEventArgs { Factor = Children[0].Convert<Factor>() });
|
2024-04-26 10:18:49 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-10 16:45:21 +08:00
|
|
|
|
OnMultiplyGenerator?.Invoke(this,
|
|
|
|
|
new MultiplyGeneratorEventArgs
|
|
|
|
|
{
|
|
|
|
|
Left = Children[0].Convert<Term>(),
|
|
|
|
|
Operator = Children[1].Convert<MultiplyOperator>(),
|
|
|
|
|
Right = Children[2].Convert<Factor>()
|
|
|
|
|
});
|
2024-04-26 10:18:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnFactorGenerator = null;
|
|
|
|
|
OnMultiplyGenerator = null;
|
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|