Compute FIRST sets correctly
This commit is contained in:
parent
4cacdcba70
commit
29f73afbc5
5 changed files with 108 additions and 9 deletions
38
spec/compiler/build_tables/next_symbols_spec.cpp
Normal file
38
spec/compiler/build_tables/next_symbols_spec.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include "spec_helper.h"
|
||||
#include "build_tables/next_symbols.h"
|
||||
#include "grammar.h"
|
||||
#include "rules.h"
|
||||
|
||||
using std::set;
|
||||
using namespace build_tables;
|
||||
using namespace rules;
|
||||
|
||||
START_TEST
|
||||
|
||||
describe("computing FIRST sets", []() {
|
||||
Grammar grammar({
|
||||
{ "A", choice({
|
||||
seq({
|
||||
sym("B"),
|
||||
sym("x"),
|
||||
sym("B") }),
|
||||
sym("B") }) },
|
||||
{ "B", choice({
|
||||
seq({
|
||||
sym("y"),
|
||||
sym("z"),
|
||||
sym("y") }),
|
||||
sym("y") }) },
|
||||
});
|
||||
|
||||
describe("for a rule", [&]() {
|
||||
it("searches the tree for terminals", [&]() {
|
||||
auto terminals = next_terminals(grammar.rules.find("A")->second, grammar);
|
||||
AssertThat(terminals, Equals(set<Symbol>({
|
||||
Symbol("y")
|
||||
})));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
END_TEST
|
||||
Loading…
Add table
Add a link
Reference in a new issue