feat: 按照open_set中的示例调整语法 (#71)
添加了构建LR分析表冲突的报错 Reviewed-on: PostGuard/Canon#71
This commit is contained in:
@@ -9,10 +9,10 @@ public class PascalGrammarTests
|
||||
public void DoNothingTest()
|
||||
{
|
||||
const string program = """
|
||||
program DoNothing;
|
||||
begin
|
||||
end.
|
||||
""";
|
||||
program DoNothing;
|
||||
begin
|
||||
end.
|
||||
""";
|
||||
|
||||
ProgramStruct root = CompilerHelpers.Analyse(program);
|
||||
Assert.Equal("DoNothing", root.Head.ProgramName.LiteralValue);
|
||||
@@ -161,4 +161,86 @@ public class PascalGrammarTests
|
||||
|
||||
CompilerHelpers.Analyse(program);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProcedureCallTest()
|
||||
{
|
||||
const string program = """
|
||||
program main;
|
||||
var a : integer;
|
||||
function test : integer;
|
||||
begin
|
||||
end;
|
||||
begin
|
||||
test;
|
||||
a := test;
|
||||
test();
|
||||
a := test();
|
||||
end.
|
||||
""";
|
||||
|
||||
CompilerHelpers.Analyse(program);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProcedureDefinitionTest()
|
||||
{
|
||||
const string program = """
|
||||
program main;
|
||||
procedure test();
|
||||
begin
|
||||
end;
|
||||
begin
|
||||
test();
|
||||
end.
|
||||
""";
|
||||
|
||||
CompilerHelpers.Analyse(program);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FactorTest()
|
||||
{
|
||||
const string program = """
|
||||
program main;
|
||||
var a : integer;
|
||||
begin
|
||||
a := 1 + +1;
|
||||
a := 1 - -1;
|
||||
a := 1 + -1;
|
||||
a := 1 - +1;
|
||||
end.
|
||||
""";
|
||||
|
||||
CompilerHelpers.Analyse(program);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TrueFalseTest()
|
||||
{
|
||||
const string program = """
|
||||
program main;
|
||||
const a = true; b = false;
|
||||
var c, d : boolean;
|
||||
begin
|
||||
c := true;
|
||||
d := false;
|
||||
end.
|
||||
""";
|
||||
|
||||
CompilerHelpers.Analyse(program);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProcedureAndVariableTest()
|
||||
{
|
||||
const string program = """
|
||||
program main;
|
||||
begin
|
||||
test
|
||||
end.
|
||||
""";
|
||||
|
||||
CompilerHelpers.Analyse(program);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
using Canon.Core.Abstractions;
|
||||
using Canon.Core.Enums;
|
||||
using Canon.Core.Enums;
|
||||
using Canon.Core.Exceptions;
|
||||
using Canon.Core.GrammarParser;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
@@ -159,11 +159,6 @@ public class SimpleGrammarWithEmptyTests(ITestOutputHelper testOutputHelper)
|
||||
};
|
||||
|
||||
Grammar grammar = builder.Build();
|
||||
IGrammarParser parser = grammar.ToGrammarParser();
|
||||
|
||||
ITransformer transformer1 = parser.BeginTransformer;
|
||||
Assert.Equal(3, transformer1.ShiftTable.Count);
|
||||
Assert.Single(transformer1.ReduceTable);
|
||||
Assert.Contains(new NonTerminator(NonTerminatorType.ProgramStruct),transformer1.ShiftTable);
|
||||
Assert.Throws<ReduceAndShiftConflictException>(() => grammar.ToGrammarParser());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user