parent
e773e666ae
commit
f1c569ee0e
|
@ -109,9 +109,7 @@ public static class PascalGrammar
|
||||||
Terminator.NumberTerminator,
|
Terminator.NumberTerminator,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
new Terminator(DelimiterType.SingleQuotation),
|
|
||||||
Terminator.CharacterTerminator,
|
Terminator.CharacterTerminator,
|
||||||
new Terminator(DelimiterType.SingleQuotation),
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,6 @@
|
||||||
using Canon.Core.Abstractions;
|
using Canon.Core.Abstractions;
|
||||||
|
using Canon.Core.Enums;
|
||||||
|
using Canon.Core.GrammarParser;
|
||||||
using Canon.Core.LexicalParser;
|
using Canon.Core.LexicalParser;
|
||||||
using Canon.Core.SyntaxNodes;
|
using Canon.Core.SyntaxNodes;
|
||||||
using Canon.Tests.GeneratedParserTests;
|
using Canon.Tests.GeneratedParserTests;
|
||||||
|
@ -25,4 +27,54 @@ public class PascalGrammarTests
|
||||||
ProgramStruct root = _parser.Analyse(tokens).Convert<ProgramStruct>();
|
ProgramStruct root = _parser.Analyse(tokens).Convert<ProgramStruct>();
|
||||||
Assert.Equal("DoNothing", root.Head.ProgramName.LiteralValue);
|
Assert.Equal("DoNothing", root.Head.ProgramName.LiteralValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AddTest()
|
||||||
|
{
|
||||||
|
const string program = """
|
||||||
|
program Add;
|
||||||
|
var a : Integer;
|
||||||
|
begin
|
||||||
|
a := 1 + 1
|
||||||
|
end.
|
||||||
|
""";
|
||||||
|
|
||||||
|
Lexer lexer = new(program);
|
||||||
|
List<SemanticToken> tokens = lexer.Tokenize();
|
||||||
|
tokens.Add(SemanticToken.End);
|
||||||
|
|
||||||
|
ProgramStruct root = _parser.Analyse(tokens).Convert<ProgramStruct>();
|
||||||
|
Assert.Equal("Add", root.Head.ProgramName.LiteralValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WriteLnTest()
|
||||||
|
{
|
||||||
|
const string program = """
|
||||||
|
program exFunction;
|
||||||
|
const str = 'result is : ';
|
||||||
|
var a, b : Integer;
|
||||||
|
begin
|
||||||
|
writeln( str, ret );
|
||||||
|
end.
|
||||||
|
""";
|
||||||
|
|
||||||
|
Lexer lexer = new(program);
|
||||||
|
List<SemanticToken> tokens = lexer.Tokenize();
|
||||||
|
tokens.Add(SemanticToken.End);
|
||||||
|
|
||||||
|
ProgramStruct root = _parser.Analyse(tokens).Convert<ProgramStruct>();
|
||||||
|
Assert.Equal("exFunction", root.Head.ProgramName.LiteralValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GrammarParserBase GenerateGrammarParser()
|
||||||
|
{
|
||||||
|
GrammarBuilder builder = new()
|
||||||
|
{
|
||||||
|
Generators = PascalGrammar.Grammar, Begin = new NonTerminator(NonTerminatorType.StartNonTerminator)
|
||||||
|
};
|
||||||
|
|
||||||
|
Grammar grammar = builder.Build();
|
||||||
|
return grammar.ToGrammarParser();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user