Closed bkaradzic closed 8 years ago
The parser doesn't ignore parentheses. It understands them and operator precedence. The AST represents the correct order of operations always. Otherwise the AST would be ambigious. The problem is the outputter which walks the AST forgets to add parens around binary expressions. I fixed this in 8f8ec27
The technique you're describing where each operation gets its own variable like that is called SSA (Single Static Assignment) that is an optional pass that occurs after AST. Typically during code generation. glsl-parser doesn't concern itself with that ;) The word parser is in the name for a reason. I would like to do a compiler eventually targeting other output shader languages (HLSL, ESSL, and maybe SPIRV) but I doubt the effort is worth it.
Yeah, I know what SSA is, it was my cunning plan attempt to word it in the way to get you to do it, otherwise I have to do it... :)
Code:
Becomes:
I wouldn't mind if fixed AST becomes (each operation separate line / temporary):