Blog.bjrn.se: Let’s build an MP3-decoder! Even though MP3 is probably the single most well known file format and codec on Earth, it’s not very well understood by most programmers – for many encoders/decoders is in the class of software “other people” write, like standard libraries or operating system kernels. This article will attempt to demystify the decoder, with short top-down primers on signal processing and information theory when necessary.
Additionally, a small but not full-featured decoder will be written (in Haskell), suited to play around with. The focus on this article is on concepts and the design choices the MPEG team made when they designed the codec – not on uninteresting implementation details or heavy theory. Some parts of a decoder are quite arcane and are better understood by reading the specification, a good book on signal processing, or the many papers on MP3 (see references at the end). A note on the code: The decoder accompanying this article is written for readability, not speed. About MP3 Huffman coding. Alexandr Andoni -- Publications. Manuscripts: The Sketching Complexity of Graph Cuts (with Robert Krauthgamer and David Woodruff). arXiv:1403.7058 Learning Polynomials with Neural Networks (with Rina Panigrahy, Gregory Valiant, and Li Zhang).
Manuscript 2014. "High frequency moments via max-stability". See also my blog post. Manuscript, 2012. Publications: Parallel Algorithms for Geometric Graph Problems (with Aleksandar Nikolov, Krzysztof Onak, and Grigory Yaroslavtsev). Theses: "Nearest Neighbor Search: the Old, the New, and the Impossible". "Approximate Nearest Neighbor Problem in High Dimensions". An undergrad project paper: "Dynamic Pattern Matching: The World of Tries and Range Queries?
" Parser in javascript. Cleaning up my hard drive I came across some old libraries I’d written. One of them was a simple set of parser combinators written in Javascript. I put it in a git repository in case they prove useful to someone: git clone The library pulls ideas from parser combinators written in various languages and is pretty simple. But even though it is a small amount of code it works quite well. The repository includes an example of parsing numbers and strings based on the grammar in the EcmaScript specification.
A parser in this library is a function that takes an input string and returns a result object. Remaining: the remaining part of the input string to be parsed matched: the part of the input string that was successfully parsed by the parser ast: The abstract syntax tree produced by the parsr Parser combinators combine parsers together to enable parsing more complex grammars. The AST produced by parser is the string that it parsed. /dev/collective. Note: This post is literate Haskell, you can copy the whole text to a .lhs file and compile it with GHC. A friend of mine was showing me a very simple and elegant parser for JSON , written in Scala . As an excercise, I decided to write one in Haskell , using the Parsec parser combinator library. Here’s a quick walkthrough. First we need some imports, > import qualified Data .
Now, to represent a JSON value, we use an algebraic data type. > data JSON = S String > | I Integer > | B Bool > | L [ JSON ] > | O ( Map . Now, to make our life somewhat easier, we’ll make use of the facilities in the ParsecToken module. > ldef = emptyDef { commentStart = "/*" > , commentEnd = "*/" > , commentLine = "//" > } > lexer = T . makeTokenParser ldef We can now pass lexer to the convenience functions of ParsecToken .
> symbol = T . symbol lexer > stringLiteral = T . stringLiteral lexer > integer = T . integer lexer > squares = T . squares lexer > braces = T . braces lexer > commaSep = T . commaSep lexer. Laurence Tratt: How Difficult is it to Write a Compiler? Recently I was discussing Converge with someone, and mentioned how little time the core compiler had taken to implement (no compile-time meta-programming, limited error checking, but a functioning compiler nonetheless) - only a few days.
The chap I was talking to looked at me and told me that he didn't believe me. I laughed. Actually, he really didn't believe me. Initially that surprised me, and I wondered why he might think that I was pulling his leg. When I was younger, there were three things in computing that seemed so complex that I had no idea how anyone had ever created them; certainly, I didn't think I would ever be capable of working on such things. Programming languages are, for most of us, an integral part of the computing infrastructure.
So let's start looking at things in more detail. Read in a source file, and create a parse tree. Parsing If we have an input file such as the following: import Sys func main(): Sys::println(2 + 3) What is its parse tree? Conclusion That's it. LukeH's WebLog : Monadic Parser Combinators using C# 3.0. Parser combinators are an idea that I enjoy every time I go back and look at again. They are an approach to building parsers by composing very simple atomic parsers into bigger and bigger units which can ultimately express real world grammars. This idea has been particularly popular in functional languages where the parsers can naturally be thought of as functions from input strings to parse trees, and composition of parsers is just function composition. This approach often leads to a simple syntax which makes the resulting parsers pleasantly declarative in that internal-DSL kind of way.
There's been plenty of great research and implementation of parser combinators over the last 15 years. Building a Parser Combinator Framework in C#3.0 The code below is some sample code I wrote shortly after getting ahold of one of the first C#3.0 prototype compilers a couple years ago. Step 1: A Type for Representing Parsers Step 2: Provide Infix AND and OR Operations on Parsers Step 6: Parse Something!
Parsing Techniques - A Practical Guide. Algorithms for Parsing Arithmetic Expressions.