this is code take if statement and split to types
and i want to add to code parse
where check if statement that is in code with if correct statement and know do it is correct or no ?
plz anyone help me and thank you
Expand|Select|Wrap|Line Numbers
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Scanner;
- public class Main {
- public static void main(String args[]) throws IOException {
- int i;
- double d;
- boolean b;
- String str;
- String str1;
- String str2;
- String str3;
- String str4;
- String str5;
- FileWriter fout = new FileWriter("test.txt");
- fout.write("if int a = 30 int c = a / 5 ;");
- fout.close();
- FileReader fin = new FileReader("Test.txt");
- Scanner src = new Scanner(fin);
- while (src.hasNext()) {
- if (src.hasNextInt()) {
- i = src.nextInt();
- System.out.println("int: " + i);
- } else if (src.hasNextDouble()) {
- d = src.nextDouble();
- System.out.println("double: " + d);
- } else if (src.hasNextBoolean()) {
- b = src.nextBoolean();
- System.out.println("boolean: " + b);
- } else if (src.hasNext("if")){
- str = src.next("if");
- System.out.println("Resrved words: " + str);
- }
- else if (src.hasNext("=")){
- str1 = src.next("=");
- System.out.println("Compute: " + str1);
- }
- else if (src.hasNext(";")){
- str2 = src.next(";");
- System.out.println("Compute: " + str2);
- }
- else if (src.hasNext("/")){
- str2 = src.next("/");
- System.out.println("Compute: " + str2);
- }
- /*else if (src.hasNext("(")){
- str3 = src.next("(");
- System.out.println("Compute: " + str3);
- }
- else if (src.hasNext(")")){
- str4 = src.next(")");
- System.out.println("Compute: " + str4);
- }*/
- else if (src.hasNext("==")){
- str5 = src.next("==");
- System.out.println("Logical: " + str5);
- }
- else if (src.hasNext("==")){
- str5 = src.next("==");
- System.out.println("Logical: " + str5);
- }
- else {
- str = src.next();
- System.out.println("Variables: " + str);
- }
- }
- fin.close();
- }
- }