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