Throughout the RDF specs an EBNF-NOTATION XML specification is used to specify the grammar of a document. So I am wondering how to use Antlr/bison/yacc (maybe with some flag within these tools I don't know how to search for) — or other tools I don’t know about yet — to consume these specifications and generate a parser for me to use to see if my RDF is well-formed before trying to load.
An example grammar for my specific use case is: https://www.w3.org/TR/n-quads/#sec-grammar
I have already converted this grammar into Antlr4 grammar and created a parser using that tool and attempted to just write my own recursive descent parser but it was time-consuming and I'd rather not repeat the exercise if I have to do this again.
Don't really have any code, this is just a request for information.
What I want to do is basically copy/paste the grammars specified in this XML EBNF-NOTATION and produce a parser generator similar to what Antlr provides.
REx Parser Generator works from grammars in W3C-style EBNF, and Railroad Diagram Generator can extract grammars directly from W3C documents.
Here is how to create a working parser from the example grammar (in Java - some other target languages are supported, too):
Get Grammar
tab, enter the example URL https://www.w3.org/TR/n-quads
Edit Grammar
WHITESPACE ::= [ #x9]+ /* ws: definition */
n-quads.ebnf
n-quads.ebnf
and command line -java -tree -main
n_quads.java
and compile itjava n_quads -i a-sample-file
Full disclosure: I’m the creator and maintainer of REx Parser Generator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With