249 karma · joined April 24, 2009
[1] http://akrzemi1.wordpress.com/2011/05/06/compile-time-comput...
constexpr tuple<double, double> Roots(double a, double b, double c)
{
return (a == 0.0) ? throw invalid_argument("a has value 0.0!") :
tuple<double, double>{
(-b + (sqrt((b * b) - 4 * a * c))) / 2*a,
(-b - (sqrt((b * b) - 4 * a * c))) / 2*a
};
}[1] http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussma...
string s;
for (;;)
{
read_string(s);
if (s.len() <= 5)
break;
//do something
}I'm doomed.
Funny to read this example since Twitter used to be named "Twttr"! I guess they understood the problem soon enough!
A great benefit of PEGs is that I can easily reason about how the parsing will be done as I write the grammar, which will be the same if it's done by the compiler or by the programmer in his head!
Those who say that the ambiguities still exist when using PEGs say so because they still reason in terms of CFGs. There is no ambiguity in PEGs, period. If the language is defined in terms of PEGs, there's no worry about that, as long as the reader of the language spec understands about prioritized choices.
[1]: http://blog.c3lang.org/aims-and-rules-of-thumb-for-the-desig...