I have a problem with my ANTLR4. I'm trying to print AST from python 3 code but there are some errors and I don't know how to fix them.
I wrote simple code for test:
a=(1,2,3)
print(a)
I ran the program but this errors appeared:
line 1:1 extraneous input '=' expecting {<EOF>, '.', '*', '(', '**', '[', '|', '^', '&', '<<', '>>', '+', '-', '/', '%', '//', '@'}
line 2:0 extraneous input '\n' expecting {<EOF>, '.', '*', '(', '**', '[', '|', '^', '&', '<<', '>>', '+', '-', '/', '%', '//', '@'}
line 3:0 extraneous input '\n' expecting {<EOF>, '.', '*', '(', '**', '[', '|', '^', '&', '<<', '>>', '+', '-', '/', '%', '//', '@'}
My main class :
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
import org.antlr.v4.*;
public class Main {
public static void main(String[] args) {
try {
ANTLRInputStream input = new ANTLRFileStream("/home/grzegorz/Desktop/Python3/input.txt");
Python3Lexer lexer = new Python3Lexer(input);
CommonTokenStream token = new CommonTokenStream(lexer);
Python3Parser parser = new Python3Parser(token);
ParseTree parseTree = parser.expr();
System.out.println(parseTree.toStringTree(parser));
}catch (Exception ex){
ex.printStackTrace();
}
}
}
I have the grammar from this site: https://github.com/antlr/grammars-v4/tree/master/python3