3 ms·
> Text parsing for programming languages is NOT a difficult problem. That depends entirely on 1) what grammar you're parsing, 2) what memory pressure you're in
by zeroxfe 10y ago
> Text parsing for programming languages is NOT a difficult problem.
That depends entirely on 1) what grammar you're parsing, 2) what memory pressure you're in, 3) how fast you want to do it, and 4) how comprehensive you want the error handling. It's actually quite difficult to parse C++ on a low-memory embedded device without resorting to clever techniques.
- wofo 10y ago> It's actually quite difficult to parse C++ This is a specific problem of C++ though, given the fact that its grammar is extremely complex.
- comex 10y agoI'm pretty curious what kind of project gave zeroxfe experience with parsing C++ on low-memory embedded devices.
- chubot 10y agoIt also depends on what functionality you want your parser to support. In theory, parsing just means "accept or reject". In practice, you need to do something like build a tree, and there are many different possible tree representations depending on what you want to do. Clang aims to support very general transformation of C++ with their parser and AST. I was shocked to learn that Clang's AST has 60K lines of header files! That's not including the code, and it's not templates! That's class definitions!!! (wc -l include/clang/AST/*.h)
- sklogic 10y agoThis is not because of a parsing complexity, it is only because C++ is an awful language for writing ASTs and parsers. Without all the boilerplate, an AST can be much smaller.
- sklogic 10y agoWhy would you parse C++ on a low memory device anyway? What are you going to do with it? Anything that follows the parsing would require far more memory.
- kazinator 10y agoIdeally, you don't even target a low-memory embedded device with C++, let alone process C++ on it. Anyway, C++ is just a strawman that seems to have been contrived deliberately in order to wreck most of the rational arguments defending "programming languages are easy to parse". Parsing as programming language is exactly as difficult as the hole we dig ourselves into. Programming language parsing isn't some information processing problem that exists in the world, or in another domain, that computer science is tasked with to solve; it's a problem that computer scientists and software people inflict on themselves. By making languages hard to parse by machine, we are also making them hard to use by humans. Humans need to parse the language also, and not have a magic oracle for doing so. (Indentation only goes so far, and can tell a lie). Still, there aren't actually difficult problems in parsing C++. It's more of a "death by a thousand blows". There is just the sheer size of it alone. The C++ parser source file in GCC is larger than some programming language implementations: their parsers, interpreters/compilers and all intrinsic routines combined. It's hard to comprehend the C++ grammar so that you can identify where the ambiguities lie, and form a strategy to deal with them, so as not to be surprised later.
- ksk 10y agoYou haven't said much, because you can say that about anything. "Drinking water from a glass is a hard problem when you have to drink it through this straw that is 1 mm wide and you're blindfolded" > It's actually quite difficult to parse C++ on a low-memory embedded device without resorting to clever techniques. Compiling C++ programs on low-memory embedded devices is not a mainstream use-case. Unless you can demonstrate that it is, your point is moot.