-1

I want a lexical analyzer for java code. Should I write my own or should i use a pre-existing tool? Is it possible to make my lexical analyzer behave the same as the Java lexical analyzer, without writing my own Regular Expressions?

For example if i have a class like this:

 Class Cat
 {
   public void fun(){ 
    int a;
     a=3;

     int b=0;

     if((a/b==3)||(a/b==0))
     {
         System.out.println("Test");
     }
   }
 }

I want its output to look like this

class keyword
Cat (id/className)
int a(declaration)
a=3 (assignment)
int b=0 (declaration and assignment) 
if (key word)
((a/b==3)||(a/b==0)) (if condition)

Please let me know if you have any ideas..

StormeHawke
  • 5,987
  • 5
  • 45
  • 73
Nishat
  • 881
  • 1
  • 17
  • 30

1 Answers1

0

http://www.programcreek.com/2011/01/a-complete-standalone-example-of-astparser/

Eclipse includes a tool for extracting the AST out of Java.

ejbs
  • 390
  • 1
  • 9