473,480 Members | 3,062 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Scan a Wren file

I have started a java program and I have one problem that I can't
overcome. I have commented in my code as to what I would like to do
but am unable to do correctly. Your help is greatly appreciated. The
guidelines for the code is the following url address:
http://www.cs.uiowa.edu/~slonnegr/plc/ScanWrenHW.pdf

code:

import java.io.*;

class Token
{
static final int IDENTIFIER=0, NUMERAL=2, RESERVED=3, RELATION=4,
OP=5, OTHER=6, EOF=7, ERROR=9;
private int type;
private String value;

Token(int t, String v){ type =t; value=v; }

int getType(){ return type; }
String getValue(){ return value; }
}

public class Wrenreader
{
private char currChar=' ';
private BufferedReader br;

Wrenreader(Reader input)
{ br=new BufferedReader(input); }

Token getToken()
{
while(currChar==' ')
currChar=getChar();

if(Character.isDigit(currChar))
{
int numval=0;
while(Character.isDigit(currChar))
{
numval=10*numval+currChar-'0';
currChar=getChar();
}
return new Token(Token.NUMERAL, Integer.toString(numval));
}
else
{
/*I need to do something here to get the token for the remaining
//types but I've hit a road block and I can't seem to come up with
//an answer to the problem. I'm not sure how to create a switch
statement
//I would like to do something like:
//int tok;
switch (currChar) // recognize a special symbol
{
case 'program'||'is' : tok = Token.LPAREN; break;
default : tok = Token.ERROR; break;
}
Token token = new Token(tok, "" + currChar);
if (tok != Token.EOL)
currChar = getChar();
return token;*/
}

char getChar()
{
try
{
int line=br.read();
if(line == -1) line='\n';
return (char)line;
}
catch(IOException ioe)
{ return '\n'; }
}

void scan()
{
Token token;
currChar=getChar();

do
{
token=getToken();
switch(token.getType())
{
case Token.IDENTIFIER:
System.out.println("IDENTIFIER: " + token.getValue()); break;
case Token.NUMERAL:
System.out.println("NUMERAL: " + token.getValue()); break;
case Token.RESERVED:
System.out.println("RESERVED: " + token.getValue()); break;
case Token.RELATION:
System.out.println("RELATION: " + token.getValue()); break;
case Token.OP:
System.out.println("OP: " + token.getValue()); break;
case Token.OTHER:
System.out.println("OTHER: " + token.getValue()); break;
case Token.EOF:
System.out.println("EOF"); break;
case Token.ERROR:
System.out.println("ERROR: " + token.getValue()); break;
}
}
while(token.getType() != Token.EOF);
}
public static void main(String[]args)
{
String filename="";
try
{
Wrenreader wr=new Wrenreader(new FileReader(filename));
wr.scan();
}
catch(Exception e)
{ }
}
}
end of code
Jul 17 '05 #1
0 1436

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5677
by: Carlos Moreno | last post by:
I can't find a reasonable explanation for this. I have a table game, with primary key gameid (an int). If I use a where involving gameid and <, or >, or <=, or >=, then I get a sequential...
6
5697
by: robert | last post by:
just got out of a "class" on EXPLAIN, from a 390/v6 maven. was told that ACCESSTYPE = 'R' in the plan_table meant a TableSpace scan. hmmmm. next step up (or down, depending on your outlook)...
2
2720
by: Kausar | last post by:
Hello All, I want to know how to scan the files before uploading it to the server in ASP.NET 2.0 application. One work arround i thought is to allow to upload in some temporary folder then sacn...
0
2194
by: sameer | last post by:
Hi all, ..net framwork 1.1 sql server 2000 I have a vb.net winforms application using webservices\ remoting to upload documents\ images to the webserver and i am gong to store them in the sql...
5
3225
by: johnwayne83 | last post by:
This is my first semester in c++ and i took java last semester. I need some help and i really cant find any information that has helped me or to point me in the right direction. I am using...
0
2860
MMcCarthy
by: MMcCarthy | last post by:
This is a module that scans for files and folders on a specified path and describe them in comma separated values file in a text format. The information is stored in this file consecutively like:...
1
1810
by: gdubois | last post by:
Hi all! Is there an easy way to scan files on network, and find out which files are new or modified? (VS2003, C#) I am trying to create a program to help myself manage the network. I am...
1
996
by: =?Utf-8?B?R3JlZ29yeU5lbHNvbg==?= | last post by:
How do I get the built-in scan component of Photo Gallery to scan at a higher resolution? When I first used it to scan a photo, the default was for a JPG file at 300 dpi, with an option to...
0
7060
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
7106
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...
1
6760
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
7022
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
5365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4501
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...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.