HN user

DmitrySoshnikov

318 karma

Software engineer interested in learning and education. Sometimes blog on topics of programming languages theory, compilers, and ECMAScript.

Posts21
Comments53
View on HN
dmitrysoshnikov.com 5y ago

“Building a Parser from scratch” full course

DmitrySoshnikov
2pts0
dmitrysoshnikov.com 5y ago

Parsing Algorithms

DmitrySoshnikov
407pts86
www.youtube.com 5y ago

LL(1) parsing: First and Follow sets

DmitrySoshnikov
1pts0
www.youtube.com 6y ago

Backtracking Parser in JavaScript

DmitrySoshnikov
1pts0
dmitrysoshnikov.com 6y ago

Writing Mark-Sweep Garbage Collector in C++

DmitrySoshnikov
3pts0
dmitrysoshnikov.com 6y ago

Essentials of Interpretation

DmitrySoshnikov
57pts21
www.youtube.com 6y ago

Stack is needed, but not specifically for Recursion

DmitrySoshnikov
1pts0
dmitrysoshnikov.com 6y ago

By-value, by-reference, by-sharing: strategies of passing arguments

DmitrySoshnikov
4pts0
www.youtube.com 6y ago

AOT vs. JIT Compiler

DmitrySoshnikov
2pts0
www.youtube.com 6y ago

Stack VM vs. Register VM

DmitrySoshnikov
4pts0
www.youtube.com 6y ago

Essentials of Interpretation.[1/16] Parsers, ASTs, Interpreters and Compilers

DmitrySoshnikov
2pts0
www.youtube.com 6y ago

Immix: A Modern and Efficient Mark-Region Garbage Collector

DmitrySoshnikov
1pts0
dmitrysoshnikov.com 6y ago

“Automata Theory. Building a RegExp machine” full course is available

DmitrySoshnikov
2pts0
dmitrysoshnikov.com 7y ago

“Essentials of Garbage Collectors” full course is now available

DmitrySoshnikov
155pts53
dmitrysoshnikov.com 7y ago

Writing a Memory Allocator

DmitrySoshnikov
3pts0
www.youtube.com 7y ago

Essentials of Garbage Collectors: Memory Layout

DmitrySoshnikov
1pts0
www.npmjs.com 8y ago

Hdl-js: Hardware description language (HDL) parser, and Hardware simulator

DmitrySoshnikov
3pts0
dmitrysoshnikov.com 8y ago

JavaScript. The Core: 2nd Edition

DmitrySoshnikov
2pts0
medium.com 9y ago

Rust LALR(1) parser generator

DmitrySoshnikov
3pts0
www.npmjs.com 9y ago

RegExp processor and optimizer for JavaScript

DmitrySoshnikov
3pts0
medium.com 9y ago

Syntax: language agnostic parser generator

DmitrySoshnikov
2pts0

sbrk is emulated via mmap today on MacOS and others, this is an abstraction (for bump allocation), not just a function

you may implement custom sbrk via mmap easily

Parsing Algorithms 6 years ago

Yes, in fact for building a language the parsing stage should be skipped altogether (start with interpreter or bytecode). We do this in the interpreters class. And once you have a fully working VM, _now_ it is a good time to shift to parsing and design a good syntax.

For recursive descent we have a separate class "Building a Recursive descent parser from scratch" which is purely practical coding class for those interested mainly in practice.

Parsing Algorithms 6 years ago

Yes, backtracking still might be an option although has its known limitations in terms of parallel paths. We describe backtracking in this class too.

The LL in the the view of manual Recursive descent is the most used on practice along with combinators and LALR(1).

Parsing Algorithms 6 years ago

Professor Aiken is a great teacher and I love his compilers course. However as for the parsering stage, that course goes as maximum as to SLR(1) which is pretty "toy" parsing mode. That's the problem with a combined "compilers class" -- one simply can't put everything, and everything is becoming slightly superficial. That's why I have Parsers and Garbage Collectors class as separate and fully specialized course.

Parsing Algorithms 6 years ago

Thank you for the feedback, glad you liked it, and glad to see more people interested in deeper CS topics!

Parsing Algorithms 6 years ago

Great details, thanks!

A benefit of a syntax with indentation-defined block structure is that you don't need to rely on balanced grouping tokens like { ... }

In fact from the lexer perspective there is no big difference, the matching indent-dedent is the same token type as would be { and }

Parsing Algorithms 6 years ago

Yes, this is called "parse error recovery" and there are multiple techniques for this. In fact, most of the production parsers support this mode. E.g. when you try executing a C++ or Java file, it shows you all the errors at once instead of failing on first parse error. The way it's achieved is by constructing a "dummy" AST node (caught up to some delimiter, e.g. semicolon in statements) and continue the parsing process as there would be no any error.

Parsing Algorithms 6 years ago

Absolutely! S-expression (used in Scheme, Lisp, etc) is a great AST-based syntax to start building an interpreter right away. But for fully ergonomic language you would need a parser for a more complex syntax.

Parsing Algorithms 6 years ago

Yes, in the "Essentials of Interpretation" class (aka "Building an Interpreter from scratch" we focus exactly on runtime semantics, and evaluating the language. The S-expression allows greatly simplifying, focus on runtime specifics themselves, skipping parsing stage altogether.

In "Essentials of Parsing" class (aka "Parsing Algorithms") we shift exactly to the syntax, and understanding the parsing process from within -- this in general may have nothing to do with runtime -- for the same exact syntax you may have different interpreters or VMs (even with different semantics).

Parsing Algorithms 6 years ago

Yes, if you need to parse that input string to generates an appropriate SQL query, you would need to have a small DSL (domain-specific language) for that "string", whatever it contains. If the string contains SQL-like syntax, e.g. "SELECT name from users", then yes, it would be easy to build a grammar for this.

Parsing Algorithms 6 years ago

Yes, to some degree -- Syntax tool normally support lexer states, and the same "while" token may mean a keyword or the property/field name of a struct. You can find more details of the lexer states in the docs.

Parsing Algorithms 6 years ago

Yes, we use LALR(1) parsing mode to build the actual parser, and it exactly supports Left recursive grammars (which are much more elegant than LL). We also don't focus much on scanner (tokenizer) since this is a topic of Regular expressions and Finite automata which we discuss in detail in the separate class "Building a RegExp machine".

Parsing Algorithms 6 years ago

Yeah, this class is specifically on parsing pipeline and syntactic analysis.

For runtime semantics (Interpreters and Virtual Machines) you can address "Essentials of Interpretation" aka "Building an Interpreter from scratch".

Parsing Algorithms 6 years ago

Yes, GLL is a good algorithm and I potentially going to publish it separately as a single public video.

Parsing Algorithms 6 years ago

Congrats, and hope this makes building of your parser easy and fun!

This course covers a lot of parsing theory as well, and if you're interested in pure practical (manual) parser, there will be also "Building a Recursive descent parser from scratch", which is mainly coding class and is an extension for the "Parsing Algorithms".

Parsing Algorithms 6 years ago

Thanks for the feedback, glad you like it. For production I use combination of software: Keynote, Notability, Good notes, Camtasia, and live editing on iPad.

Parsing Algorithms 6 years ago

Great point on combinators, PEG, and GLL -- this potentially would be covered in 201 as suggested, since it's good having a foundation of the LL/LR, and then gradually moving to combinators if needed. LALR(1) covers a pretty wide range of the most practical languages.

the Voodoo magic is in the scheduling and code generation

Yes, for the code generation one needs to well understand semantics of the target language. And when it's a low-level language (Assembly), the "voodoo magic" mainly relates to generic understanding of the lower-level architectures. However, there might be compilation to another high-level language (in case of a transpiler), and by itself code generation at this stage is not that hard, simply because a target language is more understood in this case.

Instruction selection topic, and where to place the data -- on the stack, or into registers (and how a register allocator works) also mainly relates to the lower-level.

until you get into the backend

Yes, and that's why I think it should be a separate class, specifically for higher-level compilation, and a low-level compilation.

We'll be covering this in "Essentials of Compilation".

Thanks for your feedback, appreciated! And glad the Garbage Collectors class is interesting. Yes, I'll consider shortening the intro in the future classes. Initially each lecture was a self-contained, and potentially with no related context to previous lectures, however when combined in a class, yes, it makes sense to make the intro shorter. In the Interpreters class I shortened it to ~5 secs only.

Yes, good point on pattern matching and algebraic data types (initially I was actually considering Rust for implementation, but not OCaml). The visitor pattern is a classic though, and is transferable knowledge further, to process different kinds of graphs, trees, etc. BTW, JavaScript will likely be getting pattern matching soon as well.

Yes, I agree, the topic is becoming pretty hot these days, and this reflects the era of transpilers, WebAssembly, coming into play with its nested bytecode format, and other related topics. More people are getting interested in how things work under the hood, instead of just "using" a language.

Thanks! Yes, we use JavaScript as the most popular language, however the code should be easily portable to any other language.

The multi-paradigm nature of JS, with its first-class functions, closures, static scope semantics, class-based and prototype-based inheritance fits the best to study semantics of programming languages -- and all these concepts we implement in the course.

For low-level bytecode interpreter there will be a C++ implementation.