Re:What Does Haskell Have to Do with C++?
by dfox on Thursday November 25, 2010 @01:15PM
(#1940738)
In my view, these issues are not orthogonal, but related in exactly opposite way that article author allures to. At least when you view Common Lisp's syntax as simple (CL has same feature as Perl and TeX - only unambiguous and reliable way to parse it is to actually run it).
[ Parent
| on HN ]
Re:What Does Haskell Have to Do with C++?
by swolchok on Thursday November 25, 2010 @11:01PM
(#1941601)
A quick Google doesn't turn up any pages stating that parsing Perl and CL is undecidable. Can you provide a reference?
There is large difference between "undecidable" and "cannot be parsed without execution". It has to do with the fact that in each of these three cases the syntax can be modified by running code, and that execution is interleaved with parsing. In CL you can essentially add arbitrary right sides to few production rules of it's grammar, and also meaning of many tokens (symbols, numbers and differentiating between symbols and numbers) is dependent on runtime state of implementation which can be modified by code being parsed. In TeX you can partially alter rules of tokenization (by redefining character categories).
And in the TeX case it also depends on what you expect as output of parsing, if you want some meaningful AST, it is even more complex (and probably impossible). Because even if you would remove the ability to redefine character categories, you would still be able to only get stream of tokens without clear semantic meaning.
But whole this discussion is mostly theoretical, because for reasonable inputs (like LaTeX), parser can effectively guess. Also, in CL cases many of these problems are solved by various conventions (like having most of relevant state consistent for whole file and specified in comment that is readable by said tools).
I don't know about CL, but it is commonly believed that Perl cannot be parsed by anything except Perl. I'm not sure about the nuances between "undecidable" and "cannot be parsed without execution", but this page seems relevant:
Perl Cannot Be Parsed: A Formal Proof