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 {
|
[[nodiscard]] bool operator==(const List& in) const {
|
||||||
if (in == *this) { return true; }
|
if (&in == this) { return true; }
|
||||||
if (in.length() != length()) {
|
if (in.length() != length()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -253,6 +253,8 @@ namespace tp {
|
||||||
if (left->data != right->data) {
|
if (left->data != right->data) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
left = left->next;
|
||||||
|
right = right->next;
|
||||||
}
|
}
|
||||||
if (left != right) {
|
if (left != right) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ using namespace tp;
|
||||||
|
|
||||||
void CfGrammar::generateSentences(List<Sentence>& out) {
|
void CfGrammar::generateSentences(List<Sentence>& out) {
|
||||||
constexpr ualni maxTime = 1000;
|
constexpr ualni maxTime = 1000;
|
||||||
constexpr ualni maxSentences = 40;
|
constexpr ualni maxSentences = 200;
|
||||||
constexpr ualni maxQueue = 20000;
|
constexpr ualni maxQueue = 1000000;
|
||||||
|
|
||||||
List<Sentence> queue;
|
List<Sentence> queue;
|
||||||
Timer timer(maxTime);
|
Timer timer(maxTime);
|
||||||
|
|
@ -49,9 +49,19 @@ void CfGrammar::generateSentences(List<Sentence>& out) {
|
||||||
isSentence = false;
|
isSentence = false;
|
||||||
termIdx++;
|
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;
|
bool stop = false;
|
||||||
stop |= !queue.length();
|
stop |= !queue.length();
|
||||||
|
|
@ -63,7 +73,7 @@ void CfGrammar::generateSentences(List<Sentence>& out) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CfGrammar::printSentence(Sentence& in) {
|
void CfGrammar::printSentence(Sentence& in) {
|
||||||
printf("Sentence: [");
|
printf("[");
|
||||||
for (auto term : in.terms) {
|
for (auto term : in.terms) {
|
||||||
printf(" %s", term->id.read());
|
printf(" %s", term->id.read());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ namespace tp {
|
||||||
struct Term {
|
struct Term {
|
||||||
String id;
|
String id;
|
||||||
bool terminal;
|
bool terminal;
|
||||||
|
bool operator==(const Term& in) const {
|
||||||
|
return (id == in.id) && (terminal == in.terminal);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
List<Term> terms;
|
List<Term> terms;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,16 @@ This grammar wil produce text in the form: TODO
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* This is the starting production of the grammar */
|
/* This is the starting production of the grammar */
|
||||||
|
|
||||||
|
/* Simple Example
|
||||||
Start A
|
Start A
|
||||||
|
A : [ ID ] | &;
|
||||||
|
*/
|
||||||
|
|
||||||
/* Production rule */
|
/* Lists Example */
|
||||||
A : [ ID ] [ IS ] [ IDs ];
|
|
||||||
|
|
||||||
|
Start List
|
||||||
|
|
||||||
|
List : List Stm | Stm;
|
||||||
|
Stm : StmBody [ END ];
|
||||||
|
StmBody: [ Stm1 ] | [ Stm2 ] | [ Stm3 ];
|
||||||
|
|
|
||||||
12
TODO
12
TODO
|
|
@ -1,11 +1,13 @@
|
||||||
Testing !!
|
Testing !!
|
||||||
|
|
||||||
Objects:
|
Parser:
|
||||||
parsing:
|
CF Grammar:
|
||||||
make cf grammar
|
optimize generation of sentences
|
||||||
make lalr parser
|
check sanity
|
||||||
test all
|
|
||||||
|
|
||||||
|
impl parse machine
|
||||||
|
|
||||||
|
Objects:
|
||||||
features:
|
features:
|
||||||
add debug line information into bytecode
|
add debug line information into bytecode
|
||||||
implement Alloc Size queries
|
implement Alloc Size queries
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue