I want to take a program as input and I want to find out:
- No. of identifiers
- No. of unique lines containing identifiers
- No. of identifiers in the set of unique lines
- No. of inputs and outputs
- According to control structures in the program I want to assign a value to control structures
If I calculate this I can do my project. This is the basic for me.
Can any one help me with this by giving guidelines or anything? I am trying this but I am not getting anywhere.
For example:
#include<stdio.h>
void main()
{
int a,b,c;
float d;
printf("enter a,b,c value");
scanf("%d %d %d",&a,&b,&c);
d=a+b+c;
getch();
}
Through files I will take the above program as input and I want to count identifiers. For examp开发者_开发知识库le:
- There are 4 identifiers (
a
,b
,c
, andd
). - No. of input is 1
- No. of output is 1
We can do this manually but I want to do the calculation in a program, how to count the identifiers, inputs, outputs, etc.
Looks like you want to write a C parser in Java.
Take a look at JavaCC
Have a look at this thread : Java Programming - Parse "C" code using Java.
It talks about using
Scanner class
JavaCC
JLEX
精彩评论