coal
or is there a benefit on having match as a object-dependent method instead of a static
coal
coal
yeah but i think you dont need to use new so much
coal
and it makes your code very vulnerable if you, for some reason, miss to delete something
coal
and it looks strange ngl
Anonymous
for example
https://gist.github.com/1301240b1b43614ad44b505b53af44f3
coal
yeah looks like pegtl
coal
all implementations of peg i've seen look like that, the worst probably being LPEG
Anonymous
yea, it is just… disorganized and unclean
it is difficult to tell if a rule has an action associated with it
and it is difficult to tell what rule an action belongs to, and in which grammar it is being used
also template strings are a macro mess
plus paramater packing and other stuff i do not like due to complexity
Anonymous
rule names can be a long tho due to the template thing, such as tao::pegtl::opt<tao::pegtl::skip<tao::pegtl::ascii::identifier_other> >
or tao::pegtl::plus<tao::pegtl::sor<GLSL_PREPROCESSOR::whitespaces, GLSL_PREPROCESSOR::function_call, GLSL_PREPROCESSOR::identifier, tao::pegtl::ascii::any>>
Anonymous
but it makes for an excellent Grammar debugger
coal
that's a very cool feature
coal
the one i mentioned earlier, LPEG
coal
i literally can't find any good point to use it, it's just a mess
Anonymous
in comparison to, for example, an LLDB backtrace
which is difficult to read
more difficult to determine which rule you are currrently in
where you are in your grammar
and how you got there
frame #7: 0x0000000100032e62 main`CPP::Rules::Sequence::match(this=0x0000608000001320, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:866:31
frame #8: 0x0000000100022430 main`CPP::Rules::RuleHolder::match(this=0x0000616000000d20, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:531:31
frame #9: 0x0000000100020467 main`CPP::Rules::Or::match(this=0x0000608000001420, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:815:34
frame #10: 0x0000000100022430 main`CPP::Rules::RuleHolder::match(this=0x000060e000001c90, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:531:31
frame #11: 0x0000000100020467 main`CPP::Rules::Or::match(this=0x00006080000014a0, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:815:34
frame #12: 0x000000010002af07 main`CPP::Rules::OneOrMore::match(this=0x00007ffeefbfdf20, iterator=0x00007ffeefbfc020, doAction=true) at Rules.h:730:64
frame #13: 0x000000010000a5b2 main`CPP::Rules::Rule::match(this=0x00007ffeefbfdf20, string="\nY(X)(z)\n#define foo(x) foo x\nfoo(z)\n", doAction=true) at Rules.h:276:24
frame #14: 0x000000010003ecc6 main`CPP::CPP::preprocess(this=0x00007ffeefbff540, input="\nY(X)(z)\n#define foo(x) foo x\nfoo(z)\n", data=0x00007ffeefbff540) at CPP.h:523:21
frame #15: 0x000000010000a063 main`CPP::CPP::preprocess(this=0x00007ffeefbff540, input="\nY(X)(z)\n#define foo(x) foo x\nfoo(z)\n") at CPP.h:52:13
frame #16: 0x000000010000568a main`CPP::CPP::parse(this=0x00007ffeefbff540, input="\nY(X)(z)\n#define foo(x) foo x\nfoo(z)\n") at CPP.h:535:13
frame #17: 0x000000010000546f main`main at main.cpp:95:9
coal
it tries to act like a metalanguage would do
coal
it attempts to look like EBNF would, but it simply looks horrible
coal
it's like a sodomized yacc grammar
Anonymous
yea
Anonymous
coal
coal
a lua implementation of PEG
Anonymous
coal
haha
doesnt it look beautiful
Anonymous
nope
coal
thanks for your honesty
Anonymous
kinda hurts my eyes lol
Anonymous
Anonymous
eg
TEST(Rules, at_test_pass) {
std::string a = "Hello World!";
CPP::Iterator<std::string> b(a);
EXPECT_TRUE(CPP::Rules::At(new CPP::Rules::Char('H')).match(b));
EXPECT_EQ(b.currentPosition(), 0);
EXPECT_EQ(b.peekNext(), 'H');
}
At automatically deletes Char when it gets destructed
Anonymous
coal
coal
fair
Anonymous
coal
yeah most likely
coal
does it recursively delete other members of itself as well
coal
for example, pointer class members
Anonymous
this is the rule holder https://gist.github.com/b414100f82dec3345c35259b4dcc44b5
Anonymous
Anonymous
it does not touch anything inside the Rule
coal
so, if you delete a Rule object that has a pointer member of another pointer instantiated with new
Anonymous
also if a RuleHolder contains another RuleHolder then yes it will “delete itself recursively"
coal
then the other pointer member becomes stranded and you have a memory leak
coal
Anonymous
eg
{
RuleHolder( // deleted when this goes out of scope
new RuleHolder( // deleted by above rule holder
new RuleHolder( // deleted by above rule holder
new Any() // deleted by above rule holder
)
)
)
// Any is still alive
}
// Any does not exist anymore
coal
coal
that explains it lol, very nice work
Anonymous
also
Rule * r;
{
r = new RuleHolder( // deleted when r is deleted
new RuleHolder( // deleted by above rule holder
new RuleHolder( // deleted by above rule holder
new Any() // deleted by above rule holder
)
)
)
// Any is still alive
}
// Any is still alive
delete r;
// Any does not exist anymore
olli
Anonymous
Anonymous
if an Action throws however, then it is up to the user to catch this
try {
grammar_that_throws.match(wrong_input);
} catch // …
or
my_action = [] (auto input) {
try {
function_that_throws();
} catch // …
olli
Anonymous
Anonymous
coal
coal
Anonymous
lmao
Anonymous
Anonymous
auto preprocessor_directive = new Rules::Sequence({
new Rules::Sequence({
new Rules::Char('#'),
optional_whitespaces,
new Rules::Or({
define
})
}, [&data](Rules::Input in) {
XOut << getTag(data) << ' ' << "erasing preprocessor statement: " << in.quotedStringRemoveCharactersFromEnd(1) << std::endl;
in.eraseAndRescan();
}),
reset_preprocessor_state
});
coal
fair
Chriss
Any C language expert here?
Who can solve a problem?
Find the sum of factorial of prime number upto N.
If you can do this in C, I have gift for you.
Chriss
Any C language expert here?
Who can solve a problem?
Find the sum of factorial of prime number upto N.
Solve the following equation:
2! +3! +5! +7! + 11! +13! + ……… +n!
Here, n is a prime number. n is to be taken input through keyboard.
If you can do this in C, I have gift for you.
Chriss
Please help me to fix this
coal
coal
and where's the gift
coal
lol
coal
Chriss
Check inbox
Abhanif
Done
Kadude
Pleasure
Clash
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> myvector{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (auto i = myvector.begin(); i != myvector.end(); ++i) {
if (*i % 2 == 0) {
myvector.erase(i);
i--;
}
}
for (auto it = myvector.begin(); it != myvector.end(); ++it)
cout << ' ' << *it;
return 0;
}
why this time complexity is O(n^2) ?
Hima
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> myvector{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (auto i = myvector.begin(); i != myvector.end(); ++i) {
if (*i % 2 == 0) {
myvector.erase(i);
i--;
}
}
for (auto it = myvector.begin(); it != myvector.end(); ++it)
cout << ' ' << *it;
return 0;
}
why this time complexity is O(n^2) ?
erase has a linear time complexity. Now, if you have to erase all the n elements , it becomes n*n
Clash