Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have this "meta-language" rant brewing for my blog[1], and I feel like you took the words out of my mouth!

Are you saying that ANTLR makes some unwarranted assumptions about Unicode? Does that just depend on the generated Java code, and would it be different for generated parsers in C++? I don't know the JVM very well, but my understanding was that the JVM makes some Unicode assumptions that aren't always appropriate.

The last "rant" was here, about meta-languages only being suitable for toys: https://news.ycombinator.com/item?id=13040682

vidarh also responds with his problems parsing Ruby (a "real" language): http://hokstad.com/compiler

The blog is based on my experience in writing a parser for bash. I ported the POSIX shell grammar to ANTLR, but it fell ridiculously short of being a production quality parser.

I believe it's essentially impossible to write a bash parser with ANTLR. But I don't hear about any alternatives. All I heard is yacc/bison for bottom up parsers, and ANTLR for top-down. Shell needs a top-down parser because it's an interactive language (the PS2 prompt) and for completion. But it doesn't appear there is any other "serious" meta-language for top-down parsers other than ANTLR? It certainly is the best documented and longest-lived, but I am surprised how far short it falls for many tasks.

Part of the rant will be a survey of "real" language parsers (i.e. take the top 20 TIOBE language implementations) and see that they almost all use hand-written parsers, or bespoke parser generators. For example, Python has its own top-down parser generator in the tree, pgen.c.

[1] http://www.oilshell.org/blog/2016/11/20.html



> it doesn't appear there is any other "serious" meta-language for top-down parsers other than ANTLR?

Have you explored Perl 6 and its Rules sub-language and engine?[1] The Rakudo Perl 6 compiler is written in Perl 6 using Rules.[2]

[1] https://en.wikipedia.org/wiki/Perl_6_rules

[2] https://github.com/rakudo/rakudo/blob/nom/src/Perl6/Grammar.....


I have heard of this feature of Perl 6, but not used it. One obvious difference is that ANTLR is language-agnostic in that you can generate parsers in C++ or Python too, while I assume Perl 6 doesn't have that functionality. So that limits its appeal.

(Although honestly ANTLR is pretty skewed towards Java; the generated code is kind of like Java-in-Python or Java-in-C++.)

I'm curious what algorithm Perl uses to match grammars. ANTLR uses a few algorithms, like the one to generate lookahead tables for LL(k), and then the LL() algorithm, and apparently a new one with ALL() in ANTLR v4.


To be fair to ANTLR I think it might have actually wanted a CharSequence, which is a bit more pragmatic, and I could probably have wrapped my byte[] in an object implementing that interface.

The real problem I should mentioned was that I seemed to be using very little of the real ANTLR parsing algorithm, as there was so much logic in actions to parse a real language like Ruby. These languages aren't designed with a formal grammar model in mind. They just do what they do and it's your problem if ANTLR isn't designed for what they want.

Actions are the grammar equivalent of unsafe blocks in languages like Rust or Haskell. If you are using them in an application it's a red flag, and I never managed to write an ANTLR grammar without them. That then makes the red flag on ANTLR, not on my programming skills.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: