diff --git a/Containers/public/List.hpp b/Containers/public/List.hpp index e80b50c..26ab926 100644 --- a/Containers/public/List.hpp +++ b/Containers/public/List.hpp @@ -243,7 +243,7 @@ namespace tp { } [[nodiscard]] bool operator==(const List& in) const { - if (in == *this) { return true; } + if (&in == this) { return true; } if (in.length() != length()) { return false; } @@ -253,6 +253,8 @@ namespace tp { if (left->data != right->data) { return false; } + left = left->next; + right = right->next; } if (left != right) { return false; diff --git a/Parser/private/CfGrammar.cpp b/Parser/private/CfGrammar.cpp index 4b6d82d..f23ac40 100644 --- a/Parser/private/CfGrammar.cpp +++ b/Parser/private/CfGrammar.cpp @@ -8,8 +8,8 @@ using namespace tp; void CfGrammar::generateSentences(List& out) { constexpr ualni maxTime = 1000; - constexpr ualni maxSentences = 40; - constexpr ualni maxQueue = 20000; + constexpr ualni maxSentences = 200; + constexpr ualni maxQueue = 1000000; List queue; Timer timer(maxTime); @@ -49,9 +49,19 @@ void CfGrammar::generateSentences(List& out) { isSentence = false; termIdx++; } - if (isSentence) out.pushBack(*sentential); - queue.popFront(); + if (isSentence) { + auto exists = false; + for (auto iter : out) { + if (iter->terms == sentential->terms) { + exists = true; + break; + } + } + if (!exists) out.pushBack(*sentential); + } + + queue.popFront(); bool stop = false; stop |= !queue.length(); @@ -63,7 +73,7 @@ void CfGrammar::generateSentences(List& out) { } void CfGrammar::printSentence(Sentence& in) { - printf("Sentence: ["); + printf("["); for (auto term : in.terms) { printf(" %s", term->id.read()); } diff --git a/Parser/public/CfGrammar.hpp b/Parser/public/CfGrammar.hpp index f8b650e..391b250 100644 --- a/Parser/public/CfGrammar.hpp +++ b/Parser/public/CfGrammar.hpp @@ -22,6 +22,9 @@ namespace tp { struct Term { String id; bool terminal; + bool operator==(const Term& in) const { + return (id == in.id) && (terminal == in.terminal); + } }; List terms; }; diff --git a/Parser/rsc/grammar.txt b/Parser/rsc/grammar.txt index 554b086..fe82820 100644 --- a/Parser/rsc/grammar.txt +++ b/Parser/rsc/grammar.txt @@ -5,8 +5,16 @@ This grammar wil produce text in the form: TODO */ /* This is the starting production of the grammar */ + +/* Simple Example Start A +A : [ ID ] | &; +*/ -/* Production rule */ -A : [ ID ] [ IS ] [ IDs ]; +/* Lists Example */ +Start List + +List : List Stm | Stm; +Stm : StmBody [ END ]; +StmBody: [ Stm1 ] | [ Stm2 ] | [ Stm3 ]; diff --git a/TODO b/TODO index a8767fb..758f6a7 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,13 @@ Testing !! -Objects: - parsing: - make cf grammar - make lalr parser - test all +Parser: + CF Grammar: + optimize generation of sentences + check sanity + impl parse machine + +Objects: features: add debug line information into bytecode implement Alloc Size queries