Fixing list copy and grammar sentence generation
This commit is contained in:
parent
43fe34dcbf
commit
0a886bd8a8
5 changed files with 38 additions and 13 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ using namespace tp;
|
|||
|
||||
void CfGrammar::generateSentences(List<Sentence>& out) {
|
||||
constexpr ualni maxTime = 1000;
|
||||
constexpr ualni maxSentences = 40;
|
||||
constexpr ualni maxQueue = 20000;
|
||||
constexpr ualni maxSentences = 200;
|
||||
constexpr ualni maxQueue = 1000000;
|
||||
|
||||
List<Sentence> queue;
|
||||
Timer timer(maxTime);
|
||||
|
|
@ -49,9 +49,19 @@ void CfGrammar::generateSentences(List<Sentence>& 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<Sentence>& out) {
|
|||
}
|
||||
|
||||
void CfGrammar::printSentence(Sentence& in) {
|
||||
printf("Sentence: [");
|
||||
printf("[");
|
||||
for (auto term : in.terms) {
|
||||
printf(" %s", term->id.read());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Term> terms;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 ];
|
||||
|
|
|
|||
12
TODO
12
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue