A game for learning C operator precedence

Have you ever added parentheses to a C expression because you weren't quite sure of operator precedence?

This is a game to learn C operator precedence. You must add parentheses to each subexpression without changing the meaning of the expression.

Note: This is currently buggy due to a bug in the Tree-sitter grammar.

Please enable JavaScript to play the game.

How it works

This was absurdly easy to make thanks to the excellent Tree-sitter library, which can parse practically any language and which supports WebAssembly. The game works by using a very simple custom generator to generate random C expressions, then parsing that expression using Tree-sitter. The user's input is also parsed and the two ASTs are compared. Fortunately, Tree-sitter does include parentheses expressions in its AST despite them being semantic noise, so checking that parentheses have been added by the user was also easy. Source code: just view source.