Compare commits
1 Commits
1.0.0
...
feat-gener
Author | SHA1 | Date | |
---|---|---|---|
![]() |
419b0bb296 |
@@ -31,7 +31,7 @@ public class CodeGeneratorVisitor(ICompilerLogger? logger = null) : TypeCheckVis
|
||||
|
||||
public override void PostVisit(ConstDeclaration constDeclaration)
|
||||
{
|
||||
base.PostVisit(constDeclaration);
|
||||
base.PreVisit(constDeclaration);
|
||||
|
||||
(IdentifierSemanticToken token, ConstValue constValue) = constDeclaration.ConstValue;
|
||||
|
||||
@@ -791,7 +791,7 @@ public class CodeGeneratorVisitor(ICompilerLogger? logger = null) : TypeCheckVis
|
||||
{
|
||||
// GenerateWhileLabel();
|
||||
Builder.AddLine($"""
|
||||
if (!{_whileConditionNames.Peek()})
|
||||
if ({_whileConditionNames.Peek()} == false)
|
||||
goto {_whileEndLabels.Peek()};
|
||||
""");
|
||||
}
|
||||
@@ -1080,7 +1080,7 @@ public class CodeGeneratorVisitor(ICompilerLogger? logger = null) : TypeCheckVis
|
||||
private void GenerateWhileLabel()
|
||||
{
|
||||
_whileBeginLabels.Push($"while_{_labelCount}");
|
||||
_whileConditionNames.Push($"while_condition_{_labelCount}");
|
||||
//_whileConditionNames.Push($"while_condition_{_labelCount}");
|
||||
_whileEndLabels.Push($"while_end_{_labelCount}");
|
||||
|
||||
_labelCount += 1;
|
||||
|
@@ -31,7 +31,7 @@ public abstract class PascalType : IEquatable<PascalType>
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return IsReference == other.IsReference;
|
||||
}
|
||||
|
||||
public T Convert<T>() where T : PascalType
|
||||
|
@@ -44,16 +44,7 @@ public class SymbolTable
|
||||
/// </summary>
|
||||
/// <param name="symbol">欲添加的符号</param>
|
||||
/// <returns>是否添加成功</returns>
|
||||
public bool TryAddSymbol(Symbol symbol)
|
||||
{
|
||||
if (_symbols.ContainsKey(symbol.SymbolName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_symbols.Add(symbol.SymbolName, symbol);
|
||||
return true;
|
||||
}
|
||||
public bool TryAddSymbol(Symbol symbol) => _symbols.TryAdd(symbol.SymbolName, symbol);
|
||||
|
||||
/// <summary>
|
||||
/// 尝试从符号表极其父符号表查找符号
|
||||
|
@@ -22,7 +22,7 @@ public class TypeCheckVisitor(ICompilerLogger? logger = null) : SyntaxNodeVisito
|
||||
|
||||
public override void PreVisit(ConstDeclaration constDeclaration)
|
||||
{
|
||||
base.PreVisit(constDeclaration);
|
||||
base.PostVisit(constDeclaration);
|
||||
|
||||
(IdentifierSemanticToken token, ConstValue constValue) = constDeclaration.ConstValue;
|
||||
|
||||
|
@@ -54,14 +54,4 @@ public class SymbolTableTests
|
||||
Assert.True(table.TryGetSymbol("temperature", out Symbol? temp));
|
||||
Assert.Equal(PascalBasicType.Real, temp.SymbolType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DuplicatedTest()
|
||||
{
|
||||
SymbolTable table = new();
|
||||
|
||||
Assert.True(table.TryAddSymbol(
|
||||
new Symbol{SymbolName = "a", SymbolType = PascalBasicType.Integer, Const = true}));
|
||||
Assert.False(table.TryAddSymbol(new Symbol{SymbolName = "a", SymbolType = PascalBasicType.Boolean}));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user