Aswin P J
Aswin P J

Reputation: 561

Is it possible to generate grammar file from the Lexer and Parser files generated by ANTLR?

I was working on a project that involved ANTLR. I generated the Lexer and Parser and used it on a project in another directory. The project was hosted on GitHub so I still have all the files that ANTLR generated with me. However I lost the grammar file due to hard disk failure. Is there anyway to regenerate the grammar file from the ANTLR generated files? Rewriting the grammar file once again is a headache and would involve changing my project code at many places.

Upvotes: 0

Views: 217

Answers (1)

Mike Lischke
Mike Lischke

Reputation: 53337

The answer is: only partially. The generated files contain functions/enums that correspond to the original rule names (both lexer and parser). So you could restore the overall structure. But you won't come far with that since the rules themselves have been translated into state changes to speed up processing (DFA). These states use generated numbers for which you have no mapping back to the original code.

As always: it's not a question whether you need a backup of your data at all, but when.

Upvotes: 1

Related Questions