sara
sara

Reputation: 91

How to solve error generate python3 code in ANTLR 4.4 ?

I am using ANTLR 4.4 with Python3 as target language. You can see in this page: https://github.com/antlr/antlr4/releases that ANTLR 4.4 suppors Python3 but when I want to create a Python lexer & parser with this command: -Dlanguage=Python3 MyGrammar.g4 , I got this error:

 ANTLR cannot generate python3 code as of version 4.4

I don't know it is because of my grammar and I have to modify it to resolve this error or waht?(BTW I got no error in ANTLRWorks 2.1) Any help would be appreciated.

Upvotes: 2

Views: 3999

Answers (3)

Joseph Glover
Joseph Glover

Reputation: 330

It might just be a typo (I ran into the same problem and I solved it by using capital P in Python):

$ antlr4 -Dlanguage=python3 grammar.g4 
error(31):  ANTLR cannot generate python3 code as of version 4.11.1

Solution

$ antlr4 -Dlanguage=Python3 grammar.g4

Upvotes: 0

Bonnie Varghese
Bonnie Varghese

Reputation: 2248

As mentioned here https://theantlrguy.atlassian.net/wiki/display/ANTLR4/Python+Target :

  • antlr4 -Dlanguage=Python2 MyGrammar.g4 or
  • antlr4 -Dlanguage=Python3 MyGrammar.g4

Upvotes: 5

sara
sara

Reputation: 91

The error is removed by change the definition of CLASSPATH. First I specified it permanently: Using System Properties dialog > Environment variables > Create or append to CLASSPATH variable

then I changed it to temporary as follows: SET CLASSPATH=.;C:\Javalib\antlr-4.4-complete.jar;%CLASSPATH% and the error disappeared.

Upvotes: 0

Related Questions