2024-04-21 22:24:35 +08:00
|
|
|
|
using Canon.Core.CodeGenerators;
|
|
|
|
|
using Canon.Core.Enums;
|
|
|
|
|
using Canon.Core.LexicalParser;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Canon.Core.SyntaxNodes;
|
|
|
|
|
|
|
|
|
|
public class AddOperator : NonTerminatedSyntaxNode
|
|
|
|
|
{
|
|
|
|
|
public override NonTerminatorType Type => NonTerminatorType.AddOperator;
|
|
|
|
|
|
|
|
|
|
public static AddOperator Create(List<SyntaxNodeBase> children)
|
|
|
|
|
{
|
|
|
|
|
return new AddOperator { Children = children };
|
|
|
|
|
}
|
2024-04-21 22:24:35 +08:00
|
|
|
|
|
|
|
|
|
public override void GenerateCCode(CCodeBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
var operatorType = Children[0].Convert<TerminatedSyntaxNode>().Token.
|
|
|
|
|
Convert<OperatorSemanticToken>().OperatorType;
|
|
|
|
|
if (operatorType == OperatorType.Plus)
|
|
|
|
|
{
|
|
|
|
|
builder.AddString(" +");
|
|
|
|
|
}
|
|
|
|
|
else if (operatorType == OperatorType.Minus)
|
|
|
|
|
{
|
|
|
|
|
builder.AddString(" -");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
builder.AddString(" ||");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|