Better HN
topnewbestaskshowjobs
Log inSign up

DmitrySoshnikov

318 karma · joined May 29, 2011 (15y ago) · 80 submissions

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

1.

“Building a Parser from scratch” full course(dmitrysoshnikov.com ↗)

2 points · by DmitrySoshnikov · 5y ago · discuss

comment 5y ago · link · parent

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

comment 6y ago · link · parent

Thanks for the feedback, and glad to see more engineers interested in deeper topics!

comment 6y ago · link · parent

That's a great point and I have the https://github.com/DmitrySoshnikov/syntax/issues/99 to add support for IELR in Syntax.

comment 6y ago · link · parent

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.

comment 6y ago · link · parent

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).

comment 6y ago · link · parent

Yeah, this makes sense, thanks.

comment 6y ago · link · parent

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.

comment 6y ago · link · parent

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

comment 6y ago · link · parent

Yes, I recommend "Parsing Techniques" book.

comment 6y ago · link · parent

See this small summary doc on different techniques for error recovery: https://gist.github.com/DmitrySoshnikov/feee52cbfb03b7b69110...

comment 6y ago · link · parent

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 }

comment 6y ago · link · parent

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.

comment 6y ago · link · parent

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.

comment 6y ago · link · parent

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).

comment 6y ago · link · parent

Should be up by now; seems auto-DDOS'ed, lol

comment 6y ago · link · parent

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.

comment 6y ago · link · parent

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.

comment 6y ago · link · parent

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".

comment 6y ago · link · parent

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".

comment 6y ago · link · parent

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

comment 6y ago · link · parent

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".

comment 6y ago · link · parent

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.

comment 6y ago · link · parent

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.
123