开发者

How to count identifiers, no. of inputs and outputs in a Java program

开发者 https://www.devze.com 2023-01-17 16:35 出处:网络
I want to take a program as input and I want to find out: No. of identifiers No. of unique lines containing identifiers

I want to take a program as input and I want to find out:

  1. No. of identifiers
  2. No. of unique lines containing identifiers
  3. No. of identifiers in the set of unique lines
  4. No. of inputs and outputs
  5. 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:

  1. There are 4 identifiers (a, b, c, and d).
  2. No. of input is 1
  3. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消