5 ms·
If parsing is "complicated", then there's another solution. Don't play the game. Change the rules. Play a different game. My understanding (and, since this is
by PhantomGremlin 8y ago
If parsing is "complicated", then there's another solution. Don't play the game. Change the rules. Play a different game.
My understanding (and, since this is the Interwebs I will quickly be corrected if I'm wrong) is that Python is easy to parse; a lot of the battles about adding features to the language involve keeping the grammar simple.
And yet Python is eminently useful, despite being simple to parse.
I'm reminded of how we didn't understand how to specify a simple grammar in the "good old days". E.g. take ancient FORTRAN.
The for-loop in FORTRAN is actually called do. And you specify the end of the loop by numerical statement label (found in columns 1 thru 5). Thus:
DO 10 I = 1, 7
some stuff here, loop done for I = 1,2,3,4,5,6,7
10 final line of loop
But spaces aren't significant. So if you write the following statement
DO 10 I = (1, 7)
You get something totally different. You set the value of the complex variable DO10I to (1,7). Bheech. Who wants to parse that? (And yet, there were very capable FORTRAN compilers back in the 1960s!)
- lisper 8y ago> Python is easy to parse Lisp is even easier.
- deleted 8y ago[deleted]
- HumanDrivenDev 8y agoAnd 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.