5

when i try to generate the listener/visitor ... for my Grammar I get the following error : ANTLR cannot generate Javascript code as of version 4.5

Does anybody knows how to fix it? I still can generate C# and Java Code.

2
  • Couldn't find any hint to that fact. Older Versions like 4.4 and 4.3 doesn't work either Commented Jan 4, 2016 at 10:28
  • 1
    github.com/antlr/antlr4/releases as statet here it should work Commented Jan 4, 2016 at 18:32

4 Answers 4

22

From the docs:

This is pretty much the same as creating a Java lexer or parser, except you need to specify the language target, for example:

$ antlr4 -Dlanguage=JavaScript MyGrammar.g4

For a full list of antlr4 tool options, please visit the tool documentation page.

It is possible that you are targeting Javascript instead of the required JavaScript (note the case); observe the difference when I execute the two:

╭─{ yaauie@celeborn:~/Desktop/tmp-20160108 }
╰─○ antlr4 -Dlanguage=JavaScript Hello.g4
[success]

╭─{ yaauie@celeborn:~/Desktop/tmp-20160108 }
╰─○ antlr4 -Dlanguage=Javascript Hello.g4
error(31):  ANTLR cannot generate Javascript code as of version 4.5.1
[error: 1]
Sign up to request clarification or add additional context in comments.

1 Comment

That's right, it should be "JavaScript", with that exact capitalization. List of language targets.
3

You need "JavaScript", not "Javascript".

The exact language values for supported languages are:

Java:

antlr4 -Dlanguage=Java MyGrammar.g4

JavaScript:

antlr4 -Dlanguage=JavaScript MyGrammar.g4

C#:

antlr4 -Dlanguage=CSharp MyGrammar.g4

Python 3:

antlr4 -Dlanguage=Python3 MyGrammar.g4

Python 2:

antlr4 -Dlanguage=Python2 MyGrammar.g4

Go:

antlr4 -Dlanguage=Go MyGrammar.g4

C++:

antlr4 -Dlanguage=Cpp MyGrammar.g4

Swift:

antlr4 -Dlanguage=Swift MyGrammar.g4 

PHP:

antlr4 -Dlanguage=PHP MyGrammar.g4

Source: https://github.com/antlr/antlr4/blob/master/doc/targets.md and follow the language-specific links.

Comments

1

I was working with ATNLR to parse hive queries in java and had a similar issue. It turns out that I was missing the case. Instead of Java I was writing java

$>antlr -Dlanguage=java Hplsql.g4 -->error(31): ANTLR cannot generate java code as of version 4.7.1

$>antlr -Dlanguage=Java Hplsql.g4 -->Success

Comments

1

I was trying to execute:

antlr4 Arithmetic.g4 -Dlanguage=cSharp

I was getting a message:

ANTLR cannot generate cSharp code as of version 4.12.0

Just found the issue. Antlr language is CASE SENSITIVE

This works:

antlr4 Arithmetic.g4 -Dlanguage=CSharp

I hope this helps someone else.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.