Programming Your Own Language in C++
accu.org
accu.org
1. Their definition of values in the language (unfortunately called "Variables") is a product (class) over all possible types:
class Variable {
...
double numValue;
string strValue;
vector<Variable> tuple;
string action;
string varname;
Constants::Type type;
};
This means each value at runtime has a large memory footprint, as each instance of a value contains slots for all possible types even though only one will ever be filled. Sum types solve this problem.2. The author intermixes parsing and code generation. This makes it difficult to implement any kind of optimizations, even for an interpreter. For example, in order to do function inlining in the author's language, you would have to manually inline calls in every single part of the code generator instead of having IR transformations as separate modules (see: LLVM). It also tightly couples the two pieces of the compiler, making it difficult to change parsing strategies without rewriting the code generator for instance.
3. It took the author nearly 5000 lines of C++ to write an interpreter for a simple Javascript-like scripting language. Some of this is due to the verbosity of C++, and some is due to the needless effort of reimplementing parsing from scratch. I implemented a similar language in <1k lines of Rust [1], and I'm sure that others could do even better in Haskell or OCaml. On top of that, the author's claimed benefit of extensibility requires writing large amounts of boilerplate.
http://web.archive.org/web/20160616053900/http://accu.org/in...
Strange advice given the state of LLVM on platforms such as windows. Both Swift and Crystal, LLVM based don't run on windows for instance. LLVM gives you more quickly but at the cost of portability.
Bottom-up parsers are nigh unreadable by mortals.
https://scholar.google.com/scholar?cluster=11340764028758422...
https://scholar.google.com/scholar?cluster=70305927860962254...
The ANTLR acronym is explained here and doesn't have anything to do with LR grammars: http://www.antlr.org/