Live data from Hacker News

Ask HN: What's a starting point for learning how to write programming languages?

news.ycombinator.com

81–90 of 105 posts

Re: Ask HN: What's a starting point for learning how to write programming languages?

#81
IMO, The best example of designing and implementing a "small" language can be seen in Chapter 8 of "The Unix Programming Environment by Kernighan & Pike" where they walk you through the construction of "hoc" (higher order calculator) using the standard compiler construction tools. The example is realistic, not too small nor too big and every step is explained. The exposition is very clear and you really can "get" how languages are designed and implemented. This should be the first thing you should read :-)

If you have a specific problem, you can then write a small DSL for it. I once had the opportunity to write a small "test language" for the sub-protocols of H.323. These protocols are specified using SDL (https://en.wikipedia.org/wiki/Specification_and_Description_...) and i just converted the tokens in the spec directly into my language and put a simple markdown syntax around it. The tests simply exercise the protocol FSM.

Eg:

   
      
         
            Var1=Val1         //these are assignments
            Var2=Val2
         
         
            MsgFromNetwork=  //trigger to FSM
         
         
             Var1=Val1.1       //these are assertions
             Var2=Val2.1
         
      
   
Though simple, this worked nicely, allowing me to push off the actual writing of the test cases to non-programmers who just had to convert the SDL diagrams from the spec. to text as given above.

Re: Ask HN: What's a starting point for learning how to write programming languages?

#82

Although its still in development, http://craftinginterpreters.com/ (previously on HN https://news.ycombinator.com/item?id=13406081 ) seems promising, and the existing content is good.

I'm not super far in but I'm very happy with it so far. I recommend it very highly and am very skeptical of anyone recommending reading the dragon book without doing something more hands on like this first.

Maybe that book is more practical than I realize though.

Re: Ask HN: What's a starting point for learning how to write programming languages?

#83
Hello There, i use the netflix app in my computer it was good but there are showing problems now the app is not working properly i want to solve this issue but how do i solve it i need to help you please suggest me so that i can use this app again.

Thanks Janice Rivera

https://www.netflix-activate.xyz

Re: Ask HN: What's a starting point for learning how to write programming languages?

#84
Lots of great advice here. In addition to "use prolog" and "play with ometa/ohm" - you might want to consider looking at a ML - like ocaml (used for bootstrapping rust) or standard ml, sml.

Another approach is to look at rpy - the restricted python subset used for pypy, see for example "other languages" on:

https://www.pypy.org/features.html

Re: Ask HN: What's a starting point for learning how to write programming languages?

#85
I bet this is what you are looking for: https://www.amazon.com/Compiler-Construction-Using-Java-Java...

This book taught me how to write a compiler and build a programming language of my own.

To answer you question "where and how did you start?": This is where I started learning about compilers and programming language implementation.

Here is its description from its website:

* Comprehensive treatment of compiler construction.

* JavaCC and Yacc coverage optional.

* Entire book is Java oriented.

* Powerful software package available to students that tests and evaluates their compilers.

* Fully defines many projects so students can learn how to put the theory into practice.

* Includes supplements on theory so that the book can be used in a course that combines compiler construction with formal languages, automata theory, and computability theory.

What I promise you with this book: You'll learn how to write your own programing language. Not only how compilers and about the language but also about computer architecture. This book is very easy to read and understand. It starts with very basic topics then slowly building from it until you'll grok implementing the language given the specification. You'll have the chance to build a compiler from scratch or by using JavaCC and Yacc.

Re: Ask HN: What's a starting point for learning how to write programming languages?

#86
languages.. are everywhere. You keep making them even if you do not notice. Say, a function with 3 arguments is a small language.. just missing all the fuss, checks and generality. A repeating data structure that feeds some switch-decision tree is another language.. implicit one, essentialy the code is an interpreter.

But it's much better to make languages explicit. And there's no need to invent new grammars and parsers.. keep those for real extreme cases.

i express my languages in python, its easiest to use as base and build semantics on top (and even syntax). One can just use function/class-based declarations, of domain-specific notions, and then interpret them any way one wants. Or one can even turn function-calls into "statements", and "with"-construct into "blocks-of-statements", etc. Gives you strict debuggable proto-syntax, on which to build your own "syntax"/semantics/error-checking/reporting.

but any way, try to see/feel the Language behind the syntax/implementation. have fun

Re: Ask HN: What's a starting point for learning how to write programming languages?

#87

Learn the mechanics of compiler construction first - that'll inform everything about your language, and is a prerequisite to actually building something other people can use. I'd recommend The Dragon Book [1], SICP [2], and Modern Compiler Implementation in ML [3] for this. After that, it's a question of where you want to go with your language, and what distinguishing features you'd like it to have relative to other…

> Languages which just change some syntax and keywords but otherwise look like C are common, but they tend not to get usage beyond their creators

Considering c++ is one of the most widely-used languages out there, I would question this.

Re: Ask HN: What's a starting point for learning how to write programming languages?

#88

Others have already mentioned various resources for learning the details of implementing a language. As someone who does programming language development as a hobby and PL technology as a career, I have a higher-level bit of advice: Take a top-down approach, and focus on semantics over syntax. If you want to design a new language, think of a moderately sized representative example of a problem you have day-to-day, an…

Thanks for your reply! Although I (think) I usually go about programming by starting small, and then adding features as they are needed. It never occurred to me, for some reason, I could do the same in this case. By reading the other replies I think a combination of starting small and using a couple of "how to"-links and books as a reference will be my best bet.

Re: Ask HN: What's a starting point for learning how to write programming languages?

#89

For many people, and I include myself in that group, the class in compiler and language design is where all of the concepts being taught in CS came together into a bigger and more rich picture. A common observation that it was like learning "how" music was written rather than just "playing" music. That said, everyone who learns to program usually learns more than one language. For me, it was after about the fifth lan…

Thanks for your reply! As a musician myself I like your analogy. It was a huge revelation for me when I learned how to write my own music, and I also started to "consume" music in a completely different way. I also sort of hope that the same will happen with my programming, taking it to the next level.

Re: Ask HN: What's a starting point for learning how to write programming languages?

#90
What helped me understanding computers more as well, is fiddling with arduino C and in extension build electrical circuits. Computers become more and more advanced, but in the end it's still an electrical circuit.

Things like loops and memory management, become pretty doh, when you learn about shift registers, and current applied to a gate on a transistor on/off.

Programming languages when becoming more abstract, become less computer like. Learning a high level language is good to learn programming, but in a way it also takes away from understanding a transistor based computer (ie. basically all computing devices on the consumer market today).

When you ask someone how to drive a car "turn the key and hit the pedals", this is abstract modern language.

The reality is, you turn a key, electrical circuit engages a spark, igniting the fuel, which then moves valves, which through gears move an axel, which then transfers energy to the wheels, which makes the vehicle propel.

This is not absolute, but I hope u get the point in different mindset.

I would learn (a bit of) C, before going into assembly, just to get a feel for the fact computers are "dumb" in nature at the hardware level.

All the abstract stuff like map functions and fancy constructs like async behavior is great for productivity, but is just really fancy juggling of very basic structures and basic imperative operations.

Post reply on HN