Fixin cfg
This commit is contained in:
parent
01b7d96ebd
commit
7d49642376
2 changed files with 12 additions and 3 deletions
|
|
@ -13,11 +13,13 @@ void run(const String& source) {
|
|||
|
||||
if (!grammar.parse(state, source)) {
|
||||
printf("Parsing is failed\n");
|
||||
CfGrammar::deinitializeCfGrammarParser(state);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!grammar.compile()) {
|
||||
printf("Compilation is failed\n");
|
||||
CfGrammar::deinitializeCfGrammarParser(state);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -41,6 +43,12 @@ int main(int argc, const char* argv[]) {
|
|||
}
|
||||
|
||||
{
|
||||
printf("Arguments given: ");
|
||||
for (auto idx = 0; idx < argc; idx++) {
|
||||
printf("[%s]", argv[idx]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
CommandLine cmd = {
|
||||
{ "grammar", CommandLine::Arg::STR },
|
||||
};
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ void CfGrammar::generateSentences(List<Sentence>& out) {
|
|||
auto appendTerm = copy->terms.findIdx(termIdx);
|
||||
auto deleteTerm = appendTerm;
|
||||
for (auto arg : production->args) {
|
||||
if (arg->isEpsilon) continue;
|
||||
auto newTerm = copy->terms.newNode({ arg->id, arg->isTerminal });
|
||||
copy->terms.attach(newTerm, appendTerm);
|
||||
appendTerm = newTerm;
|
||||
|
|
@ -62,11 +63,11 @@ void CfGrammar::generateSentences(List<Sentence>& out) {
|
|||
}
|
||||
|
||||
void CfGrammar::printSentence(Sentence& in) {
|
||||
printf("Sentence:");
|
||||
printf("Sentence: [");
|
||||
for (auto term : in.terms) {
|
||||
printf(" %s", term->id.read());
|
||||
}
|
||||
printf("\n");
|
||||
printf(" ]\n");
|
||||
}
|
||||
|
||||
bool CfGrammar::compile() {
|
||||
|
|
@ -103,7 +104,7 @@ bool CfGrammar::compile() {
|
|||
|
||||
if (arg->isTerminal) {
|
||||
mTerminals.put(rule->id, {});
|
||||
} else {
|
||||
} else if (!arg->isEpsilon) {
|
||||
auto idx = mNonTerminals.presents(arg->id);
|
||||
if (!idx) {
|
||||
printf("Referenced non-terminal '%s' is not defined\n", arg->id.read());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue