Where is the BNF for the shader language used in WebGL? - fragment-shader

I'm having trouble locating the exact specification of the grammar for the WebGL2 shader language. I see references that it is "based on" version 3 of the Open GL Shader language -- but it is obviously not exactly that since there are missing keywords in the Open GL version. Where is the precise syntax of the shader language specified for the current version of WebGL supported on modern browsers?
For example this spec specifically disallows the keyword "attribute" which is used in WebGL vertex shaders. Where is the correct BNF grammar specified?

The spec for WebGL2 points to the specs for GLSL ES 3.0 which contains the grammar in section 9.
The WebGL2 spec also points to the spec for WebGL1 which points to the spec for GLSL ES 1.0 which also happens to have its grammar in section 9.

Related

ANTLR4 not processing UTF-16 input correctly

I'm using ANTLR 4.10.1 and C++. I'm using ANTLRInputStream as the input to my lexer
antlr4::ANTLRInputStream inputStream(....);
Which works fine until I use UTF-16 characters in the input, as they cause problems later on.
Since ANTLRInputStream is deprecated for 4.10.1, it seems CharStreams needs to be used to be able to specify a Charset, i.e. "UTF-16LE". But I could only find documentation for Java. Is there a way to use CharStreams with UTF-16 to make this work in C++?
The input stream in the C++ runtime actually expects UTF-8, always! See also the source code in ANTLRInputStream::load. Internally it converts that to UTF-32. The 16 bit transformation format is never used.
Because of this convention, there's no need to deprecate the C++ version of the ATNLRInputStream. That was only necessary for old language targets, which had no UTF-32 (like JS and Java). With that in mind you can ignore the new CharStreams class in the C++ target.

Xcode Model I/O - importing custom shader from Marmoset

Accordion to Apple Model I/o documentation:
Block quote
You can use this framework to import and export assets from and to a variety of industry standard file formats supported by popular authoring tools and game engines.
Block quote
And
Block quote
Describing realistic rendering parameters. TheMDLPhysicallyPlausibleScatteringFunction class—one of many ways to describe the surface appearance for a MDLMaterial object associated with a mesh—defines the intended rendering of a surface using the same physically based shading systems seen in popular feature films and high-end game engines. The MDLPhotometricLight and MDLPhysicallyPlausibleLight classes describe realistic lighting properties for use in rendering, and the MDLCamera class also supports physically based rendering parameters.
Block quote
So,it it possible to import a custom PBR shader created in Marmoset?
If yes, how can I do it?
Thanks
As the documentation (of MDLAsset) also includes:
“The set of supported formats includes Alembic (.abc), Wavefront Object (.obj), Polygon (.ply), and Standard Tessellation Language (.stl). Additional formats may be supported as well.”
From marmoset.co:
“Marmoset Toolbag uses a somewhat customized shader language, which is a kind of union of HLSL and GLSL syntax conventions”
Metal uses it’s own shading language and is not even supported by the file formats it can import and export. So in short, no, you can’t import those shaders.

Is there an Antlr Grammar available for LLVM IR?

I want to parse a LLVM IR file and perform certain operation accordingly, Wondering if there is an ANTLR Grammar available for LLVM IR, this will make my job much simpler?
The largest repository of grammars I know of is here. I don't see your grammar in the list, sorry. Terence Parr makes mention of it in this article, but that's all I can find, but it's quite old and seems to be based on ANTLR3.
I got this file from one of the github repositories:
https://github.com/rwl/JLLVM/blob/master/src/cn/edu/sjtu/jllvm/VMCore/Parser/LLVM.g
It is a part of JLLVM source code(JLLVM is a Java version of LLVM Core. To get more info about JLLVM you should follow the link: http://tcloud.sjtu.edu.cn/wiki/index.php/User:Liuhaots:JLLVM)

"Human-readable" ANTLR-generated code?

I've been learning ANTLR for a few days now. My goal in learning it was that I would be able to generate parsers and lexers, and then personally hand-translate them from Java into my target language (neither C/C++/Java/C#/Python, no tool has support for it). I chose ANTLR because from its About page: ANTLR is widely used because it's easy to understand, powerful, flexible, generates human-readable output[...]
In learning this tool, I decided to start with a simple lexer for a simple grammar: JSON. However, once I generated the .java file for this lexer using ANTLR4 I was caught widely off-guard. I got a huge mess of far-from-human-readable serialized code, followed by:
public static final ATN _ATN =
ATNSimulator.deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
}
A few Google searches were unable to provide me a way to disable this behavior.
Is there a way to disable this behavior and produce human-readable code, or am I going to have to hand-write my lexers and parsers for this target programming language?
ANTLR 4 uses a new algorithm for prediction. Terence Parr is currently working on a tech report describing the algorithm in detail. The human-readable output refers to the generated parsers.
ANTLR 4 lexers use a DFA recognizer for a massive speed and memory usage improvement over previous releases of ANTLR. For parsers, the _ATN field is a data structure used within calls to adaptivePredict (you'll notice lines in the generated code calling that method).
You won't be able to manually translate the generated Java code of an ANTLR 4 lexer to another programming language. You might be able to manually translate the code of a generated parser provided the grammar is strictly LL(1) (i.e. the generated code does not contain any calls to adaptivePredict). However, you will lose the error recovery ability that draws from information encoded in the serialized ATN.

Generate AST for Java with ANTLR

As far as I know, there are two mechanisms in ANTLR for building abstract syntax trees. I want to build a AST for Java source files.
Question: There are so many grammar rules in Java.g (java specification), it's a large work if I specify the AST generating rules for every item in Java.g. So I wondering if there is a ready-made one, and where can I get it.
This Java 1.5 grammar1 from the ANTLR Wiki generates an AST and also provides a tree grammar2.
Java.g
JavaTreeParser.g
22 Aug 2014 - UPDATE
Since the original link appears to be dead, the grammar and tree grammar are available in a public Gist: https://gist.github.com/bkiers/741125a606954b24bbf4