Why is bottom-up parsing more common than top-down parsing?

If you choose a powerful parser generator, you can code your grammar without worrying about peculiar properties. (LA)LR means you don’t have to worry about left recursion, one less headache. GLR means you don’t have to worry about local ambiguity or lookahead. And the bottom-up parsers tend to be pretty efficient. So, once you’ve paid … Read more

Practical difference between parser rules and lexer rules in ANTLR?

… what are the practical differences between these two statements in ANTLR … MY_RULE will be used to tokenize your input source. It represents a fundamental building block of your language. my_rule is called from the parser, it consists of zero or more other parser rules or tokens produced by the lexer. That’s the difference. … Read more

Writing a parser from scratch in Haskell

It’s actually surprisingly easy to build Parsec-from-scratch. The actual library code itself is heavily generalized and optimized which contorts the core abstraction, but if you’re just building things from scratch to understand more about what’s going on you can write it in just a few lines of code. I’ll build a slightly weaker Applicative parser … Read more

Choosing a Haskell parser

You have several good options. For lightweight parsing of String types: parsec polyparse For packed bytestring parsing, e.g. of HTTP headers. attoparsec For actual binary data most people use either: binary — for lazy binary parsing cereal — for strict binary parsing The main question to ask yourself is what is the underlying string type? … Read more

Parse URL in shell script

[EDIT 2019] This answer is not meant to be a catch-all, works for everything solution it was intended to provide a simple alternative to the python based version and it ended up having more features than the original. It answered the basic question in a bash-only way and then was modified multiple times by myself … Read more

tech