Re:Let's write a compiler, part 3: A parser
by chrisseaton on Monday August 16, 2021 @01:27PM
(#28200601)
Fundamentally I don't think parsing is a problem that's complex enough to warrant a custom tool and language. And even if it was Yacc is the wrong tool for the job in most cases.
Since most languages are context-sensitive, you almost always have to bend Yacc, which is designed for context-free languages, out of shape to apply it.
It's a hammer but we hardly have any nails, and the nails can just be pushed in by hand without a hammer, and they're the wrong type of nails anyway so that hammer isn't really compatible, and top of that it's a really expensive hammer.
Re:Let's write a compiler, part 3: A parser
by rightbyte on Monday August 16, 2021 @02:28PM
(#28201230)
Isn't the context sensitivity handled when you build an AST with the action statements in Yacc?
Re:Let's write a compiler, part 3: A parser
by chrisseaton on Monday August 16, 2021 @02:32PM
(#28201274)
Yes - so straight away you have to leave the DSL and bypass the formal mode of Yacc. At which point why bother with it? If the first thing you need to do with your tool is hack around it, maybe the tool isn’t so well-designed?
And actions often do things like side-effect changes to the lexer state, so it gets worse from there.
What few seem to realize is that it's perfectly possible to abstract out some of the work and create an extensible foundation for manual parsers.
Since it's all regular code, you can use the full power of the host language to deal with the problem.
https://github.com/codr7/swifties/blob/main/Sources/Swifties...
I understand that, but I still find it easier to write/maintain/extend a grammar than a parser for that grammar.
Re:Let's write a compiler, part 3: A parser
by brundolf on Monday August 16, 2021 @02:30PM
(#28201259)
If you've got the right utility functions, a handwritten parser visually maps very directly to its grammar. It won't be as concise of course, but cognitively you can work with it almost as if it were just a grammar.
What are the arguments in favor of manually writing parsers?