ANTLR4 extraneous input

江枫思渺然 提交于 2019-12-06 06:18:35

Explanation

Your input file consists of two statements and you are parsing the file as if it was an expression (with line ParseTree parseTree = parser.expr();; rule expr from Python 3 grammar).

This also exaplains the first error: an identificator a is accepted as a part of expression but = sign is not. That's because = is a part of assignment statement.

Solution

Parse the input using another grammar rule for example file_input rule which will accept many statements. Change the abovementioned line to ParseTree parseTree = parser.file_input();.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!