ankit lohiya
ankit lohiya

Reputation: 1

Writing ANTLR grammar for parsing java file

I am new to ANTLRWorks and I am doing my final year project. Could anyone please help me in how to write ANTLR grammar just for recognising a class in java "and printing it in any file as an output". On the same lines then I will be able to write the grammar for my project.

Upvotes: 0

Views: 2250

Answers (1)

Bakul Brahmbhatt
Bakul Brahmbhatt

Reputation: 61

Creating all required java classes from grammar.

Execute
java -cp antlr-3.3-complete.jar org.antlr.Tool Java.g

OR

java -jar antlr-3.3-complete.jar Java.g

from the directory where you have antlr-3.3-complete.jar and Java.g file.

Java Grammer which is compatible with Java 1.3 to 1.6

This Page explains how to use Java.g file and compile it into JavaParser and JavaLexer which are required classes to generate AST tree

Reference Resources:

This exaplains how can we generate AST Tree

This explains how can we create parser and generate AST tree for any Java class. It also explains what we need to modify in original grammar file Java.g

Upvotes: 2

Related Questions