Canon/Canon.Core/SyntaxNodes/AddOperator.cs
jackfiled d381f56e1d fix: 修复编译中的一些小问题 (#52)
Co-authored-by: Lan_G <2911328695@qq.com>
Reviewed-on: PostGuard/Canon#52
2024-04-22 21:48:57 +08:00

37 lines
1022 B
C#

using Canon.Core.CodeGenerators;
using Canon.Core.Enums;
using Canon.Core.LexicalParser;
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 };
}
public override void GenerateCCode(CCodeBuilder builder)
{
var token = Children[0].Convert<TerminatedSyntaxNode>().Token;
if (token.TokenType == SemanticTokenType.Operator)
{
var operatorType = token.Convert<OperatorSemanticToken>().OperatorType;
if (operatorType == OperatorType.Plus)
{
builder.AddString(" +");
}
else if (operatorType == OperatorType.Minus)
{
builder.AddString(" -");
}
}
else
{
builder.AddString(" ||");
}
}
}