473,409 Members | 1,945 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,409 software developers and data experts.

Help with JLex code please!

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
0 1113

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

Similar topics

1
by: the_proud_family | last post by:
HELP ME PLEASE!! my email is the_proud_family@yahoo.com I can't get the ball to go up right side and then I need it to turn around and keep turning until velocity=0 I have been at it for the ...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
8
by: punk86 | last post by:
Hi, i been working on this codes but i keep getting broken links for the pictures. Im using apache. Need help for this please. I think its just the codes in my index.php is wrong and i do not know...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.