So, I'm really unclear on this situation and what it means.

I have an EBNF-based grammar file that we use for our project. This EBNF grammar describes rules for parsing/lexing a document (e.g. some source code for a Domain-Specific language). EBNF can be thought of as a generalisation of regular expressions.

Lexer/parser generators, such as ANTLR, YACC, and Bison, take this grammar file as input, and output source code which can perform the parsing of the language described by the grammar. We are using ANTLR, it is outputting a suite of C# classes.

The particular grammar file we use as input is licensed under GPLv3 and we've made modifications to it.

Now, the resulting files do not require the grammar file after the classes are generated. Technically, there's no need to distribute the grammar file along with the project. We could keep that private and distribute everything without it and everything works just fine.

Up until now, we've been releasing our software under GPLv3 under the assumption that our project is a derivative of this grammar file, but is it? I'm wondering if we're really required to release our entire project under GPLv3. We'd much prefer to release under the MIT license. Can we do that? The grammar file isn't a library, but a tool that is used in conjunction with ANTLR to generate code.

Can we create a separate distribution/repository for the modified grammar file, then re-license our core project? (We'd still like to share our modifications to the grammar, we just don't want to continue licensing ours with a viral license).

  • 5
    Performing a machinal transformation of a work - which is something ANTLR does - never creates a new original work as meant in copyright law. I'll see if I can write a full answer later. – Martijn Oct 7 '15 at 9:26
  • 2
    Could you elaborate on how you think the grammar-to-code transformation is different from a compiler's code-to-binary transformation? – apsillers Oct 7 '15 at 13:45
  • @apsillers can you elaborate on why that's important? – RubberDuck Oct 7 '15 at 14:15
  • 2
    Sure, sorry for the terse comment above. It seems to me that ANTLR and a compiler both take a copyright-eligible creative work and perform automated operations to produce output based on the input work. Based on the assumption that we agree that compilation creates a derivative work, I asked for your thoughts on the subject to see if you have any specific considerations about how the process of parser-generation differs from compilation that would be relevant in a copyright context. I would like to address any such considerations in an answer. – apsillers Oct 7 '15 at 14:31
  • @apsillers I don't have any real thoughts on the matter, but only because I don't really truly understand the differences between the two at a licensing level. – RubberDuck Oct 7 '15 at 14:35

The code is a derived work of the grammar. (but not of ANTLR)

  • The Grammar file is a description of how to parse the language, written in EBNF.
  • The source code generated by ANTLR etc is a description of how to parse the language, written in Java (etc).
  • The source code was derived from the Grammar, using ANTLR.
  • It is thus a derived work, of the Grammar (but not of ANTLR).

It would make very poor sense for ANTLR to try to claim that anything made using it was a derived work. Like painting is not a derived work from a paint brush, or a letter a derived work of the word processor. I won't go into that further, (I think that further details should go in another similar question with different emphasis)

The GPL uses the term "work based on" rather the derivative work, but I believe though are synonymous Thus derivative works must be licensed.

Consider translating between two main stream programming languages. (EBNF is essentially a programming language, as is Java.) The translated source code is clearly a derived from the original.

To give a concrete example:

  • I have some source code, written in Dart I used dart2js to convert it to Javascript for execution in the browser.
    • My Dart source code, is analogous to your Grammar file
    • dart2js is analogous to ANTLR -- changing one language to another
    • the Javascript output which I incorporate into my overall webapp is the Source Code, which you incorperate into your project
    • If I released the Dart code under the GPL, and then someone else run dart2js on it and said it was a original work; well they would be incorrect, and obviously so. (NB: I have not released the linked code under GPL or any other license)
    • The source code is not a derived work of

Consider also the non-software examples:

  • I have written a play. I producted a Play script in English, and it was translated to Russian.

    • The play script, is a set of instruction on how to produce the play. How to move on stage, what to say when to say it etc.
    • The English playscript is your Grammar File.
    • The Translator is your ANTLR
    • The Russian playscript is your Source Code produced.
    • The Russian playscript is a derived work from my English original.
  • Or I have a music score (sheet music) it describes a song in musical notation.

    • I have my band play the song, and I record it into a MP3.
      • I now have a description of the song, in MP3 form
      • That recording is a derived work
    • Or, say I used OCR tool to convert it to MusicXML
      • The sheet music (score) is exactly analogous to your EBNF grammar
      • The OCR tool is analogous to ANTLR
      • The MusicXML file generated is analogous to your generated class files
      • The MusicXML was derived from the score

Taking one work, and using it as the bases for another work is creating a derived work. It doesn't matter if it looks different, it is still derived.

Your modified grammar would still have to be licensed under the GPL if released (it is obviously derived, as given by the words "modified"), as would any code generated from it, thus your whole project would have to be under the GPL.

The short of it is: The Grammar is under a viral license, therefore anything derived from it is under that license (otherwise what would be the point in licensing it under a license that does not allow relicensing?). Producing source code is producing a work based on the grammar (like any translation). Thus the source must be under the viral licence

(But, I'm not a lawyer and I am not your lawyer)

  • 2
    You could make an example more closely related to open source software: You have a C program. You use gcc to compile it. The resulting executable is a derived work, derived from the C program. The gcc compiler (GPLv3-licensed) is a tool used in the process. The executable is not considered to be derived from gcc, is it? – Glenn Randers-Pehrson Oct 7 '15 at 1:51
  • 2
    I agree with this interpretation. It's particularly flagrant that the generated code is derivative of the grammar, when you consider that the generated subtypes are named exactly after the grammar rules defined in the .g4 file (e.g. VBAParser.AmbiguousIdentifierContext generated from the ambiguousIdentifier rule in the VBA.g4 file). – Mathieu Guindon Oct 7 '15 at 3:05
  • 1) That's a fairly dangerous analogy. The grammar is not at all like sheet music. Sheet music is much closer to the resulting code. 2) You never directly answered the licensing question. – RubberDuck Oct 7 '15 at 9:04
  • I could write a program to take the output code from ANTLR and generate the grammer file (identical up to style choices). Just like I could write a program to convert MusicXML to sheet music (again identical up to style choices). A bijection exists between the Code output by ANLTR and the input grammar file. Just like a bijection exist between sheet music and MusicXML. Thus I refute your statement that "The grammar is not at all like sheet music. Sheet music is much closer to the resulting code". In both cases the two derived forms are informationally equivalent (isomorphic) to the original. – Lyndon White Oct 7 '15 at 11:05
  • @RubberDuck Does it seem directly answered now? I removed some of the hedging, the first 5 words remains the same: "It is a derived work.", which i think directly answers the question? – Lyndon White Oct 7 '15 at 11:26

TL;DR: yes, the software you distribute which builds on grammar files under copyright for which you have a GPLv3 license must also be licensed under the GPLv3.

Your software is made up of several parts.

  • The ANTLR runtime (BSD)
  • The original grammar files (GPLv3)
  • The rest of your software

Your software contains in part a machine translation of the grammar files. The US copyright office has said


meaning that the generated parser is not a separate derivative work as far as copyright is concerned, it is the same work.

ANTLR also injects large parts of its own codebase in the generated parser, and links against the ANTLR runtime. This is not much of a problem as both are under the (permissive) 3 clause BSD license, which is easy to comply with in combined or derivative works.

What I'm not sure of, and what I believe could only be tested in court, is whether grammar files themselves would be eligible for copyright protection at all. What is copyrighted is the expression of the idea the grammar describes, but one could argue there is no originality in the expression of the grammar. This would probably also depend on the grammar file itself. It might make a lot of difference if it's just BNFR rules or if there are significant code snippets or other things that are definitely eligible for copyright in the grammar files.

What you could certainly do is make a clean room re-implementation of the grammar files, and you're not bound by the license of the grammar files.

  • We've talked before about creating a clean room implementation. Thank you for the concise answer on the matter. – RubberDuck Oct 7 '15 at 15:48

I dug into this and found some answers in the GPL FAQ.


For example, if my program is used to develop hardware designs, can I require that these designs must be free? (#GPLOutput) In general this is legally impossible; copyright law does not give you any say in the use of the output people make from their data using your program. If the user uses your program to enter or convert his own data, the copyright on the output belongs to him, not you. More generally, when a program translates its input into some other form, the copyright status of the output inherits that of the input it was generated from.

So the only way you have a say in the use of the output is if substantial parts of the output are copied (more or less) from text in your program. For instance, part of the output of Bison (see above) would be covered by the GNU GPL, if we had not made an exception in this specific case.



Can I use GPL-covered editors such as GNU Emacs to develop non-free programs?

Can I use GPL-covered tools such as GCC to compile them? (#CanIUseGPLToolsForNF) Yes, because the copyright on the editors and tools does not cover the code you write. Using them does not place any restrictions, legally, on the license you use for your code.

Some programs copy parts of themselves into the output for technical reasons—for example, Bison copies a standard parser program into its output file. In such cases, the copied text in the output is covered by the same license that covers it in the source code. Meanwhile, the part of the output which is derived from the program's input inherits the copyright status of the input.

As it happens, Bison can also be used to develop non-free programs. This is because we decided to explicitly permit the use of the Bison standard parser program in Bison output files without restriction. We made the decision because there were other tools comparable to Bison which already permitted use for non-free programs.


Emphasis mine, as it's the important part of this FAQ. Because Antlr copies large parts of the grammar file into the resulting parser classes, those resulting classes are licensed under whatever license the grammar file uses. I find it interesting that another such tool (Bison) was mentioned here and given an explicit exception. I could find no evidence of any such exception for Antlr, so any code that links to the generated parser, must be licensed as GPLv3 like the grammar file.

  • You are taking the emphasis slightly out of context. The emphisis on "So the only way you have a say in the use of the output is if substantial parts of the output are copied (more or less) from text in your program. " is relevant for the Output of programs, including that of Bison. But also including other things like say Flash Pro to convert a Flash video into an .exe file (which basically works by embedding a subset of the flash code into the .exe). It is relevant as to whether the Output is considered derived from the Converter -- not whether it is derived from the input source. – Lyndon White Oct 7 '15 at 13:24
  • I'm starting to think I should contact the guy that wrote ANTLR... – RubberDuck Oct 7 '15 at 13:26
  • I thought ANTLR had a licensing FAQ on the website? (Apparently not, of if they did, it has been removed since I last used it 3+ years ago) – Lyndon White Oct 7 '15 at 13:31
  • 1
    @RubberDuck there is the license of the tool (ANTLR/BISON) and the license of the original grammar file. Your answer deals with the license of the tool, which is BSD for ANTLR and GPL + Bison exception for Bison. Bison is mentioned by name in the GNU FAQ because it's a GNU tool. Had the license been permissive, the exception wouldn't be needed. – Martijn Oct 7 '15 at 15:05
  • Thanks for the clarification @Martijn. I think I'll leave this answer here as it does contain some useful information. – RubberDuck Oct 7 '15 at 15:47

Your Answer

