2

Grammar for python is given on antlr site but on using it to generate AST its giving error. I am using same procedure as for java grammar which generated AST .

Errors:

> C:\testpython>java -cp antlr-3.2.jar org.antlr.Tool Python.g

error(10): internal error: : java.lang.Error: Error parsing Python.g: 'class' not expected 'grammar' org.antlr.tool.GrammarSpelunker.match(GrammarSpelunker.java:74) org.antlr.tool.GrammarSpelunker.grammarHeader(GrammarSpelunker.java:112) org.antlr.tool.GrammarSpelunker.parse(GrammarSpelunker.java:84) org.antlr.Tool.sortGrammarFiles(Tool.java:552) org.antlr.Tool.process(Tool.java:408) org.antlr.Tool.main(Tool.java:91) error(100): Python.g:56:1: syntax error: antlr: Python.g:56:1: unexpected token: class error(8): file Python.g contains grammar PythonParser; names must be identical error(100): Python.g:56:20: syntax error: antlr: Python.g:56:20: expecting SEMI, found 'extends' error(100): syntax error: invalid char literal: '\014' error(150): grammar file Python.g has no rules error(100): Python.g:0:0: syntax error: assign.types: :0:0: unexpected end of subtree error(100): Python.g:0:0: syntax error: define: :0:0: unexpected end of subtree

Any help?

1 Answer 1

1

You're trying to generate a parser with ANTLR v3 using a grammar that is written for ANTLR v2. Either find a grammar for v3, or keep the grammar and use ANTLR v2: http://www.antlr2.org/download.html

A grammar that starts like this is targeted for v2:

class FooParser extends Parser;

and this for v3:

grammar FooParser;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.