4 ms·
Ask HN: How fast could you create a programming language?
As a thought experiment, would it be possible to create a new programming language and teach at least one other person to use it within a week or so.
This hypothetical language needs to support concurrency, networking ( a simple HTTP get request is fine) and IO ( nothing insane, just write a text file and read it back).
Also I'd love to see real life examples of this. Have any of you created a new programming language ?
- zaphar 5y agoIf I can implement it as an AST Walking interpreter, Have the syntax be lisp, and leverage most of the runtime of the language I write it in I could produce something in a week and probably teach them to use it for some definition of use as well. Would it be polished? no. Would it have really good well defined semantics for everything that I might want it to? no. But within those constraints I could probably do it.
- Someone 5y agoApart from the concurrency (but even that could be simplified, I think, by effectively forbidding data sharing), I think it isn’t hard to design and implement such a language. For example, on today’s hardware it’s easy to write an interpreter for the early microcomputer Basics (only globals, no user-defined functions, at most 26 integers and 26 strings) You could make it even simpler by not allowing complex expressions. Why allow a = b + c / (d + e) when a = d + e a = c / a a = b + a works fine, too? Also, if parsing that is too difficult, require users to write that as, for example = a + d e = a / c a = a + b a or, forth-like d e + a= c a / a= b a + a= Not ideal? Likely, but teachable to at least one other person? Definitely. As to others doing something like this: Brendan Eich wrote the first (limited) running version of JavaScript in 10 days.
- 999900000999 5y agoDo you have any good resources on how compliers actually work ? I imagine most of the work is in creating the complier,you could just fork the base language add enough features to it. This is a gross oversimplification, but I believe that was the original idea for c++, right?
- Someone 5y agoWho’s talking compiler? An interpreter typically is a bit easier. If you don’t want utmost speed, compilers can be easy, too, though. For version one, forget about what the textbooks say about separating tokenizing from parsing from optimizing from code generation, and just eagerly emit assembly instructions as soon as you reasonably can. Don’t worry about short or long branches, use only one or two registers, give each local its own place on the stack, even if they could use the same location, don’t keep intermediates in registers (so “a = a + 2 b; a = a + 1”* could compile to “load b, load 2, multiply, add a, store a, load a, load 1, add, store a”, without even attempting to remove the redundant “store a, load a” pair or without using inc instead of ”load 1; add” those are for version 2) etc. If you pick the right language, you can generate the code in a single pass, possibly with some after-the-fact patching to fill in jump targets. Pascal is famous for that (modules define types and functions before they are used, so when you encounter a function name, you can immediately check whether their arguments are of the correct types, and then generate the function call)
- mikewarot 5y agoLong ago, Jack Crenshaw wrote this series[1] about creating a Pascal recursive descent compiler from scratch. I wrote a working pascal compiler from that, back in the day. Similar tutorials exist for many other languages. 1 - https://compilers.iecc.com/crenshaw/ https://compilers.iecc.com/crenshaw/ What do you want to do that existing programming languages can't do?