How to handle conflicting function names between my antlr grammar and the target language

I have a grammar containing function names called eval and round, these are already functions in python, and when I try to generate a listener using:

antlr4 -listener -lib / src / grammar -Dlanguage = Python3 -o / gen -no-visitor / src / grammar / Grammar.g4

I get the following:

error (134): Grammar.g4: 138: 0: conflicts around character generated in target language or runtime error (134): Grammar.g4: 174: 0: eval character conflicts with generated code in target language or runtime error (134): Grammar.g4: 62: 3: conflict of eval characters with generated code in the target language or runtime error (134): Grammar.g4: 134: 3: conflicts around character with generated code in the target language or runtime

I cannot just change eval / round to another name because I am writing a clone from different dls. Is it possible to create a namespace or work around this problem in another way without changing the syntax of the grammar language?

+4
source share
1

-, , - - r_.

:

:

 eval:  'eval' anotherRule ';' ;
 anotherRule  : '1';

:

 r_eval:  'eval' anotherRule ';' ;// change the rule name since eval is a reserved identifier in Python
 anotherRule  : '1'; // you don't have to change this rule, since "anotherRule" is most likely not reserved.

, 'eval' ( , dsl) !

+8

All Articles