
hi
here is my code
import java.util.*;
import java.io.*;
import java.util.Scanner;
class Node
{
public boolean marked;
public int node_no;
public String node_type;
//public float value;
//public float control_value;
public String usevar[];
public String defvar[];
public int child[];
public int par[];
public int actIn[];
public int actOut[];
public int advice;
}
public class Input
{
public int n,nn,vn; //vn total no of variables, n total no of node ,nn node no.
public int i,use_var,def_var,p_c,c_c; //
public String c,f,var_nam[];
public Node node[];
StringTokenizer str,str1;
Input() throws Exception
{
FileReader df=new FileReader("Input.txt");
Scanner fr=new Scanner(df);
str=new StringTokenizer(fr.nextLine(),"$");
this.n=Integer.parseInt(str.nextToken()); //total no of nodes
this.vn=Integer.parseInt(str.nextToken()); //toal no of variables
var_nam=new String[vn]; //for total variables
str=new StringTokenizer(fr.nextLine(),"$");
System.out.println("rtryutrty"+n+vn);
for(int i=0;i<vn;i++)
{
String a=str.nextToken();
var_nam[i]=a;
}
node=new Node[n+1];
for(int i=1;i<=n;i++)
{
node[i]=new Node();
}
i=1;
while(fr.hasNextLine())
{
c=fr.nextLine();
str=new StringTokenizer(c,"$"); //node no is parsed
nn=Integer.parseInt(str.nextToken());
System.out.println(nn);
node[i].node_no=nn; //node no is assigned
str1=new StringTokenizer(str.nextToken()," ");
use_var=str1.countTokens(); // no of use var
node[i].usevar=new String[use_var];
for(int j=0;j<use_var;j++)
{
node[i].usevar[j]=str1.nextToken();
}
for(int j=0;j<use_var;j++)
{
System.out.println(node[i].usevar[j]);
}
str1=new StringTokenizer(str.nextToken()," "); // for def var
def_var=str1.countTokens();
node[i].defvar=new String[def_var];
for(int j=0;j<def_var;j++)
{
node[i].defvar[j]=str1.nextToken();
}
for(int j=0;j<def_var;j++)
{
System.out.println(node[i].defvar[j]);
}
str1=new StringTokenizer(str.nextToken()," "); // parents node info
p_c=str1.countTokens();
node[i].par=new int[p_c];
for(int j=0;j<p_c;j++)
{
node[i].par[j]=Integer.parseInt(str1.nextToken());
}
for(int j=0;j<p_c;j++)
{
System.out.println(node[i].par[j]);
}
System.out.println("erhiwe");
str1=new StringTokenizer(str.nextToken()," "); // child node info
c_c=str1.countTokens();
node[i].child=new int[c_c];
for(int j=0;j<c_c;j++)
{
node[i].child[j]=Integer.parseInt(str1.nextToken());
}
for(int j=0;j<c_c;j++)
{
System.out.println(node[i].child[j]);
}
node[i].node_type=str.nextToken(); // node type
//System.out.println("sfdsrsr\n\n\n");
int temp=Integer.parseInt(str.nextToken());
System.out.println(temp);
node[i].actIn= new int[temp];
str1=new StringTokenizer(str.nextToken()," ");
for(int temp1=0;str1.hasMoreTokens();temp1++)
node[i].actIn[temp1]=Integer.parseInt(str1.nextToken()); //total actIn are Obtained
temp=Integer.parseInt(str.nextToken());
System.out.println(temp);
node[i].actOut= new int[temp];
str1=new StringTokenizer(str.nextToken()," ");
for(int temp1=0;str1.hasMoreTokens();temp1++)
node[i].actOut[temp1]=Integer.parseInt(str1.nextToken()); //total actOut are Obtained
node[i].advice=Integer.parseInt(str.nextToken()); //advice vertex if not then simply put zero
i++; //next node
}
}
public static void main(String args[])throws Exception
{
Input i=new Input();
System.out.println("\nnew main\n");
for(int k=1;k<=i.n;k++)
{
//System.out.println("\nnew main\n");
System.out.print(i.node[k].marked);
System.out.print(i.node[k].node_no+" a121a ");
for(int j=0;j<i.node[k].usevar.length;j++)
System.out.print(i.node[k].usevar[j]+" ");
for(int j=0;j<i.node[k].defvar.length;j++)
System.out.print(i.node[k].defvar[j]+" ");
for(int j=0;j<i.node[k].child.length;j++)
System.out.print(i.node[k].child[j]+" ");
for(int j=0;j<i.node[k].par.length;j++)
System.out.print(i.node[k].par[j]+" ");
for(int j=0;j<i.node[k].actOut.length;j++)
System.out.print(i.node[k].actOut[j]+" ");
for(int j=0;j<i.node[k].actIn.length;j++)
System.out.print(i.node[k].actIn[j]+" ");
System.out.print(i.node[k].node_type+" ");
System.out.println(" ");
}
}
}
When i am trying to compile the code i found the following error
Error: Exception in thread "main" java.util.NoSuchElementException at
java.util.StringTokenizer.nextToken(Unknown Source)
at Input.
Actually this is an implementation of a slicing algorithm. The class Input.java specifies the Input to the program with the help of a text file. Below I am attaching the text file named Input.txt. the input file is too large in size. Please let me know more about the flaws.
58$14 name$Threadname$t$k$e$i$j$sc$x$y$z$a$b$n 57$$$$0$58$$$$$ 58$$$$57$59 60$$$$$ 59$$$$58$6$$$$$ 60$$$$58$33$$$$$ 6$7 33 34$7$59$7 8 9 10 12$$$$$$ 33$34 6 7$34$60$67 34 35 36 37 38 39$$$$$$ 7$8 15 34 35$7 34 $6$8$$$$$$ 34$35 7 8$7 34$33$35$$$$$$ 35$36 37 5 7 9 10 14 15$35$33 34$36 37$$$$$$ 59$$$$58$6$$$$$ 10$$8$6 8 9$11 14 17$$$$$$ 8$9 10 14 15 35 36 37$8$6 7$10 15$$$$$$ 9$$8 35$6 8$10 15$$$$$$ 36$$8 35$33 35$37$$$$$$ 37$$9 35$6 8$10 15$$$$$$ 38$$$33$40$$$$$$ 39$$$33$52$$$$$$ 40$$$37 38 69$41 45 46 50$$$$$$ 41$47 48 50 51 70 71 72 74$41$40$47 48$$$$$$ 46$47 49 45$45$40$47 48 49 70$$$$$$ 45$49 45 46$45$40$49$$$$$$ 47$48 45 46 49$41$41 45$48 49$$$$$$ 48$47 49 45 46 70 71 72 74$41$41 46 47 50 51$0$$$$$$ 49$47 49 45 46$45$45 46 47$0$$$$$$ 50$51 41 48$41$40$70 51 48$$$$$$ 51$41 48 50 51 71 72 74 70$41$40 50 75$48$$$$$$ 52$$$49$37 39$53 54 55 56$$$$$ 53$56$53$52$56$$$$$$ 54$56 27 28 29$54 27$52 27$56$$$$$$ 55$56 28 29$55$52 28$56$$$$$$ 56$53 54 55 27 28 29$53 54 55 27 28$52 53 54 55$0$$$$$$ 11$$$10$26$$$$$$ 12$$$6 24 66$13 16$$$$$$ 13$15$13$12$14 15$$$$$$ 14$8 9 10 15 14 35 36 37$8 35$10 13$15$sleep node$$$$$ 15$8 9 10 13 14 15 35 36 37$8 35 13$8 9 13 14$16$$$$$$ 16$$$12 15$0$$$$$$ 17$$$$29 64 10$19 23 24$$$$$ 19$24$19$17$24$$$$$$ 23$23 24 25$$17$24$$$$$$ 24$19 23 24 25$19$17 19 23$12 25$$$$$$ 25$23 24 25$$24$65$$$$$$ 26$$$11$27 28 29$$$$$$ 27$29 54 56$27 54$26$29$$$$$$ 28$29 55 56$28 55$26$29 55$$$$$$ 29$27 28 29 54 55 56$27 28 54 55$26 27 28$17 62$$$$$$ 62$$$29$63 65$pointcut vertex$$$$$ 63$$$62$64$$$$$$ startingadvice vertex 64$$$63$17$$$$$$ 65$$$25 62$66$$$$$$ startingadvice vertex 66$$$65$12$$$$$$ 67$$$33$68 70$poincut vertex$$$$$ 68$$$67$69$$$$$$ startingadvice vertex 69$$$68$40$$$$$$ 70$71 72 74 41 48 50 70 51$41$46 50 67$71 75 f1_in$$1$f1_in$$$ startingadvice vertex 71$70 71 72 74 41 48 50 51$41$70$72 74$$$$$$ 72$70 71 72 74 41 48 50 51$41$f1_in$0$$$$$$ 74$70 71 72 74 41 48 50 51$41$71 f1_in$0$$$$$$ 75$$$70$51$$$$$$
The algorithm is as follows:
import java.util.*;
class DynamicSlice
{
String var_name;
int par[];
DynamicSlice(int n)
{
par=new int[n+1]; //no of nodes is=n
}
}
class Algo extends Input
{
int zc=n+1;
DynamicSlice dn[][]=new DynamicSlice[zc][vn];
int rec_def[];
Algo() throws Exception
{}
public void init()
{
rec_def =new int[vn];
for(int i=1;i<n+1;i++)
for(int j=0;j<vn;j++)
dn[i][j]=new DynamicSlice(n);
//set Dynamic slice is creATED
for(int i=1;i<n+1;i++)
for(int j=0;j<vn;j++)
{
dn[i][j].var_name=var_nam[j];
}
}
//variable name is assigned to each position
public int varat(String x)
{
for(int i=0;i<vn;i++)
if(x.equals(var_nam[i]))return(i);
return 0;
} // knowing the position of var in vaiable list
public void a2(int nodeno)
{
for(int l=0; l<node[nodeno].usevar.length;l++)
{
int index = varat(node[nodeno].usevar[l]);
for(int i=1;i<n+1;i++){
int k=dn[nodeno][index].par[i];
if(k!=0)
if(node[k].marked=true)
{
dn[nodeno][index].par[k]=1;
for(int j=1;j<=n;j++)
{
dn[nodeno][index].par[j]=(dn[k][index].par[j]==1)?1:0;
}
}
}
}
}
public void call2a()
{
for(int i=1;i<=n;i++)
a2(node[i].node_no);
}
/* 2 A over*/
/* 2B starts */
public void call2b()
{
for(int i=1;i<=n;i++)
{
for(int j=0;j<node[i].defvar.length;j++)
{
int index = varat(node[i].defvar[j]); //index of def var in varnam list
dn[i][index].par[i]=1; //dynamic slice updated
rec_def[index]=i;
node[rec_def[index]].marked=false;
}
node[i].marked=true;
}
}
/* 2 C and 2 B over */
/* rest start*/
public void other()
{
for(int i=1;i<n+1;i++)
{
if(node[i].node_type.equals("pointcut"))
{
node[i].marked=true;
for(int j=0;j<node[i].actIn.length;j++)
node[node[i].actIn[j]].marked=true;
for(int j=0;j<node[i].actOut.length;j++)
node[node[i].actOut[j]].marked=true;
if(node[i].advice>0) //advice vertex is marked along with the formal in formal out
{
node[node[i].advice].marked=true;
for(int j=0;j<node[node[i].advice].actIn.length;j++)
node[node[node[i].advice].actIn[j]].marked=true;
for(int j=0;j<node[node[i].advice].actOut.length;j++)
node[node[node[i].advice].actOut[j]].marked=true;
}
}
if(node[i].node_type.equals("sleep"))
{
node[i].marked=true;
}
}
}
public void call3a()
{
System.out.println(" enter the var name and the node no");
int sw,sq;
String arg;
Scanner scan=new Scanner(System.in);
arg=scan.next();
sw=scan.nextInt();
sq=varat(arg); //index no of arg
for(int i=0;i<n;i++)
{
if(dn[sw][sq].par[i]==1)
System.out.print(dn[sw][sq].par[i]+1);
}
}
public static void main(String arg[]) throws Exception
{
//Input input=new Input();
Algo alg=new Algo();
alg.init();
System.out.println("\n\n\n\n\\n\n\n");
alg.call2a();
alg.call2b();
alg.other();
while(true)
{
alg.call3a();
System.out.println(" want to exit then enter 0");
Scanner scan=new Scanner(System.in);
int i=scan.nextInt();
if(i==0)break;
}
}/*end of main*/
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.