News for hackers. Stuff that matters.
Re:So you want to be a compiler wizard (2016) by smabie on Sunday April 12, 2020 @03:07PM (#22850365)
Here's a valuable tip for making a compiler/interpreter: don't use a separate lexer and parser like lex and yacc. Parser combinators (also known as parser monads) are so much easier to use. In fact, if you already have decided upon your language's grammar, you can probably write yourself a parser and lexer with a parser combinator inside a day.
Re:So you want to be a compiler wizard (2016) by tanin on Sunday April 12, 2020 @11:43PM (#22853003)
Yes! I find that writing a parser by hand (using parser combinator) is the most straightforward way (once you know how to write one).

It can also support variable-length lookahead, which is really nice.

Re:So you want to be a compiler wizard (2016) by millstone on Sunday April 12, 2020 @06:47PM (#22851572)
This is going to be language-specific: parser combinators are much more pleasant in Haskell than in C++ for example.

Handwritten recursive descent has a lot going for it, error messages in particular.

Re:So you want to be a compiler wizard (2016) by orbifold on Sunday April 12, 2020 @09:39PM (#22852348)
There is a pretty nice parser combinator library in the capnproto compiler: https://github.com/capnproto/capnproto/tree/master/c%2B%2B/s.... Here is an example of how it is used: https://github.com/capnproto/capnproto/blob/950d23a13f1d602d...
Re:So you want to be a compiler wizard (2016) by saagarjha on Monday April 13, 2020 @12:50AM (#22853267)
They're not too bad in C++; I'm writing one.
Re:So you want to be a compiler wizard (2016) by popotamonga on Sunday April 12, 2020 @04:46PM (#22850917)
How easier are they? I did the lex and yacc for javascript and it was easy (except parsing js's // regex format in lex needed a little hack)
Re:So you want to be a compiler wizard (2016) by smabie on Monday April 13, 2020 @12:39AM (#22853223)
The easiest. Much much easier than lex and yacc.
Re:So you want to be a compiler wizard (2016) by amelius on Sunday April 12, 2020 @05:53PM (#22851274)
What is the class of grammar they can handle? (I mean in the sense of LALR(k), LL(k), etc.)

And is there a large (e.g. exponential) performance penalty for large lookahead?

Re:So you want to be a compiler wizard (2016) by tanin on Sunday April 12, 2020 @11:46PM (#22853009)
There's still "lookahead" in a hand written parser. The lookahead is decided case by case.

Performance penalty only comes if we backtrack in our hand written parsers. I don't think we usually do that.

Any glimpse of top-down parser would be simply too slow.

Re:So you want to be a compiler wizard (2016) by samatman on Sunday April 12, 2020 @04:43PM (#22850911)
Agreed, and this goes even smoother when one realizes the isomorphism between (naive) parser combinators and parsing expression grammars.