GLSL Language Parsers for Java?

I’m looking for an open source GLSL parser preferably producing an abstract syntax tree.

What we found so far:

  • glsl4idea: IntelliJ plugin. Too many dependencies on IntelliJ code, but language description for FLEX might be useful.
  • glslang: Reference implementation of a GLSL compiler in C, by Khronos Group. Contains language description for Bison.
  • fragbyte: GLSL to bytecode compiler based on ANTLR4. Uses AST for bytecode representation. Rule set possibly useful.
  • antlr4_convert: Compiler based on ANTLR4, which converts between GLSL and HLSL.

Does anybody of you know of some others? Maybe integrated in graphics/game engines?

Seems there is no “official” GLSL grammar for ANTLR, but Google points me to a few Github projects:

Thanks, CoDi^R. fragbyte looks promising and uses even an AST. Will see.

EDIT: Nope. The AST is for the bytecode which is getting generated by the compiler. But the ANTLR rule set might be a good start.


The author of Unlicense Lib probably knows the answer, you should contact him.

@ gouessej: had a look at their repository but didn’t find anything related to GLSL parsing. Also, I couldn’t find a contact address.

Ported the grammar from Khronos’ reference impl to ANTLR4 and extended it by the rules for preprocessing according to ISO C standard (also added #include directive while I’m at it - doesn’t hurt to have it).

The grammar is written. Test coverage is currently at 30%, roughly.

I just stumbled upon this looking for other GLSL parsers. I have written a GLSL parsing and program transformation library in java which you might find helpful: GitHub - IrisShaders/glsl-transformer: An advanced Java library for GLSL parsing, program transformation, and printing that uses ANTLR4. Developed and maintained by @douira.
The grammar I’m using is adapted from the grammar given in the spec and the grammar used by graphicsfuzz.

1 Like