News for hackers. Stuff that matters.
Re:Pratt parsing is a black box by adrian_b on Tuesday November 03, 2026 @04:07PM (#50358202)
I assume that they refer to what you do when you write a Yacc or Bison file or any other input file for a similar parser generator.

A Yacc file contains the grammar of the language to be parsed, but to each grammar rule you can attach a C function that will be invoked by the generated parser when matching that rule.

Re:Pratt parsing is a black box by direwolf20 on Tuesday November 03, 2026 @06:48PM (#50359835)
Executing the operation inside the semantic action only works for simple calculators. Otherwise you have the problem that the line of code may run multiple times even though it's only parsed once. Usually you make the semantic actions build an AST (a data structure holding the structure of the program, e.g. new BinaryExpression(left_ast, '+', right_ast)