ANTLR not generating ParserBase

I am new to ANTLR and was looking into the CPP14 grammar here. I tried using

antlr4 -Dlanguage=Python3 CPP14Lexer.g4

antlr4 -Dlanguage=Python3 CPP14Parser.g4

Then use the following driver code:

import sys
from antlr4 import *
from CPP14Lexer import CPP14Lexer
from CPP14Parser import CPP14Parser

def main(argv):
    input_stream = FileStream(argv[1])
    lexer = CPP14Lexer(input_stream)
    stream = CommonTokenStream(lexer)
    parser = CPP14Parser(stream)
    tree = parser.start_()

if __name__ == '__main__':

And, try running it to parse a Hello World code in cpp, but I get the following error:

Traceback (most recent call last):
  File "/Users/vedantamohapatra/antlr/", line 4, in <module>
    from CPP14Parser import CPP14Parser
  File "/Users/vedantamohapatra/antlr/", line 14, in <module>
    from CPP14ParserBase import CPP14ParserBase
ModuleNotFoundError: No module named 'CPP14ParserBase'

How should I go about correcting this?


  • I think you should first run, and then also before running your driver file.