News for hackers. Stuff that matters.

DmitrySoshnikov

Re:Writing a Memory Allocator (2019) on Sunday December 13, 2020 @04:04PM (#25410266)
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

Re:Parsing Algorithms on Tuesday October 27, 2020 @06:27PM (#24912761)
Thanks for the feedback, and glad to see more engineers interested in deeper topics!
Re:Parsing Algorithms on Tuesday October 27, 2020 @03:13PM (#24910734)
That's a great point and I have the https://github.com/DmitrySoshnikov/syntax/issues/99 to add support for IELR in Syntax.
Re:Parsing Algorithms on Tuesday October 27, 2020 @02:05PM (#24910091)
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.

Re:Parsing Algorithms on Tuesday October 27, 2020 @12:32PM (#24909033)
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).

Re:Parsing Algorithms on Tuesday October 27, 2020 @01:40AM (#24904743)
Yeah, this makes sense, thanks.
Re:Parsing Algorithms on Tuesday October 27, 2020 @01:28AM (#24904695)
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.
Re:Parsing Algorithms on Tuesday October 27, 2020 @01:25AM (#24904686)
Thank you for the feedback, glad you liked it, and glad to see more people interested in deeper CS topics!
Re:Parsing Algorithms on Tuesday October 27, 2020 @01:23AM (#24904678)
Yes, I recommend "Parsing Techniques" book.
Re:Parsing Algorithms on Tuesday October 27, 2020 @01:21AM (#24904672)
See this small summary doc on different techniques for error recovery: https://gist.github.com/DmitrySoshnikov/feee52cbfb03b7b69110...
Re:Parsing Algorithms on Tuesday October 27, 2020 @01:20AM (#24904670)
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 }

Re:Parsing Algorithms on Monday October 26, 2020 @06:15PM (#24902154)
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.
Re:Parsing Algorithms on Monday October 26, 2020 @05:20PM (#24901565)
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.
Re:Parsing Algorithms on Monday October 26, 2020 @04:28PM (#24900995)
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).

Re:Parsing Algorithms on Monday October 26, 2020 @04:25PM (#24900952)
Should be up by now; seems auto-DDOS'ed, lol
Re:Parsing Algorithms on Monday October 26, 2020 @04:23PM (#24900926)
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.
Re:Parsing Algorithms on Monday October 26, 2020 @04:21PM (#24900904)
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.
Re:Parsing Algorithms on Monday October 26, 2020 @04:19PM (#24900882)
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".
Re:Parsing Algorithms on Monday October 26, 2020 @04:16PM (#24900844)
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".

Re:Parsing Algorithms on Monday October 26, 2020 @02:39PM (#24899560)
Yes, GLL is a good algorithm and I potentially going to publish it separately as a single public video.
Re:Parsing Algorithms on Monday October 26, 2020 @02:38PM (#24899537)
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".

Re:Parsing Algorithms on Monday October 26, 2020 @02:35PM (#24899504)
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.
Re:Parsing Algorithms on Monday October 26, 2020 @02:34PM (#24899480)
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.
Re:Essentials of Interpretation on Saturday March 14, 2020 @07:18PM (#22579524)
> 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".

Re:Essentials of Interpretation on Thursday March 12, 2020 @07:22PM (#22563099)
Indeed, TypeScript is also a good choice for this.

Older »