7 ms·
A language's grammar wouldn't necessarily be a good indicator of implementation size, would it?
by baddox 15y ago
A language's grammar wouldn't necessarily be a good indicator of implementation size, would it?
- groovy2shoes 15y agoNot necessarily. Some grammars can be parsed with simpler code than others, but optimizations can make a compiler larger. Also of note is that Turbo Pascal was written by hand in assembly language, and the executable wasn't likely to have been linked with any libraries.
- MatthewPhillips 15y agoInteresting, I didn't know this but Turbo Pascal was written by Anders Hejlsberg (of Delphi and C# fame).
- bhangi 15y agoIndeed TP did not have any linking step. I still recall trying to fruitlessly find "Link" on the menu for quite some time until it hit me -- oh, no linking needed. But TP did include a run-time with each of the generated executable. This run-time was part of the compiler and it was approximately 10K (from memory, so I could be wrong). That makes the compiler about 22Kbytes worth of code, which is even more impressive.
- groovy2shoes 15y agoI wasn't aware that the runtime was included in the executable. Oh, the things we did in the DOS days!
- barrkel 15y agoPascal's grammar is so simple by design that it can be parsed and codegenned in a single recursive descent pass. Not many languages are like that, especially these days.
- tluyben2 15y agoThere are a billion Lisp parsers in a few lines of Python, C, Lisp, etc. Any Pascal ones like that? Edit; not meant sarcastic, I would really like to see such a simple parser as was implied.
- colanderman 15y ago"parsed and codegenned" he said. Any Lisp compilers like that?
- groovy2shoes 15y agoI believe that's how the Clojurescript compiler currently works (though I haven't looked at the code in detail). Compilers that don't do it that way usually have optimizations going on in between the parse and codegen phases, not because it's impossible to do with Lisp syntax.
- fogus 15y agoClojureScript has a two-pass compiler; more if you consider GClosure a step.
- xyzzyz 15y ago"because it's impossible to do with Lisp syntax." The problem is not with Lisp syntax. The problem is with Lisp's semantics, which makes it much more difficult (if at all possible) to compile in one pass. Things like closures, conditions or macros are absent in Pascal.
- ajross 15y agoNo, but only by definition. Passing through an s-expression representation is a requirement for a lisp compiler, because the tree to be compiled might have been built at runtime. Certainly lisp's grammar is no more complicated than pascal's. Nor, frankly, is K&R C, which is is also a very simple representation. The ANSI process added some edge cases that complicated it, but really it's pretty simple.
- skeptical 15y agoYes it would. Not a bullet proof one (is there any?) but a good indicator.