ANTLR JavaScript Target

后端 未结 4 466
执念已碎 2021-02-20 12:09

I have been using ANTLR to generate a parser + tree grammar for a mark up language with Java target which works fine. Now I am trying to get the target in JavaScript to use it i

  • 2021-02-20 12:44

    You should use the latest version (3.3), in previous versions the javascript target was not properly integrated. There still some bugs, but you can see a working example with some guidance and links on

    0 讨论(0)
  • 2021-02-20 12:54

    There is a new JS Lang target for ANTLR4 that was posted to GitHub almost 3 months ago:


    It's not integrated into an official release yet, but you can probably just throw it into the latest ANTLR4 codebase and recompile ANTLR yourself.

    0 讨论(0)
  • 2021-02-20 13:02

    It appears as though the JavaScript target is broken again in the 3.4 distribution. 3.3 is working fine for me though.

    0 讨论(0)
  • 2021-02-20 13:05

    I have been trying to get this working, and have only just managed to generate .js files succesfully after reading this:

    From the post:

    Here's how to get started with ANTLR and the JavaScript back-end:

    1. Download ANTLRWorks 1.2.2: <>. The JavaScript target only works when the IDE generates the lexer and parser code (see <>). If you try to run ANTLR v3.1 from the command line, you will see the error message "error(10): internal error: group JavaScript does not satisfy interface ANTLRCore".
    2. Download the JS runtime distribution:

    From then on you can use ANTLRWorks 1.2.2 to generate the lexer and parser code by selecting "Generate Code" from the "Generate" menu. ANTLRWorks will place the generated files into an output directory in the folder in which the grammar file resides.

    Note that if an error occurs in the generation process, then for some reason the "Generate Code" action no longer works. Simply close the grammar and re-open it from the "Open Recent" menu.

    0 讨论(0)