473,378 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how add parse in scanner

1
how add parse in scanner
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
  1. import java.io.FileReader;
  2. import java.io.FileWriter;
  3. import java.io.IOException;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.   public static void main(String args[]) throws IOException {
  8.     int i;
  9.     double d;
  10.     boolean b;
  11.     String str;
  12.     String str1;
  13.     String str2;
  14.     String str3;
  15.     String str4;
  16.     String str5;
  17.  
  18.     FileWriter fout = new FileWriter("test.txt");
  19.     fout.write("if int a = 30 int c = a / 5 ;");
  20.     fout.close();
  21.  
  22.     FileReader fin = new FileReader("Test.txt");
  23.  
  24.     Scanner src = new Scanner(fin);
  25.  
  26.     while (src.hasNext()) {
  27.       if (src.hasNextInt()) {
  28.         i = src.nextInt();
  29.         System.out.println("int: " + i);
  30.       } else if (src.hasNextDouble()) {
  31.         d = src.nextDouble();
  32.         System.out.println("double: " + d);
  33.       } else if (src.hasNextBoolean()) {
  34.         b = src.nextBoolean();
  35.         System.out.println("boolean: " + b);
  36.       } else  if (src.hasNext("if")){
  37.         str = src.next("if");
  38.         System.out.println("Resrved words: " + str);
  39.       }
  40.       else  if (src.hasNext("=")){
  41.         str1 = src.next("=");
  42.         System.out.println("Compute: " + str1);
  43.       }
  44.       else  if (src.hasNext(";")){
  45.         str2 = src.next(";");
  46.         System.out.println("Compute: " + str2);
  47.       }
  48.       else  if (src.hasNext("/")){
  49.         str2 = src.next("/");
  50.         System.out.println("Compute: " + str2);
  51.       }
  52.       /*else  if (src.hasNext("(")){
  53.         str3 = src.next("(");
  54.         System.out.println("Compute: " + str3);
  55.       }
  56.       else  if (src.hasNext(")")){
  57.         str4 = src.next(")");
  58.         System.out.println("Compute: " + str4);
  59.       }*/
  60.       else  if (src.hasNext("==")){
  61.         str5 = src.next("==");
  62.         System.out.println("Logical: " + str5);
  63.       }
  64.       else  if (src.hasNext("==")){
  65.         str5 = src.next("==");
  66.         System.out.println("Logical: " + str5);
  67.       }
  68.       else {
  69.           str = src.next();
  70.         System.out.println("Variables: " + str);
  71.       }
  72.  
  73.     }
  74.     fin.close();
  75.   }
  76. }
Jan 15 '10 #1
1 2049
RedSon
5,000 Expert 4TB
It looks like you are already parsing src. I don't understand what you are trying to add to your program.
Jan 19 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Reiner Merz | last post by:
Hi, I'm looking for advice on how to parse a timestamp string according to the ISO 8601 specification. For those unfamiliar with the standard, here's an example: 2003-09-09T23:00:00Z...
0
by: Daniel Bass | last post by:
Symbol MC9000k scanner running Windows Mobile 2003. C# .Net (.Net CF) with OpenNetCf 1.2 installed. Latest Symbol SDK driving the scan engine stuff. I've extracted the barcode scanner handling...
9
by: Dan =o\) | last post by:
Hey guys, I wonder if you could please provide me with some ideas as to how to get around this problem. Symbol MC9000-k, Pocket PC 2003... With a scanner application I've written, data is...
7
by: DemonWasp | last post by:
I've been having some trouble getting the Scanner class to operate the way I'd like. I'm doing some fairly basic file IO and I can't seem to get the class to load the last line/token any way I try....
10
by: Michael B. Trausch | last post by:
Alright... I am attempting to find a way to parse ANSI text from a telnet application. However, I am experiencing a bit of trouble. What I want to do is have all ANSI sequences _removed_ from...
2
by: chris_gpf1 | last post by:
Hi, I'm working on a website where the user will have to scan a barcode with a serial barcode scanner. I get the scanner working and reading the barcode, but when I want to write the string in...
4
by: Gerry19 | last post by:
Hi All, I'm trying to monitor data passed from a USB Barcode scanner but I can't find any decent code examples of what I need to do, including any references I need to include. I know I need to...
3
by: thename1000 | last post by:
Hi, I'm trying to create this output: Input team 1's name: Team 1 Input team 1's ranking: 90.4 etc.
6
by: rotaryfreak | last post by:
Hi everyone, ive had this problem for a while and i cant seem to figure out why. I am using eclipse to create my java code. When import the Scanner class, create a new object and so on... ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.