4 ms·
I am not sure what you mean by context-free languages because literally none of the modern languages have context-free grammars. This includes HTML and XML alth
by zzless 4y ago
I am not sure what you mean by context-free languages because literally none of the modern languages have context-free grammars. This includes HTML and XML although I would not call them programming languages per se. C++ grammar is undecidable. On the other hand, TeX's core typesetting language (i.e. not using its macro facilities) is context-free. Quite trivial in fact. Pascal, which is the language used to build TeX is context-free (even LL(1)), as well, which cannot be said about, say, C.
I would also be quite hesitant to claim that Knuth, who literally pioneered modern LR parsing theory (and deservedly got a Turing award for it) somehow lacked knowledge or awareness of cutting edge parser design techniques.
Finally, there is absolutely good reasons to design TeX as Knuth did. That TeX withstood the test of time for over three decades is a perfect testimony to that.
- wrewrtet 4y agoAs someone who is intimidated by the thought of programming TeX, I think the following comment which asserts that it is badly designed seems unlikely to be coming out of nowhere. (MetaFont is apparently better than TeX) https://tex.stackexchange.com/a/602950 https://tex.stackexchange.com/a/602950 I'll quote the key part here in case that link stops working. > TeX has two programming systems, the "mouth" (which does macro expansion essentially) and the "stomach" (which typesets and does assignments). They run only loosely synchronised and on-demand. > For programming purposes, they are a pairing of a blind and a lame system since the "stomach" is not able to make decisions based on the value of variables (conditionals only exist in the "mouth") and the "mouth" is not able to affect the value of variables and other state. > While eTeX has added a bit of arithmetic facilities that can be operated in the mouth, as originally designed the mouth does not do arithmetic. There is a fishy hack for doing a given run-time specified number of iterations in the mouth that relies on the semantics of \romannumeral which converts, say, 11000 into mmmmmmmmmmm. > Because of the synchronisation issues of mouth and stomach, there is considerable incentive to get some tasks done mouth-only. Due to the mouth being lame and suffering from dyscalculia, this is somewhat akin to programming a Turing machine in lambda calculus. > TLDR: the programming paradigm of the TeX language is awful.
- zzless 4y agoThis description of TeX's process (originally by Knuth himself) is quite tongue in cheek but I fail to see why this makes TeX's programming paradigm 'awful'. Think of it this way: both C and C++ (even Rust has macros, which I heard is the new hotness) have a preprocessor, which is exactly what TeX's 'mouth' is. The fact that the language of the preprocessor looks very similar to the main language does not make it weird (Rust again...). 'Loosely synchronised and on demand' is a very uncharitable description of what is happening: would you call JavaScript paradigm awful just because events are asynchronously processed? One tricky part of TeX is output routines running asynchronously with the main paragraph typesetting algorithm. This is indeed a compromise made by Knuth simply because in his days the thought of keeping the whole book in memory (which is what a perfect page breaking algorithm would require) was pure science fiction. A mildly augmented design will fix this (indeed, some modern implementations offer exactly this) but the solution found by Knuth is still incredibly beautiful. Also, 'the mouth does not do arithmetic' is not true at all. While I am not a big fan of LaTeX, its developers are incredibly talented programmers and they have implemented a fully expandable (in TeX parlance, taking place entirely in its 'mouth') floating point library in TeX (it uses some eTeX extensions for efficiency but they can be avoided as well; I speak from experience, since I do not use eTeX). Finally, please do not let your fear stop you from enjoying TeX: most users do not do any serious programming and its output is aesthetically superb. If one day you decide to write some tricky macros, there is a vast TeXlore that awaits.
- teleforce 4y agoI'll probably try SILE just because it does not support macro. I personally think the adoption macro is the embodiment of non intuitive programming languages and why a modern programming languages, for example Rust is supporting macro is beyond me. I'm not alone in this regard, D a modern successor of C and C++ does not support macro. Hopefully one day Walter will write document on "Macro Considered Harmful" to enlighten the subject.
- zzless 4y agoI respect your stance (although I disagree strongly) but you might consider something other than Sile, as Chapter 6 of Sile's manual is called 'SILE Macros and Commands'. Also from reading about D, his strongest objection to using macros is that they do not respect the scope. This is probably the main source of macros' strength as code generators. Again, I respect your aversion to macros, I am not sure I understand the reasons, though.