java.lang.Object
java.io.StreamTokenizer
- See Also:
- Top Examples, Source Code,
nextToken()
,
TT_EOF
public void commentChar(int ch)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1062]Parse a file
By cute { dot } devil { at } rediffmail { dot } com on 2005/08/07 21:29:02 Rate
import java.io.*;
import java.util.*;
class fileadi
{ static int lno;
int offset;
symboltable sm =new symboltable ( ) ;
String type;
String segment;
public static void main ( String args [ ] ) throws IOException
{
int i;
FileReader fr ;
BufferedReader br;
BufferedWriter out;
LineNumberReader lnr ;
String line;
String a = new String ( ) ;
try
{
lnr = new LineNumberReader ( new BufferedReader ( new FileReader ( "test.asm" ) ) ) ;
out = new BufferedWriter ( new FileWriter ( new File ( "output.txt" ) ) ) ; // good approach!
while ( ( line=lnr.readLine ( ) ) != null )
{
lno = lnr.getLineNumber ( ) ;
}
lnr.close ( ) ;
String s1 [ ] =new String [ lno ] ;
br = new BufferedReader ( new FileReader ( "test.asm" ) ) ;
i=0;
while ( ( ( line=br.readLine ( ) ) != null ) && ( i < lno ) )
{
a = ( line.toLowerCase ( ) ) ;
s1 [ i ] =a;
StringTokenizer st = new StringTokenizer ( s1 [ i ] ) ;
while ( ( st.nextToken ( ) ) !="segment" )
{
if ( ( st.nexttoken ( ) ) =="segment" )
{
offset=0;
type="segment";
}
}
i++;
}
out.flush ( ) ;
out.close ( ) ; //close ( ) output streams
} catch ( IOException ioErr )
{
System.out.println ( ioErr.toString ( ) ) ;
System.exit ( 100 ) ;
}
}
}
class symboltable
{
private String symbol;
private int offset;
private String segment;
private String type;
symboltable ( String symbol,int offset,String segment,String type )
{
this.symbol=symbol;
this.offset=offset;
this.segment=segment;
this.type=type;
}
public String getsymbol ( )
{ return symbol; }
public int getoffset ( )
{ return offset; }
public String getsegment ( )
{ return segment; }
public String gettype ( )
{ return type; }
}
[1692]Warning, error in code sample
By Elena elena { at } orcca { dot } on { dot } ca on 2006/01/04 17:49:07 Rate
The line "while ( ( st.nextToken ( ) ) !="segment" ) "
makes no sense, since nextToken returns int value,
must be tested st.sval !="segment" instead.
public void eolIsSignificant(boolean flag)
- See Also:
TT_EOL
, ttype
, nextToken()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int lineno()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void lowerCaseMode(boolean fl)
- See Also:
TT_WORD
, ttype
, nextToken()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int nextToken()
throws IOException
- See Also:
ttype
, sval
, nval
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[79]StreamTokenizer example
By Anonymous on 2005/05/07 17:51:57 Rate
import java.io.*;
import java.util.*;
public class streamtoken {
public static void main ( String args [ ] )
{
if ( args.length == 0 ) {
System.err.println ( "missing input filename" ) ;
System.exit ( 1 ) ;
}
Hashtable wordlist = new Hashtable ( ) ;
try {
FileReader fr = new FileReader ( args [ 0 ] ) ;
BufferedReader br = new BufferedReader ( fr ) ;
StreamTokenizer st = new StreamTokenizer ( br ) ;
//StreamTokenizer st =
// new StreamTokenizer ( new StringReader (
// "this is a test" ) ) ;
st.resetSyntax ( ) ;
st.wordChars ( 'A', 'Z' ) ;
st.wordChars ( 'a', 'z' ) ;
int type;
Object dummy = new Object ( ) ;
while ( ( type = st.nextToken ( ) ) !=
StreamTokenizer.TT_EOF ) {
if ( type == StreamTokenizer.TT_WORD )
wordlist.put ( st.sval, dummy ) ;
}
br.close ( ) ;
}
catch ( IOException e ) {
System.err.println ( e ) ;
}
Enumeration enum = wordlist.keys ( ) ;
while ( enum.hasMoreElements ( ) )
System.out.println ( enum.nextElement ( ) ) ;
}
}
public double nval
- See Also:
ttype
, TT_NUMBER
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void ordinaryChar(int ch)
- See Also:
ttype
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void ordinaryChars(int low,
int hi)
- See Also:
ordinaryChar(int)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void parseNumbers()
- See Also:
ttype
, TT_NUMBER
, nval
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void pushBack()
- See Also:
ttype
, sval
, nval
, nextToken()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void quoteChar(int ch)
- See Also:
ttype
, sval
, nextToken()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void resetSyntax()
- See Also:
ordinaryChar(int)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void slashSlashComments(boolean flag)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void slashStarComments(boolean flag)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
@Deprecated
public StreamTokenizer(InputStream is)
- See Also:
StreamTokenizer(java.io.Reader)
, InputStreamReader
, BufferedReader
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public StreamTokenizer(Reader r)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String sval
- See Also:
ttype
, TT_WORD
, quoteChar(int)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String toString()
- See Also:
ttype
, sval
, nval
, Object
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int ttype
- See Also:
TT_WORD
, TT_NUMBER
, TT_EOL
, TT_EOF
, quoteChar(int)
, nextToken()
, eolIsSignificant(boolean)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int TT_EOF
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int TT_EOL
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[2003]token
By ooroofoos { at } yahoo { dot } com on 2009/12/22 10:46:42 Rate
token file
public static final int TT_NUMBER
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int TT_WORD
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void whitespaceChars(int low,
int hi)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void wordChars(int low,
int hi)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples