2 ms·
Don't forget function templates! D can do them, too, but we strongly discourage their use. The trouble is that people use them to create DSLs that are indisting
by WalterBright 4y ago
Don't forget function templates! D can do them, too, but we strongly discourage their use. The trouble is that people use them to create DSLs that are indistinguishable from C++ code. For example:
#include <boost/spirit.hpp>
using namespace boost;
int main() {
spirit::rule<> group, fact, term, expr;
group = '(' >> expr >> ')';
fact = spirit::int_p | group;
term = fact >> *(('*' >> fact) | ('/' >> fact));
expr = term >> *(('+' >> term) | ('-' >> term));
assert( spirit::parse("2*(3+4)", expr).full );
assert( ! spirit::parse("2*(3+4", expr).full );
}
https://studylib.net/doc/10029968/text-processing-with-boost---northwest-c---users--group https://studylib.net/doc/10029968/text-processing-with-boost... slide 40
What's C++ and what's regex?
- xigoi 4y agoAren't these just normal parser combinators?
- WalterBright 4y agoA >> means right shift, except when it doesn't in the example.
- eru 4y agoWell, the problem here is the re-use of existing operators. (That's why it's great that Haskell and other languages in that family allow you to define your own operators, instead of eg re-using bit-shifting for IO.)
- WalterBright 4y agoDefining your own operators means combining the lexer with the semantic analysis, which comes with all sorts of complexities.
- eru 4y agoActually, no. At least the way it's handled in Haskell and OCaml avoids this problem. (Btw, parsing C++ is already Turing complete.)
- xigoi 4y agoYes, obviously operations with parser combinators are different that those with numbers. (Also, I find it kind of dumb to reserve short symbols for low-level operations that are rarely used in normal programming.)