fix: 修复编译中的一些小问题 (#52)

Co-authored-by: Lan_G <2911328695@qq.com>
Reviewed-on: PostGuard/Canon#52
This commit is contained in:
jackfiled 2024-04-22 21:48:57 +08:00
parent 366991046a
commit d381f56e1d
3 changed files with 13 additions and 10 deletions

View File

@ -15,8 +15,10 @@ public class AddOperator : NonTerminatedSyntaxNode
public override void GenerateCCode(CCodeBuilder builder) public override void GenerateCCode(CCodeBuilder builder)
{ {
var operatorType = Children[0].Convert<TerminatedSyntaxNode>().Token. var token = Children[0].Convert<TerminatedSyntaxNode>().Token;
Convert<OperatorSemanticToken>().OperatorType; if (token.TokenType == SemanticTokenType.Operator)
{
var operatorType = token.Convert<OperatorSemanticToken>().OperatorType;
if (operatorType == OperatorType.Plus) if (operatorType == OperatorType.Plus)
{ {
builder.AddString(" +"); builder.AddString(" +");
@ -25,6 +27,7 @@ public class AddOperator : NonTerminatedSyntaxNode
{ {
builder.AddString(" -"); builder.AddString(" -");
} }
}
else else
{ {
builder.AddString(" ||"); builder.AddString(" ||");

View File

@ -25,7 +25,7 @@ public class MultiplyOperator : NonTerminatedSyntaxNode
} }
else if (operatorType == OperatorType.Divide) else if (operatorType == OperatorType.Divide)
{ {
//实数除法,需要将操作数强转为float //实数除法,需要将操作数强转为double
builder.AddString(" /(double)"); builder.AddString(" /(double)");
} }
} }

View File

@ -24,7 +24,7 @@ public class ProgramStruct : NonTerminatedSyntaxNode
public override void GenerateCCode(CCodeBuilder builder) public override void GenerateCCode(CCodeBuilder builder)
{ {
builder.AddString("#include <PascalCoreLib.h> #include <stdbool.h>"); builder.AddString("#include <stdbool.h>");
Body.GenerateCCode(builder); Body.GenerateCCode(builder);
} }
} }