4 ms·
And Forth easier still.
by HumanDrivenDev 8y ago
And Forth easier still.
- kazagistar 8y agoIsn't forth actually a regular language, and parsable on a finite state machine?
- howerj 8y agoOn the contrary, it requires a Turing machine to parse fully.
- lisper 8y agoWhich is typically implemented in Forth. (The same is true of Common Lisp. But that in and of itself does not make it hard to parse.)
- howerj 8y agoYes it does, in fact it is pretty much the canonical definition of something being hard to parse. Given an arbitrary Forth program you can't even tell if the parser will terminate. Granted, the non-fixed grammar starts off simple, but it can be made to be arbitrarily complex.
- lisper 8y agoIMHO "hard to parse" means that writing a parser that works requires a lot of effort. In the case of both Forth and Lisp, that is not the case. Writing a working parser for either language is an elementary exercise, notwithstanding that the syntax can be arbitrarily extended by the user.
- howerj 8y agoYes...and far more accurately no, you can't actually write a parser for Forth with a fixed grammar, you can only write a complete interpreter for it as it is capable of modifying its own grammar on the fly. It is possible to define new words which when executed take over the input stream and do arbitrary things.
- kazinator 8y agoThose tricks will not necessarily compile right though. Forth is a compiled language, if implemented completely.
- howerj 8y agoThose tricks certainly are necessary to compile Forth, it's common to define words that create new words for custom data structure, which extend the grammar of Forth. Any time you use 'create ... does>' you are in effect extending the grammar in an ad-hoc way.