By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,787 Members | 2,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,787 IT Pros & Developers. It's quick & easy.

Help with JLex code please!

P: 1
I am coding a lexer that reads the input from a text file and displays the token ID's of each of the words in the file (e.g. if the file contains "<HEAD>" it displays the Symbol ID 10).

Below is my code that requires the user to input HTML code, which displays the token ID's:

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class Test {
  4.  
  5.    public static void main (String[] args) throws Exception {
  6.  
  7.       //  prompt the user to enter their Noddy HTML text
  8.       System.out.print("Enter your Noddy HTML Text: ");
  9.  
  10.       //  open up standard input
  11.       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  12.  
  13.     Arithmetic lexer = new Arithmetic(br);
  14.  
  15.     Symbol s;
  16.  
  17.     do
  18.     {
  19.       s = lexer.next_token();
  20.       System.out.println(s);
  21.     }
  22.     while (s.id != SymbolId.EOF);
  23.   }
  24.  
  25. }
And this is my current code that looks into the text file and displays the text on screen. It gives me the token ID 0 each time (which is EOF). Can anyone please help me get this to return the proper token ID's of the text that is contained in the text file?

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class Test {
  4.  
  5. public static void main (String[] args) throws Exception {
  6.  
  7. final FileReader inputFile = new FileReader("TestFile.txt");
  8. final BufferedReader inputBuffer = new BufferedReader(inputFile);
  9.  
  10. String line = inputBuffer.readLine();
  11.  
  12. System.out.println(line);
  13.  
  14. NoddyHTML lexer = new NoddyHTML(inputBuffer);
  15.  
  16.     Symbol s;
  17.  
  18.     do
  19.     {
  20.       s = lexer.next_token();
  21.       System.out.println(s);
  22.     }
  23.     while (s.id != SymbolId.EOF);
  24.  
  25. }
  26.      } 

Any help would be greatly appreciated. Thanks.
Nov 27 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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